github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/component/task.cue (about) 1 task: { 2 type: "component" 3 annotations: {} 4 labels: {} 5 description: "Describes jobs that run code or a script to completion." 6 attributes: { 7 workload: { 8 definition: { 9 apiVersion: "batch/v1" 10 kind: "Job" 11 } 12 type: "jobs.batch" 13 } 14 status: { 15 customStatus: #""" 16 status: { 17 active: *0 | int 18 failed: *0 | int 19 succeeded: *0 | int 20 } & { 21 if context.output.status.active != _|_ { 22 active: context.output.status.active 23 } 24 if context.output.status.failed != _|_ { 25 failed: context.output.status.failed 26 } 27 if context.output.status.succeeded != _|_ { 28 succeeded: context.output.status.succeeded 29 } 30 } 31 message: "Active/Failed/Succeeded:\(status.active)/\(status.failed)/\(status.succeeded)" 32 """# 33 healthPolicy: #""" 34 succeeded: *0 | int 35 if context.output.status.succeeded != _|_ { 36 succeeded: context.output.status.succeeded 37 } 38 isHealth: succeeded == context.output.spec.parallelism 39 """# 40 } 41 } 42 } 43 template: { 44 output: { 45 apiVersion: "batch/v1" 46 kind: "Job" 47 spec: { 48 parallelism: parameter.count 49 completions: parameter.count 50 template: { 51 metadata: { 52 labels: { 53 if parameter.labels != _|_ { 54 parameter.labels 55 } 56 "app.oam.dev/name": context.appName 57 "app.oam.dev/component": context.name 58 } 59 if parameter.annotations != _|_ { 60 annotations: parameter.annotations 61 } 62 } 63 spec: { 64 restartPolicy: parameter.restart 65 containers: [{ 66 name: context.name 67 image: parameter.image 68 69 if parameter["imagePullPolicy"] != _|_ { 70 imagePullPolicy: parameter.imagePullPolicy 71 } 72 73 if parameter["cmd"] != _|_ { 74 command: parameter.cmd 75 } 76 77 if parameter["env"] != _|_ { 78 env: parameter.env 79 } 80 81 if parameter["cpu"] != _|_ { 82 resources: { 83 limits: cpu: parameter.cpu 84 requests: cpu: parameter.cpu 85 } 86 } 87 88 if parameter["memory"] != _|_ { 89 resources: { 90 limits: memory: parameter.memory 91 requests: memory: parameter.memory 92 } 93 } 94 95 if parameter["volumes"] != _|_ { 96 volumeMounts: [ for v in parameter.volumes { 97 { 98 mountPath: v.mountPath 99 name: v.name 100 }}] 101 } 102 }] 103 104 if parameter["volumes"] != _|_ { 105 volumes: [ for v in parameter.volumes { 106 { 107 name: v.name 108 if v.type == "pvc" { 109 persistentVolumeClaim: claimName: v.claimName 110 } 111 if v.type == "configMap" { 112 configMap: { 113 defaultMode: v.defaultMode 114 name: v.cmName 115 if v.items != _|_ { 116 items: v.items 117 } 118 } 119 } 120 if v.type == "secret" { 121 secret: { 122 defaultMode: v.defaultMode 123 secretName: v.secretName 124 if v.items != _|_ { 125 items: v.items 126 } 127 } 128 } 129 if v.type == "emptyDir" { 130 emptyDir: medium: v.medium 131 } 132 }}] 133 } 134 135 if parameter["imagePullSecrets"] != _|_ { 136 imagePullSecrets: [ for v in parameter.imagePullSecrets { 137 name: v 138 }, 139 ] 140 } 141 142 } 143 } 144 } 145 } 146 147 parameter: { 148 // +usage=Specify the labels in the workload 149 labels?: [string]: string 150 151 // +usage=Specify the annotations in the workload 152 annotations?: [string]: string 153 154 // +usage=Specify number of tasks to run in parallel 155 // +short=c 156 count: *1 | int 157 158 // +usage=Which image would you like to use for your service 159 // +short=i 160 image: string 161 162 // +usage=Specify image pull policy for your service 163 imagePullPolicy?: "Always" | "Never" | "IfNotPresent" 164 165 // +usage=Specify image pull secrets for your service 166 imagePullSecrets?: [...string] 167 168 // +usage=Define the job restart policy, the value can only be Never or OnFailure. By default, it's Never. 169 restart: *"Never" | string 170 171 // +usage=Commands to run in the container 172 cmd?: [...string] 173 174 // +usage=Define arguments by using environment variables 175 env?: [...{ 176 // +usage=Environment variable name 177 name: string 178 // +usage=The value of the environment variable 179 value?: string 180 // +usage=Specifies a source the value of this var should come from 181 valueFrom?: { 182 // +usage=Selects a key of a secret in the pod's namespace 183 secretKeyRef?: { 184 // +usage=The name of the secret in the pod's namespace to select from 185 name: string 186 // +usage=The key of the secret to select from. Must be a valid secret key 187 key: string 188 } 189 // +usage=Selects a key of a config map in the pod's namespace 190 configMapKeyRef?: { 191 // +usage=The name of the config map in the pod's namespace to select from 192 name: string 193 // +usage=The key of the config map to select from. Must be a valid secret key 194 key: string 195 } 196 } 197 }] 198 199 // +usage=Number of CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core) 200 cpu?: string 201 202 // +usage=Specifies the attributes of the memory resource required for the container. 203 memory?: string 204 205 // +usage=Declare volumes and volumeMounts 206 volumes?: [...{ 207 name: string 208 mountPath: string 209 // +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir", default to emptyDir 210 type: *"emptyDir" | "pvc" | "configMap" | "secret" 211 if type == "pvc" { 212 claimName: string 213 } 214 if type == "configMap" { 215 defaultMode: *420 | int 216 cmName: string 217 items?: [...{ 218 key: string 219 path: string 220 mode: *511 | int 221 }] 222 } 223 if type == "secret" { 224 defaultMode: *420 | int 225 secretName: string 226 items?: [...{ 227 key: string 228 path: string 229 mode: *511 | int 230 }] 231 } 232 if type == "emptyDir" { 233 medium: *"" | "Memory" 234 } 235 }] 236 237 // +usage=Instructions for assessing whether the container is alive. 238 livenessProbe?: #HealthProbe 239 240 // +usage=Instructions for assessing whether the container is in a suitable state to serve traffic. 241 readinessProbe?: #HealthProbe 242 } 243 244 #HealthProbe: { 245 246 // +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. 247 exec?: { 248 // +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. 249 command: [...string] 250 } 251 252 // +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. 253 httpGet?: { 254 // +usage=The endpoint, relative to the port, to which the HTTP GET request should be directed. 255 path: string 256 // +usage=The TCP socket within the container to which the HTTP GET request should be directed. 257 port: int 258 httpHeaders?: [...{ 259 name: string 260 value: string 261 }] 262 } 263 264 // +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. 265 tcpSocket?: { 266 // +usage=The TCP socket within the container that should be probed to assess container health. 267 port: int 268 } 269 270 // +usage=Number of seconds after the container is started before the first probe is initiated. 271 initialDelaySeconds: *0 | int 272 273 // +usage=How often, in seconds, to execute the probe. 274 periodSeconds: *10 | int 275 276 // +usage=Number of seconds after which the probe times out. 277 timeoutSeconds: *1 | int 278 279 // +usage=Minimum consecutive successes for the probe to be considered successful after having failed. 280 successThreshold: *1 | int 281 282 // +usage=Number of consecutive failures required to determine the container is not alive (liveness probe) or not ready (readiness probe). 283 failureThreshold: *3 | int 284 } 285 }