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