Skip to main content

Expressions

Playbook event filters use Common Expression Language (CEL).

The Common Expression Language (CEL) is a non-Turing complete language designed for simplicity, speed, safety, and portability. CEL's C-like syntax looks nearly identical to equivalent expressions in C++, Go, Java, and TypeScript.

Examples:

notify-with-filter.yaml
---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: notify-with-filter
spec:
on:
config:
- event: created
configs:
- type: Kubernetes::Pod
actions:
- name: Send notification
exec:
script: notify-send "{{.config.name}} was created"
- name: Bad script to create a failing action
exec:
script: non-existing-command
- name: Send all success notification
if: success() # this filter practically skips this action as the second action above always fails
exec:
script: notify-send "Everything went successfully"
- name: Send notification regardless
if: always()
exec:
script: notify-send "a config was created"

Conditionally running actions

Playbook actions can be selectively executed based on CEL expressions. These expressions must either return

  • a boolean value (true indicating run the action & skip the action otherwise)
  • or a special function among the ones listed below
FunctionDescription
always()run no matter what; even if the playbook is cancelled/fails
failure()run if any of the previous actions failed
skip()skip running this action
success()run only if all previous actions succeeded (default)
timeout()run only if any of the previous actions timed out

Examples

  • if: config.deleted_at ? true: false
  • if: always()

Context

Expressions have access to the following variables and functions

FieldDescriptionSchema
.configConfig passed to the playbookConfigItem
.componentComponent passed to the playbookComponent
.checkCanary Check passed to the playbookCheck
.paramsUser provided parameters to the playbookmap[string]string
.user.nameName of the user who invoked the actionstring
.user.emailEmail of the user who invoked the actionstring