Skip to content

Commit

Permalink
Feature/image state update action (#49)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
semmet95 authored Jun 21, 2023
1 parent ed3b9a6 commit ac10e57
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
103 changes: 103 additions & 0 deletions config/definition/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
apiVersion: core.oam.dev/v1alpha1
kind: Definition
metadata:
name: task
namespace: vela-system
spec:
type: trigger-action
templates:
# create a Job resource as an action in the same namespace as the source (by default)
main.cue: |
import (
"vela/kube"
)
apply: kube.#Apply & {
$params: {
resource: {
apiVersion: "batch/v1"
kind: "Job"
metadata: {
name: parameter.name
namespace: parameter.namespace
if context.data.metadata.labels != _|_ {
labels: context.data.metadata.labels
}
ownerReferences: [
{
apiVersion: context.data.apiVersion
kind: context.data.kind
name: context.data.metadata.name
uid: context.data.metadata.uid
controller: true
},
]
}
spec: {
if parameter.ttlSecondsAfterFinished != _|_ {
ttlSecondsAfterFinished: parameter.ttlSecondsAfterFinished
}
template: {
spec: {
restartPolicy: parameter.restart
containers: [{
name: parameter.name
image: parameter.image
command: parameter.cmd
if parameter.env == _|_ {
env: [{
name: "SOURCE_NAME"
value: context.data.metadata.name
},{
name: "SOURCE_NAMESPACE"
value: context.data.metadata.namespace
}]
}
if parameter.env != _|_ {
env: [{
name: "SOURCE_NAME"
value: context.data.metadata.name
},{
name: "SOURCE_NAMESPACE"
value: context.data.metadata.namespace
}] + parameter.env
}
}]
}
}
}
}
}
}
parameter: {
// +usage=The image to run the job container on
image: string
// +usage=Name of the cron job
name: *context.data.metadata.name | string
// +usage=The namespace to create the Job in
namespace: *context.data.metadata.namespace | string
// +usage=Define the job restart policy, the value can only be Never or OnFailure. By default, it's Never.
restart: *"Never" | string
// +usage=Number of seconds to wait before a successfully completed job is cleaned up
ttlSecondsAfterFinished?: uint
// +usage=Commands to run in the container
cmd: [...string]
// +usage=Define evironment variables for the Job container
env?: [...{
// +usage=Name of the environment variable
name: string
// +usage=Value of the environment variable
value: string
}]
}
28 changes: 28 additions & 0 deletions examples/triggerservice-image-update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: standard.oam.dev/v1alpha1
kind: TriggerService
metadata:
name: image-rebase-trigger
namespace: default
spec:
triggers:
- source:
# source is all the kpack Image resources in all the namespaces
type: resource-watcher
properties:
apiVersion: kpack.io/v1alpha2
# kpack needs to be installed on the cluster to have this resource type
kind: Image
events:
- update

# only trigger action when an Image is successfully rebased
filter: >
context.data.status.latestBuildReason == "STACK" && context.data.status.conditions[0].status == "True"
action:
type: task
properties:
cmd: [/bin/sh, -c, "echo Image: ${SOURCE_NAME} in namespace: ${SOURCE_NAMESPACE} has been successfully rebased at $(date)"]
image: busybox
name: image-update-task
ttlSecondsAfterFinished: 600

0 comments on commit ac10e57

Please sign in to comment.