github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/deprecated/ingress-1-20.cue (about)

     1  "ingress-1-20": {
     2  	type: "trait"
     3  	annotations: {}
     4  	labels: {
     5  		"deprecated": "true"
     6  	}
     7  	description: "Enable public web traffic for the component, the ingress API matches K8s v1.20+."
     8  	attributes: {
     9  		podDisruptive: false
    10  		status: {
    11  			customStatus: #"""
    12  				let igs = context.outputs.ingress.status.loadBalancer.ingress
    13  				if igs == _|_ {
    14  				  message: "No loadBalancer found, visiting by using 'vela port-forward " + context.appName + "'\n"
    15  				}
    16  				if len(igs) > 0 {
    17  				  if igs[0].ip != _|_ {
    18  					  message: "Visiting URL: " + context.outputs.ingress.spec.rules[0].host + ", IP: " + igs[0].ip
    19  				  }
    20  				  if igs[0].ip == _|_ {
    21  					  message: "Visiting URL: " + context.outputs.ingress.spec.rules[0].host
    22  				  }
    23  				}
    24  				"""#
    25  			healthPolicy: #"""
    26  				isHealth: len(context.outputs.service.spec.clusterIP) > 0
    27  				"""#
    28  		}
    29  	}
    30  }
    31  template: {
    32  	// trait template can have multiple outputs in one trait
    33  	outputs: service: {
    34  		apiVersion: "v1"
    35  		kind:       "Service"
    36  		metadata: name: context.name
    37  		spec: {
    38  			selector: "app.oam.dev/component": context.name
    39  			ports: [
    40  				for k, v in parameter.http {
    41  					port:       v
    42  					targetPort: v
    43  				},
    44  			]
    45  		}
    46  	}
    47  
    48  	outputs: ingress: {
    49  		apiVersion: "networking.k8s.io/v1"
    50  		kind:       "Ingress"
    51  		metadata: {
    52  			name: context.name
    53  			annotations: {
    54  				"kubernetes.io/ingress.class": parameter.class
    55  			}
    56  		}
    57  		spec: rules: [{
    58  			host: parameter.domain
    59  			http: paths: [
    60  				for k, v in parameter.http {
    61  					path:     k
    62  					pathType: "ImplementationSpecific"
    63  					backend: service: {
    64  						name: context.name
    65  						port: number: v
    66  					}
    67  				},
    68  			]
    69  		}]
    70  	}
    71  
    72  	parameter: {
    73  		// +usage=Specify the domain you want to expose
    74  		domain: string
    75  
    76  		// +usage=Specify the mapping relationship between the http path and the workload port
    77  		http: [string]: int
    78  
    79  		// +usage=Specify the class of ingress to use
    80  		class: *"nginx" | string
    81  	}
    82  }