github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/component/cron-task.cue (about) 1 "cron-task": { 2 type: "component" 3 annotations: {} 4 labels: {} 5 description: "Describes cron jobs that run code or a script to completion." 6 attributes: workload: type: "autodetects.core.oam.dev" 7 } 8 template: { 9 mountsArray: { 10 pvc: *[ 11 for v in parameter.volumeMounts.pvc { 12 { 13 mountPath: v.mountPath 14 if v.subPath != _|_ { 15 subPath: v.subPath 16 } 17 name: v.name 18 } 19 }, 20 ] | [] 21 22 configMap: *[ 23 for v in parameter.volumeMounts.configMap { 24 { 25 mountPath: v.mountPath 26 if v.subPath != _|_ { 27 subPath: v.subPath 28 } 29 name: v.name 30 } 31 }, 32 ] | [] 33 34 secret: *[ 35 for v in parameter.volumeMounts.secret { 36 { 37 mountPath: v.mountPath 38 if v.subPath != _|_ { 39 subPath: v.subPath 40 } 41 name: v.name 42 } 43 }, 44 ] | [] 45 46 emptyDir: *[ 47 for v in parameter.volumeMounts.emptyDir { 48 { 49 mountPath: v.mountPath 50 if v.subPath != _|_ { 51 subPath: v.subPath 52 } 53 name: v.name 54 } 55 }, 56 ] | [] 57 58 hostPath: *[ 59 for v in parameter.volumeMounts.hostPath { 60 { 61 mountPath: v.mountPath 62 if v.subPath != _|_ { 63 subPath: v.subPath 64 } 65 name: v.name 66 } 67 }, 68 ] | [] 69 } 70 volumesArray: { 71 pvc: *[ 72 for v in parameter.volumeMounts.pvc { 73 { 74 name: v.name 75 persistentVolumeClaim: claimName: v.claimName 76 } 77 }, 78 ] | [] 79 80 configMap: *[ 81 for v in parameter.volumeMounts.configMap { 82 { 83 name: v.name 84 configMap: { 85 defaultMode: v.defaultMode 86 name: v.cmName 87 if v.items != _|_ { 88 items: v.items 89 } 90 } 91 } 92 }, 93 ] | [] 94 95 secret: *[ 96 for v in parameter.volumeMounts.secret { 97 { 98 name: v.name 99 secret: { 100 defaultMode: v.defaultMode 101 secretName: v.secretName 102 if v.items != _|_ { 103 items: v.items 104 } 105 } 106 } 107 }, 108 ] | [] 109 110 emptyDir: *[ 111 for v in parameter.volumeMounts.emptyDir { 112 { 113 name: v.name 114 emptyDir: medium: v.medium 115 } 116 }, 117 ] | [] 118 119 hostPath: *[ 120 for v in parameter.volumeMounts.hostPath { 121 { 122 name: v.name 123 hostPath: path: v.path 124 } 125 }, 126 ] | [] 127 } 128 volumesList: volumesArray.pvc + volumesArray.configMap + volumesArray.secret + volumesArray.emptyDir + volumesArray.hostPath 129 deDupVolumesArray: [ 130 for val in [ 131 for i, vi in volumesList { 132 for j, vj in volumesList if j < i && vi.name == vj.name { 133 _ignore: true 134 } 135 vi 136 }, 137 ] if val._ignore == _|_ { 138 val 139 }, 140 ] 141 output: { 142 if context.clusterVersion.minor < 25 { 143 apiVersion: "batch/v1beta1" 144 } 145 if context.clusterVersion.minor >= 25 { 146 apiVersion: "batch/v1" 147 } 148 kind: "CronJob" 149 spec: { 150 schedule: parameter.schedule 151 concurrencyPolicy: parameter.concurrencyPolicy 152 suspend: parameter.suspend 153 successfulJobsHistoryLimit: parameter.successfulJobsHistoryLimit 154 failedJobsHistoryLimit: parameter.failedJobsHistoryLimit 155 if parameter.startingDeadlineSeconds != _|_ { 156 startingDeadlineSeconds: parameter.startingDeadlineSeconds 157 } 158 jobTemplate: { 159 metadata: { 160 labels: { 161 if parameter.labels != _|_ { 162 parameter.labels 163 } 164 "app.oam.dev/name": context.appName 165 "app.oam.dev/component": context.name 166 } 167 if parameter.annotations != _|_ { 168 annotations: parameter.annotations 169 } 170 } 171 spec: { 172 parallelism: parameter.count 173 completions: parameter.count 174 if parameter.ttlSecondsAfterFinished != _|_ { 175 ttlSecondsAfterFinished: parameter.ttlSecondsAfterFinished 176 } 177 if parameter.activeDeadlineSeconds != _|_ { 178 activeDeadlineSeconds: parameter.activeDeadlineSeconds 179 } 180 backoffLimit: parameter.backoffLimit 181 template: { 182 metadata: { 183 labels: { 184 if parameter.labels != _|_ { 185 parameter.labels 186 } 187 "app.oam.dev/name": context.appName 188 "app.oam.dev/component": context.name 189 } 190 if parameter.annotations != _|_ { 191 annotations: parameter.annotations 192 } 193 } 194 spec: { 195 restartPolicy: parameter.restart 196 containers: [{ 197 name: context.name 198 image: parameter.image 199 if parameter["imagePullPolicy"] != _|_ { 200 imagePullPolicy: parameter.imagePullPolicy 201 } 202 if parameter["cmd"] != _|_ { 203 command: parameter.cmd 204 } 205 if parameter["env"] != _|_ { 206 env: parameter.env 207 } 208 if parameter["cpu"] != _|_ { 209 resources: { 210 limits: cpu: parameter.cpu 211 requests: cpu: parameter.cpu 212 } 213 } 214 if parameter["memory"] != _|_ { 215 resources: { 216 limits: memory: parameter.memory 217 requests: memory: parameter.memory 218 } 219 } 220 if parameter["volumes"] != _|_ if parameter["volumeMounts"] == _|_ { 221 volumeMounts: [ for v in parameter.volumes { 222 { 223 mountPath: v.mountPath 224 name: v.name 225 }}] 226 } 227 if parameter["volumeMounts"] != _|_ { 228 volumeMounts: mountsArray.pvc + mountsArray.configMap + mountsArray.secret + mountsArray.emptyDir + mountsArray.hostPath 229 } 230 }] 231 if parameter["volumes"] != _|_ if parameter["volumeMounts"] == _|_ { 232 volumes: [ for v in parameter.volumes { 233 { 234 name: v.name 235 if v.type == "pvc" { 236 persistentVolumeClaim: claimName: v.claimName 237 } 238 if v.type == "configMap" { 239 configMap: { 240 defaultMode: v.defaultMode 241 name: v.cmName 242 if v.items != _|_ { 243 items: v.items 244 } 245 } 246 } 247 if v.type == "secret" { 248 secret: { 249 defaultMode: v.defaultMode 250 secretName: v.secretName 251 if v.items != _|_ { 252 items: v.items 253 } 254 } 255 } 256 if v.type == "emptyDir" { 257 emptyDir: medium: v.medium 258 } 259 }}] 260 } 261 if parameter["volumeMounts"] != _|_ { 262 volumes: deDupVolumesArray 263 } 264 if parameter["imagePullSecrets"] != _|_ { 265 imagePullSecrets: [ for v in parameter.imagePullSecrets { 266 name: v 267 }, 268 ] 269 } 270 if parameter.hostAliases != _|_ { 271 hostAliases: [ for v in parameter.hostAliases { 272 ip: v.ip 273 hostnames: v.hostnames 274 }, 275 ] 276 } 277 } 278 } 279 } 280 } 281 } 282 } 283 284 parameter: { 285 // +usage=Specify the labels in the workload 286 labels?: [string]: string 287 288 // +usage=Specify the annotations in the workload 289 annotations?: [string]: string 290 291 // +usage=Specify the schedule in Cron format, see https://en.wikipedia.org/wiki/Cron 292 schedule: string 293 294 // +usage=Specify deadline in seconds for starting the job if it misses scheduled 295 startingDeadlineSeconds?: int 296 297 // +usage=suspend subsequent executions 298 suspend: *false | bool 299 300 // +usage=Specifies how to treat concurrent executions of a Job 301 concurrencyPolicy: *"Allow" | "Allow" | "Forbid" | "Replace" 302 303 // +usage=The number of successful finished jobs to retain 304 successfulJobsHistoryLimit: *3 | int 305 306 // +usage=The number of failed finished jobs to retain 307 failedJobsHistoryLimit: *1 | int 308 309 // +usage=Specify number of tasks to run in parallel 310 // +short=c 311 count: *1 | int 312 313 // +usage=Which image would you like to use for your service 314 // +short=i 315 image: string 316 317 // +usage=Specify image pull policy for your service 318 imagePullPolicy?: "Always" | "Never" | "IfNotPresent" 319 320 // +usage=Specify image pull secrets for your service 321 imagePullSecrets?: [...string] 322 323 // +usage=Define the job restart policy, the value can only be Never or OnFailure. By default, it's Never. 324 restart: *"Never" | string 325 326 // +usage=Commands to run in the container 327 cmd?: [...string] 328 329 // +usage=Define arguments by using environment variables 330 env?: [...{ 331 // +usage=Environment variable name 332 name: string 333 // +usage=The value of the environment variable 334 value?: string 335 // +usage=Specifies a source the value of this var should come from 336 valueFrom?: { 337 // +usage=Selects a key of a secret in the pod's namespace 338 secretKeyRef?: { 339 // +usage=The name of the secret in the pod's namespace to select from 340 name: string 341 // +usage=The key of the secret to select from. Must be a valid secret key 342 key: string 343 } 344 // +usage=Selects a key of a config map in the pod's namespace 345 configMapKeyRef?: { 346 // +usage=The name of the config map in the pod's namespace to select from 347 name: string 348 // +usage=The key of the config map to select from. Must be a valid secret key 349 key: string 350 } 351 } 352 }] 353 354 // +usage=Number of CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core) 355 cpu?: string 356 357 // +usage=Specifies the attributes of the memory resource required for the container. 358 memory?: string 359 360 volumeMounts?: { 361 // +usage=Mount PVC type volume 362 pvc?: [...{ 363 name: string 364 mountPath: string 365 subPath?: string 366 // +usage=The name of the PVC 367 claimName: string 368 }] 369 // +usage=Mount ConfigMap type volume 370 configMap?: [...{ 371 name: string 372 mountPath: string 373 subPath?: string 374 defaultMode: *420 | int 375 cmName: string 376 items?: [...{ 377 key: string 378 path: string 379 mode: *511 | int 380 }] 381 }] 382 // +usage=Mount Secret type volume 383 secret?: [...{ 384 name: string 385 mountPath: string 386 subPath?: string 387 defaultMode: *420 | int 388 secretName: string 389 items?: [...{ 390 key: string 391 path: string 392 mode: *511 | int 393 }] 394 }] 395 // +usage=Mount EmptyDir type volume 396 emptyDir?: [...{ 397 name: string 398 mountPath: string 399 subPath?: string 400 medium: *"" | "Memory" 401 }] 402 // +usage=Mount HostPath type volume 403 hostPath?: [...{ 404 name: string 405 mountPath: string 406 subPath?: string 407 path: string 408 }] 409 } 410 411 // +usage=Deprecated field, use volumeMounts instead. 412 volumes?: [...{ 413 name: string 414 mountPath: string 415 // +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir", default to emptyDir 416 type: *"emptyDir" | "pvc" | "configMap" | "secret" 417 if type == "pvc" { 418 claimName: string 419 } 420 if type == "configMap" { 421 defaultMode: *420 | int 422 cmName: string 423 items?: [...{ 424 key: string 425 path: string 426 mode: *511 | int 427 }] 428 } 429 if type == "secret" { 430 defaultMode: *420 | int 431 secretName: string 432 items?: [...{ 433 key: string 434 path: string 435 mode: *511 | int 436 }] 437 } 438 if type == "emptyDir" { 439 medium: *"" | "Memory" 440 } 441 }] 442 443 // +usage=An optional list of hosts and IPs that will be injected into the pod's hosts file 444 hostAliases?: [...{ 445 ip: string 446 hostnames: [...string] 447 }] 448 449 // +usage=Limits the lifetime of a Job that has finished 450 ttlSecondsAfterFinished?: int 451 452 // +usage=The duration in seconds relative to the startTime that the job may be continuously active before the system tries to terminate it 453 activeDeadlineSeconds?: int 454 455 // +usage=The number of retries before marking this job failed 456 backoffLimit: *6 | int 457 458 // +usage=Instructions for assessing whether the container is alive. 459 livenessProbe?: #HealthProbe 460 461 // +usage=Instructions for assessing whether the container is in a suitable state to serve traffic. 462 readinessProbe?: #HealthProbe 463 } 464 465 #HealthProbe: { 466 467 // +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. 468 exec?: { 469 // +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. 470 command: [...string] 471 } 472 473 // +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. 474 httpGet?: { 475 // +usage=The endpoint, relative to the port, to which the HTTP GET request should be directed. 476 path: string 477 // +usage=The TCP socket within the container to which the HTTP GET request should be directed. 478 port: int 479 httpHeaders?: [...{ 480 name: string 481 value: string 482 }] 483 } 484 485 // +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. 486 tcpSocket?: { 487 // +usage=The TCP socket within the container that should be probed to assess container health. 488 port: int 489 } 490 491 // +usage=Number of seconds after the container is started before the first probe is initiated. 492 initialDelaySeconds: *0 | int 493 494 // +usage=How often, in seconds, to execute the probe. 495 periodSeconds: *10 | int 496 497 // +usage=Number of seconds after which the probe times out. 498 timeoutSeconds: *1 | int 499 500 // +usage=Minimum consecutive successes for the probe to be considered successful after having failed. 501 successThreshold: *1 | int 502 503 // +usage=Number of consecutive failures required to determine the container is not alive (liveness probe) or not ready (readiness probe). 504 failureThreshold: *3 | int 505 } 506 }