Inject cert-manager annotations and TLS configuration into Ingress resources
This commit is contained in:
		
							parent
							
								
									5dc4290337
								
							
						
					
					
						commit
						3892da3ced
					
				@ -12,9 +12,6 @@ httpServiceRender = lambda h: HTTPService {
 | 
				
			|||||||
        kind = "Ingress"
 | 
					        kind = "Ingress"
 | 
				
			||||||
        metadata = {
 | 
					        metadata = {
 | 
				
			||||||
            name = h.service
 | 
					            name = h.service
 | 
				
			||||||
            annotations = {
 | 
					 | 
				
			||||||
                "cert-manager.io/issuer": "letsencrypt"
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        spec = {
 | 
					        spec = {
 | 
				
			||||||
            rules = [{
 | 
					            rules = [{
 | 
				
			||||||
@ -38,3 +35,26 @@ httpServiceRender = lambda h: HTTPService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    [ingress]
 | 
					    [ingress]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					certInjector = lambda input: networkingv1.Ingress | any {
 | 
				
			||||||
 | 
					    """Inject cert to Ingress"""
 | 
				
			||||||
 | 
					    _result: any = {}
 | 
				
			||||||
 | 
					    if input.kind != "Ingress":
 | 
				
			||||||
 | 
					        _result = input
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        ingress: networkingv1.Ingress = input as networkingv1.Ingress
 | 
				
			||||||
 | 
					        print(ingress)
 | 
				
			||||||
 | 
					        ingress.metadata.annotations = {"cert-manager.io/issuer" = "letsencrypt"}
 | 
				
			||||||
 | 
					        ingress.spec.tls = [{
 | 
				
			||||||
 | 
					            hosts = [r.host for r in ingress.spec.rules]
 | 
				
			||||||
 | 
					            secretName = "tls-" + ingress.metadata.name
 | 
				
			||||||
 | 
					        }]
 | 
				
			||||||
 | 
					        _result = ingress
 | 
				
			||||||
 | 
					    _result
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					httpServiceRefine = lambda h: HTTPService {
 | 
				
			||||||
 | 
					    ingress = httpServiceRender(h)
 | 
				
			||||||
 | 
					    ingress2 = certInjector(ingress[0])
 | 
				
			||||||
 | 
					    ingress2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										8
									
								
								main.k
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								main.k
									
									
									
									
									
								
							@ -26,15 +26,17 @@ envs = base.Envs {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
http = base.HTTPService {
 | 
					http = base.HTTPService {
 | 
				
			||||||
    service = "nginxxx"
 | 
					    service = "nginxxx"
 | 
				
			||||||
    domain = "nginxxx.ve.suyiiyii.top"
 | 
					    domain = prefix + "nginxxx.ve.suyiiyii.top"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					prefix = option(prefix, "str", False, "")
 | 
				
			||||||
deploys = sum([base.appRender(a) for a in apps], [])
 | 
					deploys = sum([base.appRender(a) for a in apps], [])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
apps_manifests = [base.envInjector(envs, deploy) for deploy in deploys]
 | 
					apps_manifests = [base.envInjector(envs, deploy) for deploy in deploys]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ingresses = [base.httpServiceRender(http)]
 | 
					ingresses = [base.httpServiceRefine(http)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
env_manifests = [base.envSecretRender(a) for a in base.Envs.instances()]
 | 
					env_manifests = [base.envSecretRender(a) for a in base.Envs.instances()]
 | 
				
			||||||
# base.appRender(a)
 | 
					# base.appRender(a)
 | 
				
			||||||
manifests.yaml_stream([apps_manifests, env_manifests, ingresses,base.issuer])
 | 
					manifests.yaml_stream([apps_manifests, env_manifests, ingresses, base.issuer])
 | 
				
			||||||
 | 
					# print(prefix)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user