1
+ apiVersion : core.oam.dev/v1alpha1
2
+ kind : Definition
3
+ metadata :
4
+ name : task
5
+ namespace : vela-system
6
+ spec :
7
+ type : trigger-action
8
+ templates :
9
+ # create a Job resource as an action in the same namespace as the source (by default)
10
+ main.cue : |
11
+ import (
12
+ "vela/kube"
13
+ )
14
+
15
+ apply: kube.#Apply & {
16
+ $params: {
17
+ resource: {
18
+ apiVersion: "batch/v1"
19
+ kind: "Job"
20
+ metadata: {
21
+ name: parameter.name
22
+ namespace: parameter.namespace
23
+ if context.data.metadata.labels != _|_ {
24
+ labels: context.data.metadata.labels
25
+ }
26
+ ownerReferences: [
27
+ {
28
+ apiVersion: context.data.apiVersion
29
+ kind: context.data.kind
30
+ name: context.data.metadata.name
31
+ uid: context.data.metadata.uid
32
+ controller: true
33
+ },
34
+ ]
35
+ }
36
+
37
+ spec: {
38
+ if parameter.ttlSecondsAfterFinished != _|_ {
39
+ ttlSecondsAfterFinished: parameter.ttlSecondsAfterFinished
40
+ }
41
+
42
+ template: {
43
+ spec: {
44
+ restartPolicy: parameter.restart
45
+ containers: [{
46
+ name: parameter.name
47
+ image: parameter.image
48
+ command: parameter.cmd
49
+
50
+ if parameter.env == _|_ {
51
+ env: [{
52
+ name: "SOURCE_NAME"
53
+ value: context.data.metadata.name
54
+ },{
55
+ name: "SOURCE_NAMESPACE"
56
+ value: context.data.metadata.namespace
57
+ }]
58
+ }
59
+
60
+ if parameter.env != _|_ {
61
+ env: [{
62
+ name: "SOURCE_NAME"
63
+ value: context.data.metadata.name
64
+ },{
65
+ name: "SOURCE_NAMESPACE"
66
+ value: context.data.metadata.namespace
67
+ }] + parameter.env
68
+ }
69
+ }]
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ parameter: {
78
+ // +usage=The image to run the job container on
79
+ image: string
80
+
81
+ // +usage=Name of the cron job
82
+ name: *context.data.metadata.name | string
83
+
84
+ // +usage=The namespace to create the Job in
85
+ namespace: *context.data.metadata.namespace | string
86
+
87
+ // +usage=Define the job restart policy, the value can only be Never or OnFailure. By default, it's Never.
88
+ restart: *"Never" | string
89
+
90
+ // +usage=Number of seconds to wait before a successfully completed job is cleaned up
91
+ ttlSecondsAfterFinished?: uint
92
+
93
+ // +usage=Commands to run in the container
94
+ cmd: [...string]
95
+
96
+ // +usage=Define evironment variables for the Job container
97
+ env?: [...{
98
+ // +usage=Name of the environment variable
99
+ name: string
100
+ // +usage=Value of the environment variable
101
+ value: string
102
+ }]
103
+ }
0 commit comments