Skip to content

Commit ac10e57

Browse files
authored
Feature/image state update action (#49)
* addds triggerserive to monitor image updates example Signed-off-by: Amit Singh <[email protected]> * updates trigger action to optionally take pod env vars Signed-off-by: Amit Singh <[email protected]> * updates trigger action definition name Signed-off-by: Amit Singh <[email protected]> --------- Signed-off-by: Amit Singh <[email protected]>
1 parent ed3b9a6 commit ac10e57

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

config/definition/task.yaml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: standard.oam.dev/v1alpha1
2+
kind: TriggerService
3+
metadata:
4+
name: image-rebase-trigger
5+
namespace: default
6+
spec:
7+
triggers:
8+
- source:
9+
# source is all the kpack Image resources in all the namespaces
10+
type: resource-watcher
11+
properties:
12+
apiVersion: kpack.io/v1alpha2
13+
# kpack needs to be installed on the cluster to have this resource type
14+
kind: Image
15+
events:
16+
- update
17+
18+
# only trigger action when an Image is successfully rebased
19+
filter: >
20+
context.data.status.latestBuildReason == "STACK" && context.data.status.conditions[0].status == "True"
21+
22+
action:
23+
type: task
24+
properties:
25+
cmd: [/bin/sh, -c, "echo Image: ${SOURCE_NAME} in namespace: ${SOURCE_NAMESPACE} has been successfully rebased at $(date)"]
26+
image: busybox
27+
name: image-update-task
28+
ttlSecondsAfterFinished: 600

0 commit comments

Comments
 (0)