github.com/oam-dev/kubevela@v1.9.11/charts/vela-core/templates/defwithtemplate/webservice.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/webservice.cue 3 apiVersion: core.oam.dev/v1beta1 4 kind: ComponentDefinition 5 metadata: 6 annotations: 7 definition.oam.dev/description: Describes long-running, scalable, containerized services that have a stable network endpoint to receive external network traffic from customers. 8 name: webservice 9 namespace: {{ include "systemDefinitionNamespace" . }} 10 spec: 11 schematic: 12 cue: 13 template: | 14 import ( 15 "strconv" 16 "strings" 17 ) 18 19 mountsArray: [ 20 if parameter.volumeMounts != _|_ && parameter.volumeMounts.pvc != _|_ for v in parameter.volumeMounts.pvc { 21 { 22 mountPath: v.mountPath 23 if v.subPath != _|_ { 24 subPath: v.subPath 25 } 26 name: v.name 27 } 28 }, 29 30 if parameter.volumeMounts != _|_ && parameter.volumeMounts.configMap != _|_ for v in parameter.volumeMounts.configMap { 31 { 32 mountPath: v.mountPath 33 if v.subPath != _|_ { 34 subPath: v.subPath 35 } 36 name: v.name 37 } 38 }, 39 40 if parameter.volumeMounts != _|_ && parameter.volumeMounts.secret != _|_ for v in parameter.volumeMounts.secret { 41 { 42 mountPath: v.mountPath 43 if v.subPath != _|_ { 44 subPath: v.subPath 45 } 46 name: v.name 47 } 48 }, 49 50 if parameter.volumeMounts != _|_ && parameter.volumeMounts.emptyDir != _|_ for v in parameter.volumeMounts.emptyDir { 51 { 52 mountPath: v.mountPath 53 if v.subPath != _|_ { 54 subPath: v.subPath 55 } 56 name: v.name 57 } 58 }, 59 60 if parameter.volumeMounts != _|_ && parameter.volumeMounts.hostPath != _|_ for v in parameter.volumeMounts.hostPath { 61 { 62 mountPath: v.mountPath 63 if v.subPath != _|_ { 64 subPath: v.subPath 65 } 66 name: v.name 67 } 68 }, 69 ] 70 71 volumesList: [ 72 if parameter.volumeMounts != _|_ && parameter.volumeMounts.pvc != _|_ for v in parameter.volumeMounts.pvc { 73 { 74 name: v.name 75 persistentVolumeClaim: claimName: v.claimName 76 } 77 }, 78 79 if parameter.volumeMounts != _|_ && parameter.volumeMounts.configMap != _|_ for v in parameter.volumeMounts.configMap { 80 { 81 name: v.name 82 configMap: { 83 defaultMode: v.defaultMode 84 name: v.cmName 85 if v.items != _|_ { 86 items: v.items 87 } 88 } 89 } 90 }, 91 92 if parameter.volumeMounts != _|_ && parameter.volumeMounts.secret != _|_ for v in parameter.volumeMounts.secret { 93 { 94 name: v.name 95 secret: { 96 defaultMode: v.defaultMode 97 secretName: v.secretName 98 if v.items != _|_ { 99 items: v.items 100 } 101 } 102 } 103 }, 104 105 if parameter.volumeMounts != _|_ && parameter.volumeMounts.emptyDir != _|_ for v in parameter.volumeMounts.emptyDir { 106 { 107 name: v.name 108 emptyDir: medium: v.medium 109 } 110 }, 111 112 if parameter.volumeMounts != _|_ && parameter.volumeMounts.hostPath != _|_ for v in parameter.volumeMounts.hostPath { 113 { 114 name: v.name 115 hostPath: path: v.path 116 } 117 }, 118 ] 119 120 deDupVolumesArray: [ 121 for val in [ 122 for i, vi in volumesList { 123 for j, vj in volumesList if j < i && vi.name == vj.name { 124 _ignore: true 125 } 126 vi 127 }, 128 ] if val._ignore == _|_ { 129 val 130 }, 131 ] 132 133 output: { 134 apiVersion: "apps/v1" 135 kind: "Deployment" 136 spec: { 137 selector: matchLabels: "app.oam.dev/component": context.name 138 139 template: { 140 metadata: { 141 labels: { 142 if parameter.labels != _|_ { 143 parameter.labels 144 } 145 if parameter.addRevisionLabel { 146 "app.oam.dev/revision": context.revision 147 } 148 "app.oam.dev/name": context.appName 149 "app.oam.dev/component": context.name 150 } 151 if parameter.annotations != _|_ { 152 annotations: parameter.annotations 153 } 154 } 155 156 spec: { 157 containers: [{ 158 name: context.name 159 image: parameter.image 160 if parameter["port"] != _|_ && parameter["ports"] == _|_ { 161 ports: [{ 162 containerPort: parameter.port 163 }] 164 } 165 if parameter["ports"] != _|_ { 166 ports: [ for v in parameter.ports { 167 { 168 containerPort: { 169 if v.containerPort != _|_ {v.containerPort} 170 if v.containerPort == _|_ {v.port} 171 } 172 protocol: v.protocol 173 if v.name != _|_ { 174 name: v.name 175 } 176 if v.name == _|_ { 177 _name: { 178 if v.containerPort != _|_ {"port-" + strconv.FormatInt(v.containerPort, 10)} 179 if v.containerPort == _|_ {"port-" + strconv.FormatInt(v.port, 10)} 180 } 181 name: *_name | string 182 if v.protocol != "TCP" { 183 name: _name + "-" + strings.ToLower(v.protocol) 184 } 185 } 186 }}] 187 } 188 189 if parameter["imagePullPolicy"] != _|_ { 190 imagePullPolicy: parameter.imagePullPolicy 191 } 192 193 if parameter["cmd"] != _|_ { 194 command: parameter.cmd 195 } 196 197 if parameter["args"] != _|_ { 198 args: parameter.args 199 } 200 201 if parameter["env"] != _|_ { 202 env: parameter.env 203 } 204 205 if context["config"] != _|_ { 206 env: context.config 207 } 208 209 if parameter["cpu"] != _|_ { 210 resources: { 211 limits: cpu: parameter.cpu 212 requests: cpu: parameter.cpu 213 } 214 } 215 216 if parameter["memory"] != _|_ { 217 resources: { 218 limits: memory: parameter.memory 219 requests: memory: parameter.memory 220 } 221 } 222 223 if parameter["volumes"] != _|_ && parameter["volumeMounts"] == _|_ { 224 volumeMounts: [ for v in parameter.volumes { 225 { 226 mountPath: v.mountPath 227 name: v.name 228 }}] 229 } 230 231 if parameter["volumeMounts"] != _|_ { 232 volumeMounts: mountsArray 233 } 234 235 if parameter["livenessProbe"] != _|_ { 236 livenessProbe: parameter.livenessProbe 237 } 238 239 if parameter["readinessProbe"] != _|_ { 240 readinessProbe: parameter.readinessProbe 241 } 242 243 }] 244 245 if parameter["hostAliases"] != _|_ { 246 // +patchKey=ip 247 hostAliases: parameter.hostAliases 248 } 249 250 if parameter["imagePullSecrets"] != _|_ { 251 imagePullSecrets: [ for v in parameter.imagePullSecrets { 252 name: v 253 }, 254 ] 255 } 256 257 if parameter["volumes"] != _|_ && parameter["volumeMounts"] == _|_ { 258 volumes: [ for v in parameter.volumes { 259 { 260 name: v.name 261 if v.type == "pvc" { 262 persistentVolumeClaim: claimName: v.claimName 263 } 264 if v.type == "configMap" { 265 configMap: { 266 defaultMode: v.defaultMode 267 name: v.cmName 268 if v.items != _|_ { 269 items: v.items 270 } 271 } 272 } 273 if v.type == "secret" { 274 secret: { 275 defaultMode: v.defaultMode 276 secretName: v.secretName 277 if v.items != _|_ { 278 items: v.items 279 } 280 } 281 } 282 if v.type == "emptyDir" { 283 emptyDir: medium: v.medium 284 } 285 } 286 }] 287 } 288 289 if parameter["volumeMounts"] != _|_ { 290 volumes: deDupVolumesArray 291 } 292 } 293 } 294 } 295 } 296 297 exposePorts: [ 298 if parameter.ports != _|_ for v in parameter.ports if v.expose == true { 299 port: v.port 300 if v.containerPort != _|_ {targetPort: v.containerPort} 301 if v.containerPort == _|_ {targetPort: v.port} 302 if v.name != _|_ {name: v.name} 303 if v.name == _|_ { 304 _name: { 305 if v.containerPort != _|_ { 306 "port-" + strconv.FormatInt(v.containerPort, 10) 307 } 308 if v.containerPort == _|_ { 309 "port-" + strconv.FormatInt(v.port, 10) 310 } 311 } 312 name: *_name | string 313 if v.protocol != "TCP" { 314 name: _name + "-" + strings.ToLower(v.protocol) 315 } 316 } 317 if v.nodePort != _|_ && parameter.exposeType == "NodePort" { 318 nodePort: v.nodePort 319 } 320 if v.protocol != _|_ { 321 protocol: v.protocol 322 } 323 }, 324 ] 325 326 outputs: { 327 if len(exposePorts) != 0 { 328 webserviceExpose: { 329 apiVersion: "v1" 330 kind: "Service" 331 metadata: name: context.name 332 spec: { 333 selector: "app.oam.dev/component": context.name 334 ports: exposePorts 335 type: parameter.exposeType 336 } 337 } 338 } 339 } 340 341 parameter: { 342 // +usage=Specify the labels in the workload 343 labels?: [string]: string 344 345 // +usage=Specify the annotations in the workload 346 annotations?: [string]: string 347 348 // +usage=Which image would you like to use for your service 349 // +short=i 350 image: string 351 352 // +usage=Specify image pull policy for your service 353 imagePullPolicy?: "Always" | "Never" | "IfNotPresent" 354 355 // +usage=Specify image pull secrets for your service 356 imagePullSecrets?: [...string] 357 358 // +ignore 359 // +usage=Deprecated field, please use ports instead 360 // +short=p 361 port?: int 362 363 // +usage=Which ports do you want customer traffic sent to, defaults to 80 364 ports?: [...{ 365 // +usage=Number of port to expose on the pod's IP address 366 port: int 367 // +usage=Number of container port to connect to, defaults to port 368 containerPort?: int 369 // +usage=Name of the port 370 name?: string 371 // +usage=Protocol for port. Must be UDP, TCP, or SCTP 372 protocol: *"TCP" | "UDP" | "SCTP" 373 // +usage=Specify if the port should be exposed 374 expose: *false | bool 375 // +usage=exposed node port. Only Valid when exposeType is NodePort 376 nodePort?: int 377 }] 378 379 // +ignore 380 // +usage=Specify what kind of Service you want. options: "ClusterIP", "NodePort", "LoadBalancer" 381 exposeType: *"ClusterIP" | "NodePort" | "LoadBalancer" 382 383 // +ignore 384 // +usage=If addRevisionLabel is true, the revision label will be added to the underlying pods 385 addRevisionLabel: *false | bool 386 387 // +usage=Commands to run in the container 388 cmd?: [...string] 389 390 // +usage=Arguments to the entrypoint 391 args?: [...string] 392 393 // +usage=Define arguments by using environment variables 394 env?: [...{ 395 // +usage=Environment variable name 396 name: string 397 // +usage=The value of the environment variable 398 value?: string 399 // +usage=Specifies a source the value of this var should come from 400 valueFrom?: { 401 // +usage=Selects a key of a secret in the pod's namespace 402 secretKeyRef?: { 403 // +usage=The name of the secret in the pod's namespace to select from 404 name: string 405 // +usage=The key of the secret to select from. Must be a valid secret key 406 key: string 407 } 408 // +usage=Selects a key of a config map in the pod's namespace 409 configMapKeyRef?: { 410 // +usage=The name of the config map in the pod's namespace to select from 411 name: string 412 // +usage=The key of the config map to select from. Must be a valid secret key 413 key: string 414 } 415 } 416 }] 417 418 // +usage=Number of CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core) 419 cpu?: string 420 421 // +usage=Specifies the attributes of the memory resource required for the container. 422 memory?: string 423 424 volumeMounts?: { 425 // +usage=Mount PVC type volume 426 pvc?: [...{ 427 name: string 428 mountPath: string 429 subPath?: string 430 // +usage=The name of the PVC 431 claimName: string 432 }] 433 // +usage=Mount ConfigMap type volume 434 configMap?: [...{ 435 name: string 436 mountPath: string 437 subPath?: string 438 defaultMode: *420 | int 439 cmName: string 440 items?: [...{ 441 key: string 442 path: string 443 mode: *511 | int 444 }] 445 }] 446 // +usage=Mount Secret type volume 447 secret?: [...{ 448 name: string 449 mountPath: string 450 subPath?: string 451 defaultMode: *420 | int 452 secretName: string 453 items?: [...{ 454 key: string 455 path: string 456 mode: *511 | int 457 }] 458 }] 459 // +usage=Mount EmptyDir type volume 460 emptyDir?: [...{ 461 name: string 462 mountPath: string 463 subPath?: string 464 medium: *"" | "Memory" 465 }] 466 // +usage=Mount HostPath type volume 467 hostPath?: [...{ 468 name: string 469 mountPath: string 470 subPath?: string 471 path: string 472 }] 473 } 474 475 // +usage=Deprecated field, use volumeMounts instead. 476 volumes?: [...{ 477 name: string 478 mountPath: string 479 // +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir", default to emptyDir 480 type: *"emptyDir" | "pvc" | "configMap" | "secret" 481 if type == "pvc" { 482 claimName: string 483 } 484 if type == "configMap" { 485 defaultMode: *420 | int 486 cmName: string 487 items?: [...{ 488 key: string 489 path: string 490 mode: *511 | int 491 }] 492 } 493 if type == "secret" { 494 defaultMode: *420 | int 495 secretName: string 496 items?: [...{ 497 key: string 498 path: string 499 mode: *511 | int 500 }] 501 } 502 if type == "emptyDir" { 503 medium: *"" | "Memory" 504 } 505 }] 506 507 // +usage=Instructions for assessing whether the container is alive. 508 livenessProbe?: #HealthProbe 509 510 // +usage=Instructions for assessing whether the container is in a suitable state to serve traffic. 511 readinessProbe?: #HealthProbe 512 513 // +usage=Specify the hostAliases to add 514 hostAliases?: [...{ 515 ip: string 516 hostnames: [...string] 517 }] 518 } 519 520 #HealthProbe: { 521 522 // +usage=Instructions for assessing container health by executing a command. Either this attribute or the httpGet attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the httpGet attribute and the tcpSocket attribute. 523 exec?: { 524 // +usage=A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures. 525 command: [...string] 526 } 527 528 // +usage=Instructions for assessing container health by executing an HTTP GET request. Either this attribute or the exec attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the tcpSocket attribute. 529 httpGet?: { 530 // +usage=The endpoint, relative to the port, to which the HTTP GET request should be directed. 531 path: string 532 // +usage=The TCP socket within the container to which the HTTP GET request should be directed. 533 port: int 534 host?: string 535 scheme?: *"HTTP" | string 536 httpHeaders?: [...{ 537 name: string 538 value: string 539 }] 540 } 541 542 // +usage=Instructions for assessing container health by probing a TCP socket. Either this attribute or the exec attribute or the httpGet attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the httpGet attribute. 543 tcpSocket?: { 544 // +usage=The TCP socket within the container that should be probed to assess container health. 545 port: int 546 } 547 548 // +usage=Number of seconds after the container is started before the first probe is initiated. 549 initialDelaySeconds: *0 | int 550 551 // +usage=How often, in seconds, to execute the probe. 552 periodSeconds: *10 | int 553 554 // +usage=Number of seconds after which the probe times out. 555 timeoutSeconds: *1 | int 556 557 // +usage=Minimum consecutive successes for the probe to be considered successful after having failed. 558 successThreshold: *1 | int 559 560 // +usage=Number of consecutive failures required to determine the container is not alive (liveness probe) or not ready (readiness probe). 561 failureThreshold: *3 | int 562 } 563 status: 564 customStatus: |- 565 ready: { 566 readyReplicas: *0 | int 567 } & { 568 if context.output.status.readyReplicas != _|_ { 569 readyReplicas: context.output.status.readyReplicas 570 } 571 } 572 message: "Ready:\(ready.readyReplicas)/\(context.output.spec.replicas)" 573 healthPolicy: |- 574 ready: { 575 updatedReplicas: *0 | int 576 readyReplicas: *0 | int 577 replicas: *0 | int 578 observedGeneration: *0 | int 579 } & { 580 if context.output.status.updatedReplicas != _|_ { 581 updatedReplicas: context.output.status.updatedReplicas 582 } 583 if context.output.status.readyReplicas != _|_ { 584 readyReplicas: context.output.status.readyReplicas 585 } 586 if context.output.status.replicas != _|_ { 587 replicas: context.output.status.replicas 588 } 589 if context.output.status.observedGeneration != _|_ { 590 observedGeneration: context.output.status.observedGeneration 591 } 592 } 593 _isHealth: (context.output.spec.replicas == ready.readyReplicas) && (context.output.spec.replicas == ready.updatedReplicas) && (context.output.spec.replicas == ready.replicas) && (ready.observedGeneration == context.output.metadata.generation || ready.observedGeneration > context.output.metadata.generation) 594 isHealth: *_isHealth | bool 595 if context.output.metadata.annotations != _|_ { 596 if context.output.metadata.annotations["app.oam.dev/disable-health-check"] != _|_ { 597 isHealth: true 598 } 599 } 600 workload: 601 definition: 602 apiVersion: apps/v1 603 kind: Deployment 604 type: deployments.apps 605