Skip to main content
Version: 1.0

Trigger

Trigger is the template of ResourceTemplate. When a Trigger is executed, Pullup webhook will create, update or delete ResourceTemplate according to Trigger and the input event.

Model#

spec.resourceName#

Required

The template of name of ResourceTemplate. The value must be a valid Go template string.

Available variables:

KeyTypeDescription
triggerTriggerCurrent Trigger resource.
eventunknownInput event.

Example:

"{{ .trigger.metadata.name }}-{{ .event.suffix }}"
// my-trigger-foo

spec.patches#

Required

The template of resources to create in your Kubernetes cluster. The value is an array of objects which contains the following fields.

KeyTypeDescription
apiVersion RequiredstringAPI version of resources to create. (e.g. v1, apps/v1)
kind RequiredstringKind of resources to create. (e.g. Pod, Deployment, Service)
sourceNamestringThe name of resources to copy when creating new resources. If this value is not specified, resources will be created directly.
targetNamestringThe template of name of created resources. By default, the value will be the same as the name of ResourceTemplate. If the spec.patches array contains multiple resources with the same apiVersion and kind, you must configure this field to avoid conflicts.
mergeobjectMutate created resources with Strategic Merge Patch.
jsonPatcharrayMutate created resources with JSON Patch.

You can use Go template string in all of the fields above. The following are the available variables.

KeyTypeDescription
triggerTriggerCurrent Trigger resource.
eventunknownInput event.
resourceResourceTemplateCurrent ResourceTemplate resource.

See the Examples section below for examples.

spec.schema#

The JSON schema for input events. Pullup uses draft 7 version currently. You can learn more about JSON schema in the official book.

Examples#

Create Resources from Scratch#

This is the most basic usage of the Trigger resource.

apiVersion: pullup.dev/v1beta1
kind: Trigger
metadata:
name: example
spec:
resourceName: "{{ .trigger.metadata.name }}"
patches:
- apiVersion: v1
kind: ConfigMap
merge:
data:
timezone: UTC

When the trigger above is executed, a ConfigMap will be created as below.

apiVersion: v1
kind: ConfigMap
metadata:
name: example
data:
timezone: UTC

Copy and Mutate Resources#

When the sourceName is specified in spec.patches. Pullup controller will copy existing resources and rename it as targetName or spec.resourceName. If merge or jsonPatch is specified, the copied resources will be mutated.

apiVersion: pullup.dev/v1beta1
kind: Trigger
metadata:
name: example
spec:
resourceName: "{{ .trigger.metadata.name }}-{{ .event.suffix }}"
patches:
- apiVersion: apps/v1
kind: Deployment
sourceName: kuard
merge:
spec:
selector:
matchLabels:
app: "{{ .resource.metadata.name }}"
template:
metadata:
labels:
app: "{{ .resource.metadata.name }}"
spec:
containers:
- name: kuard
image: "gcr.io/kuar-demo/kuard-amd64:{{ .event.version }}"

When the trigger above is executed, a Deployment will be created as below.

apiVersion: apps/v1
kind: Deployment
metadata:
name: example
spec:
replicas: 1
selector:
matchLabels:
app: example
template:
metadata:
labels:
app: example
spec:
containers:
- name: kuard
image: gcr.io/kuar-demo/kuard-amd64:green

Validate Input Data#

apiVersion: pullup.dev/v1beta1
kind: Trigger
metadata:
name: example
spec:
resourceName: "{{ .trigger.metadata.name }}"
patches:
- apiVersion: v1
kind: ConfigMap
merge:
data:
timezone: UTC
schema:
type: object
properties:
suffix:
type: string
version:
type: string

Customize Resource Name#

By default, the name of created resources will be the same as the name of ResourceTemplate, which is fine usually. However, if spec.patches contains multiple resources with the same apiVersion and kind, you must specify targetName for these resources to avoid conflicts.

apiVersion: pullup.dev/v1beta1
kind: Trigger
metadata:
name: example
spec:
resourceName: "{{ .trigger.metadata.name }}"
patches:
- apiVersion: v1
kind: ConfigMap
targetName: "{{ .resource.metadata.name }}-utc"
merge:
data:
timezone: UTC
- apiVersion: v1
kind: ConfigMap
targetName: "{{ .resource.metadata.name }}-tpe"
merge:
data:
timezone: Asia/Taipei