-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |