github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/component/worker.cue (about) 1 worker: { 2 type: "component" 3 annotations: {} 4 labels: { 5 "ui-hidden": "true" 6 } 7 description: "Describes long-running, scalable, containerized services that running at backend. They do NOT have network endpoint to receive external network traffic." 8 attributes: { 9 workload: { 10 definition: { 11 apiVersion: "apps/v1" 12 kind: "Deployment" 13 } 14 type: "deployments.apps" 15 } 16 status: { 17 customStatus: #""" 18 ready: { 19 readyReplicas: *0 | int 20 } & { 21 if context.output.status.readyReplicas != _|_ { 22 readyReplicas: context.output.status.readyReplicas 23 } 24 } 25 message: "Ready:\(ready.readyReplicas)/\(context.output.spec.replicas)" 26 """# 27 healthPolicy: #""" 28 ready: { 29 updatedReplicas: *0 | int 30 readyReplicas: *0 | int 31 replicas: *0 | int 32 observedGeneration: *0 | int 33 } & { 34 if context.output.status.updatedReplicas != _|_ { 35 updatedReplicas: context.output.status.updatedReplicas 36 } 37 if context.output.status.readyReplicas != _|_ { 38 readyReplicas: context.output.status.readyReplicas 39 } 40 if context.output.status.replicas != _|_ { 41 replicas: context.output.status.replicas 42 } 43 if context.output.status.observedGeneration != _|_ { 44 observedGeneration: context.output.status.observedGeneration 45 } 46 } 47 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) 48 """# 49 } 50 } 51 } 52 template: { 53 mountsArray: [ 54 if parameter.volumeMounts != _|_ && parameter.volumeMounts.pvc != _|_ for v in parameter.volumeMounts.pvc { 55 { 56 mountPath: v.mountPath 57 if v.subPath != _|_ { 58 subPath: v.subPath 59 } 60 name: v.name 61 } 62 }, 63 64 if parameter.volumeMounts != _|_ && parameter.volumeMounts.configMap != _|_ for v in parameter.volumeMounts.configMap { 65 { 66 mountPath: v.mountPath 67 if v.subPath != _|_ { 68 subPath: v.subPath 69 } 70 name: v.name 71 } 72 }, 73 74 if parameter.volumeMounts != _|_ && parameter.volumeMounts.secret != _|_ for v in parameter.volumeMounts.secret { 75 { 76 mountPath: v.mountPath 77 if v.subPath != _|_ { 78 subPath: v.subPath 79 } 80 name: v.name 81 } 82 }, 83 84 if parameter.volumeMounts != _|_ && parameter.volumeMounts.emptyDir != _|_ for v in parameter.volumeMounts.emptyDir { 85 { 86 mountPath: v.mountPath 87 if v.subPath != _|_ { 88 subPath: v.subPath 89 } 90 name: v.name 91 } 92 }, 93 94 if parameter.volumeMounts != _|_ && parameter.volumeMounts.hostPath != _|_ for v in parameter.volumeMounts.hostPath { 95 { 96 mountPath: v.mountPath 97 if v.subPath != _|_ { 98 subPath: v.subPath 99 } 100 name: v.name 101 } 102 }, 103 ] 104 105 volumesList: [ 106 if parameter.volumeMounts != _|_ && parameter.volumeMounts.pvc != _|_ for v in parameter.volumeMounts.pvc { 107 { 108 name: v.name 109 persistentVolumeClaim: claimName: v.claimName 110 } 111 }, 112 113 if parameter.volumeMounts != _|_ && parameter.volumeMounts.configMap != _|_ for v in parameter.volumeMounts.configMap { 114 { 115 name: v.name 116 configMap: { 117 defaultMode: v.defaultMode 118 name: v.cmName 119 if v.items != _|_ { 120 items: v.items 121 } 122 } 123 } 124 }, 125 126 if parameter.volumeMounts != _|_ && parameter.volumeMounts.secret != _|_ for v in parameter.volumeMounts.secret { 127 { 128 name: v.name 129 secret: { 130 defaultMode: v.defaultMode 131 secretName: v.secretName 132 if v.items != _|_ { 133 items: v.items 134 } 135 } 136 } 137 }, 138 139 if parameter.volumeMounts != _|_ && parameter.volumeMounts.emptyDir != _|_ for v in parameter.volumeMounts.emptyDir { 140 { 141 name: v.name 142 emptyDir: medium: v.medium 143 } 144 }, 145 146 if parameter.volumeMounts != _|_ && parameter.volumeMounts.hostPath != _|_ for v in parameter.volumeMounts.hostPath { 147 { 148 name: v.name 149 hostPath: { 150 path: v.path 151 } 152 } 153 }, 154 ] 155 156 deDupVolumesArray: [ 157 for val in [ 158 for i, vi in volumesList { 159 for j, vj in volumesList if j < i && vi.name == vj.name { 160 _ignore: true 161 } 162 vi 163 }, 164 ] if val._ignore == _|_ { 165 val 166 }, 167 ] 168 169 output: { 170 apiVersion: "apps/v1" 171 kind: "Deployment" 172 spec: { 173 selector: matchLabels: "app.oam.dev/component": context.name 174 175 template: { 176 metadata: { 177 labels: { 178 "app.oam.dev/name": context.appName 179 "app.oam.dev/component": context.name 180 } 181 } 182 183 spec: { 184 containers: [{ 185 name: context.name 186 image: parameter.image 187 188 if parameter["imagePullPolicy"] != _|_ { 189 imagePullPolicy: parameter.imagePullPolicy 190 } 191 192 if parameter["cmd"] != _|_ { 193 command: parameter.cmd 194 } 195 196 if parameter["env"] != _|_ { 197 env: parameter.env 198 } 199 200 if parameter["cpu"] != _|_ { 201 resources: { 202 limits: cpu: parameter.cpu 203 requests: cpu: parameter.cpu 204 } 205 } 206 207 if parameter["memory"] != _|_ { 208 resources: { 209 limits: memory: parameter.memory 210 requests: memory: parameter.memory 211 } 212 } 213 214 if parameter["volumes"] != _|_ && parameter["volumeMounts"] == _|_ { 215 volumeMounts: [ for v in parameter.volumes { 216 { 217 mountPath: v.mountPath 218 name: v.name 219 }}] 220 } 221 222 if parameter["volumeMounts"] != _|_ { 223 volumeMounts: mountsArray 224 } 225 226 if parameter["livenessProbe"] != _|_ { 227 livenessProbe: parameter.livenessProbe 228 } 229 230 if parameter["readinessProbe"] != _|_ { 231 readinessProbe: parameter.readinessProbe 232 } 233 234 }] 235 236 if parameter["imagePullSecrets"] != _|_ { 237 imagePullSecrets: [ for v in parameter.imagePullSecrets { 238 name: v 239 }, 240 ] 241 } 242 243 if parameter["volumes"] != _|_ && parameter["volumeMounts"] == _|_ { 244 volumes: [ for v in parameter.volumes { 245 { 246 name: v.name 247 if v.type == "pvc" { 248 persistentVolumeClaim: claimName: v.claimName 249 } 250 if v.type == "configMap" { 251 configMap: { 252 defaultMode: v.defaultMode 253 name: v.cmName 254 if v.items != _|_ { 255 items: v.items 256 } 257 } 258 } 259 if v.type == "secret" { 260 secret: { 261 defaultMode: v.defaultMode 262 secretName: v.secretName 263 if v.items != _|_ { 264 items: v.items 265 } 266 } 267 } 268 if v.type == "emptyDir" { 269 emptyDir: medium: v.medium 270 } 271 } 272 }] 273 } 274 if parameter["volumeMounts"] != _|_ { 275 volumes: deDupVolumesArray 276 } 277 } 278 } 279 } 280 } 281 282 parameter: { 283 // +usage=Which image would you like to use for your service 284 // +short=i 285 image: string 286 287 // +usage=Specify image pull policy for your service 288 imagePullPolicy?: string 289 290 // +usage=Specify image pull secrets for your service 291 imagePullSecrets?: [...string] 292 293 // +usage=Commands to run in the container 294 cmd?: [...string] 295 296 // +usage=Define arguments by using environment variables 297 env?: [...{ 298 // +usage=Environment variable name 299 name: string 300 // +usage=The value of the environment variable 301 value?: string 302 // +usage=Specifies a source the value of this var should come from 303 valueFrom?: { 304 // +usage=Selects a key of a secret in the pod's namespace 305 secretKeyRef?: { 306 // +usage=The name of the secret in the pod's namespace to select from 307 name: string 308 // +usage=The key of the secret to select from. Must be a valid secret key 309 key: string 310 } 311 // +usage=Selects a key of a config map in the pod's namespace 312 configMapKeyRef?: { 313 // +usage=The name of the config map in the pod's namespace to select from 314 name: string 315 // +usage=The key of the config map to select from. Must be a valid secret key 316 key: string 317 } 318 } 319 }] 320 321 // +usage=Number of CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core) 322 cpu?: string 323 324 // +usage=Specifies the attributes of the memory resource required for the container. 325 memory?: string 326 327 volumeMounts?: { 328 // +usage=Mount PVC type volume 329 pvc?: [...{ 330 name: string 331 mountPath: string 332 // +usage=The name of the PVC 333 claimName: string 334 }] 335 // +usage=Mount ConfigMap type volume 336 configMap?: [...{ 337 name: string 338 mountPath: string 339 defaultMode: *420 | int 340 cmName: string 341 items?: [...{ 342 key: string 343 path: string 344 mode: *511 | int 345 }] 346 }] 347 // +usage=Mount Secret type volume 348 secret?: [...{ 349 name: string 350 mountPath: string 351 defaultMode: *420 | int 352 secretName: string 353 items?: [...{ 354 key: string 355 path: string 356 mode: *511 | int 357 }] 358 }] 359 // +usage=Mount EmptyDir type volume 360 emptyDir?: [...{ 361 name: string 362 mountPath: string 363 medium: *"" | "Memory" 364 }] 365 // +usage=Mount HostPath type volume 366 hostPath?: [...{ 367 name: string 368 mountPath: string 369 path: string 370 }] 371 } 372 373 // +usage=Deprecated field, use volumeMounts instead. 374 volumes?: [...{ 375 name: string 376 mountPath: string 377 // +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir", default to emptyDir 378 type: *"emptyDir" | "pvc" | "configMap" | "secret" 379 if type == "pvc" { 380 claimName: string 381 } 382 if type == "configMap" { 383 defaultMode: *420 | int 384 cmName: string 385 items?: [...{ 386 key: string 387 path: string 388 mode: *511 | int 389 }] 390 } 391 if type == "secret" { 392 defaultMode: *420 | int 393 secretName: string 394 items?: [...{ 395 key: string 396 path: string 397 mode: *511 | int 398 }] 399 } 400 if type == "emptyDir" { 401 medium: *"" | "Memory" 402 } 403 }] 404 405 // +usage=Instructions for assessing whether the container is alive. 406 livenessProbe?: #HealthProbe 407 408 // +usage=Instructions for assessing whether the container is in a suitable state to serve traffic. 409 readinessProbe?: #HealthProbe 410 } 411 412 #HealthProbe: { 413 414 // +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. 415 exec?: { 416 // +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. 417 command: [...string] 418 } 419 420 // +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. 421 httpGet?: { 422 // +usage=The endpoint, relative to the port, to which the HTTP GET request should be directed. 423 path: string 424 // +usage=The TCP socket within the container to which the HTTP GET request should be directed. 425 port: int 426 httpHeaders?: [...{ 427 name: string 428 value: string 429 }] 430 } 431 432 // +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. 433 tcpSocket?: { 434 // +usage=The TCP socket within the container that should be probed to assess container health. 435 port: int 436 } 437 438 // +usage=Number of seconds after the container is started before the first probe is initiated. 439 initialDelaySeconds: *0 | int 440 441 // +usage=How often, in seconds, to execute the probe. 442 periodSeconds: *10 | int 443 444 // +usage=Number of seconds after which the probe times out. 445 timeoutSeconds: *1 | int 446 447 // +usage=Minimum consecutive successes for the probe to be considered successful after having failed. 448 successThreshold: *1 | int 449 450 // +usage=Number of consecutive failures required to determine the container is not alive (liveness probe) or not ready (readiness probe). 451 failureThreshold: *3 | int 452 } 453 }