github.com/oam-dev/kubevela@v1.9.11/charts/vela-core/templates/defwithtemplate/gateway.yaml (about) 1 # Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file. 2 # Definition source cue file: vela-templates/definitions/internal/gateway.cue 3 apiVersion: core.oam.dev/v1beta1 4 kind: TraitDefinition 5 metadata: 6 annotations: 7 definition.oam.dev/description: Enable public web traffic for the component, the ingress API matches K8s v1.20+. 8 name: gateway 9 namespace: {{ include "systemDefinitionNamespace" . }} 10 spec: 11 appliesToWorkloads: 12 - deployments.apps 13 - statefulsets.apps 14 podDisruptive: false 15 schematic: 16 cue: 17 template: | 18 import "strconv" 19 20 let nameSuffix = { 21 if parameter.name != _|_ {"-" + parameter.name} 22 if parameter.name == _|_ {""} 23 } 24 25 let serviceMetaName = { 26 if (parameter.existingServiceName != _|_) {parameter.existingServiceName} 27 if (parameter.existingServiceName == _|_) {context.name + nameSuffix} 28 } 29 30 if (parameter.existingServiceName == _|_) { 31 let serviceOutputName = "service" + nameSuffix 32 outputs: (serviceOutputName): { 33 apiVersion: "v1" 34 kind: "Service" 35 metadata: name: "\(serviceMetaName)" 36 spec: { 37 selector: "app.oam.dev/component": context.name 38 ports: [ 39 for k, v in parameter.http { 40 name: "port-" + strconv.FormatInt(v, 10) 41 port: v 42 targetPort: v 43 }, 44 ] 45 } 46 } 47 } 48 49 let ingressOutputName = "ingress" + nameSuffix 50 let ingressMetaName = context.name + nameSuffix 51 legacyAPI: context.clusterVersion.minor < 19 52 53 outputs: (ingressOutputName): { 54 if legacyAPI { 55 apiVersion: "networking.k8s.io/v1beta1" 56 } 57 if !legacyAPI { 58 apiVersion: "networking.k8s.io/v1" 59 } 60 kind: "Ingress" 61 metadata: { 62 name: "\(ingressMetaName)" 63 annotations: { 64 if !parameter.classInSpec { 65 "kubernetes.io/ingress.class": parameter.class 66 } 67 if parameter.gatewayHost != _|_ { 68 "ingress.controller/host": parameter.gatewayHost 69 } 70 if parameter.annotations != _|_ { 71 for key, value in parameter.annotations { 72 "\(key)": "\(value)" 73 } 74 } 75 } 76 labels: { 77 if parameter.labels != _|_ { 78 for key, value in parameter.labels { 79 "\(key)": "\(value)" 80 } 81 } 82 } 83 } 84 spec: { 85 if parameter.classInSpec { 86 ingressClassName: parameter.class 87 } 88 if parameter.secretName != _|_ { 89 tls: [{ 90 hosts: [ 91 parameter.domain, 92 ] 93 secretName: parameter.secretName 94 }] 95 } 96 rules: [{ 97 if parameter.domain != _|_ { 98 host: parameter.domain 99 } 100 http: paths: [ 101 for k, v in parameter.http { 102 path: k 103 pathType: parameter.pathType 104 backend: { 105 if legacyAPI { 106 serviceName: serviceMetaName 107 servicePort: v 108 } 109 if !legacyAPI { 110 service: { 111 name: serviceMetaName 112 port: number: v 113 } 114 } 115 } 116 }, 117 ] 118 }] 119 } 120 } 121 122 parameter: { 123 // +usage=Specify the domain you want to expose 124 domain?: string 125 126 // +usage=Specify the mapping relationship between the http path and the workload port 127 http: [string]: int 128 129 // +usage=Specify the class of ingress to use 130 class: *"nginx" | string 131 132 // +usage=Set ingress class in '.spec.ingressClassName' instead of 'kubernetes.io/ingress.class' annotation. 133 classInSpec: *false | bool 134 135 // +usage=Specify the secret name you want to quote to use tls. 136 secretName?: string 137 138 // +usage=Specify the host of the ingress gateway, which is used to generate the endpoints when the host is empty. 139 gatewayHost?: string 140 141 // +usage=Specify a unique name for this gateway, required to support multiple gateway traits on a component 142 name?: string 143 144 // +usage=Specify a pathType for the ingress rules, defaults to "ImplementationSpecific" 145 pathType: *"ImplementationSpecific" | "Prefix" | "Exact" 146 147 // +usage=Specify the annotations to be added to the ingress 148 annotations?: [string]: string 149 150 // +usage=Specify the labels to be added to the ingress 151 labels?: [string]: string 152 153 // +usage=If specified, use an existing Service rather than creating one 154 existingServiceName?: string 155 } 156 status: 157 customStatus: |- 158 let nameSuffix = { 159 if parameter.name != _|_ { "-" + parameter.name } 160 if parameter.name == _|_ { "" } 161 } 162 let ingressMetaName = context.name + nameSuffix 163 let ig = [for i in context.outputs if (i.kind == "Ingress") && (i.metadata.name == ingressMetaName) {i}][0] 164 igs: *null | string 165 if ig != _|_ if ig.status != _|_ if ig.status.loadbalancer != _|_ { 166 igs: ig.status.loadbalancer.ingress[0] 167 } 168 igr: *null | string 169 if ig != _|_ if ig.spec != _|_ { 170 igr: ig.spec.rules[0] 171 } 172 if igs == _|_ { 173 message: "No loadBalancer found, visiting by using 'vela port-forward " + context.appName + "'\n" 174 } 175 if igs != _|_ { 176 if igs.ip != _|_ { 177 if igr.host != _|_ { 178 message: "Visiting URL: " + igr.host + ", IP: " + igs.ip + "\n" 179 } 180 if igr.host == _|_ { 181 message: "Host not specified, visit the cluster or load balancer in front of the cluster, IP: " + igs.ip + "\n" 182 } 183 } 184 if igs.ip == _|_ { 185 if igr.host != _|_ { 186 message: "Visiting URL: " + igr.host + "\n" 187 } 188 if igs.host == _|_ { 189 message: "Host not specified, visit the cluster or load balancer in front of the cluster\n" 190 } 191 } 192 } 193 healthPolicy: |- 194 let nameSuffix = { 195 if parameter.name != _|_ { "-" + parameter.name } 196 if parameter.name == _|_ { "" } 197 } 198 let ingressMetaName = context.name + nameSuffix 199 let igstat = len([for i in context.outputs if (i.kind == "Ingress") && (i.metadata.name == ingressMetaName) {i}]) > 0 200 isHealth: igstat 201