Skip to content

Commit

Permalink
docs(playbook): template vars
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jun 26, 2024
1 parent db906b4 commit 6cd1100
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 40 deletions.
79 changes: 40 additions & 39 deletions mission-control/docs/reference/playbooks/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
title: Context
---


### CEL Expressions

The following variables can be used within the [CEL](/reference/scripting/cel) expressions of `filter`, `if`, `delays` and `parameters.default`:
The following variables can be used within the [CEL](/reference/scripting/cel) expressions of `filter`, `if`, `delays` and `parameters.default`:

| Field | Description | Schema |
| ----------- | ---------------------------------------- | -------------------------------------------- |
| `config` | Config passed to the playbook | [`ConfigItem`](/reference/config-db) |
| `component` | Component passed to the playbook | [`Component`](/reference/topology/components) |
| `check` | Canary Check passed to the playbook | [`Check`](/reference/canary-checker/check) |
| `params` | User provided parameters to the playbook | `map[string]string` |
| `env` | Environment variables defined on the playbook | `map[string]string` |
| `user.name` | Name of the user who invoked the action | `string` |
| `user.email` | Email of the user who invoked the action | `string` |
| Field | Description | Schema |
| ------------ | --------------------------------------------- | -------------------------------------------------- |
| `config` | Config passed to the playbook | [`ConfigItem`](/reference/config-db) |
| `component` | Component passed to the playbook | [`Component`](/reference/topology/components) |
| `check` | Canary Check passed to the playbook | [`Check`](/reference/canary-checker/check) |
| `playbook` | Playbook passed to the playbook | [`Playbook`](/reference/playbooks) |
| `run` | Current run | [`Run`](/reference/playbooks/#run) |
| `params` | User provided parameters to the playbook | `map[string]any` |
| `request` | Webhook request | [`Webhook Request`](/reference/playbooks/webhooks) |
| `env` | Environment variables defined on the playbook | `map[string]any` |
| `user.name` | Name of the user who invoked the action | `string` |
| `user.email` | Email of the user who invoked the action | `string` |
| `agent.id` | ID of the agent the resource belongs to. | `string` |
| `agent.name` | Name of the agent the resource belongs to. | `string` |

<details summary="Conditionally Running Actions">
<div>
Expand All @@ -31,51 +35,48 @@ Playbook actions can be selectively executed based on CEL expressions. These exp
| `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 |

```yaml title="delete-kubernetes-pod.yaml" file=../../../modules/mission-control/fixtures/playbooks/exec-filter.yaml

```

</div>
</details>

<details summary="Defaulting Parameters">
<div>
```yaml title="delete-kubernetes-pod.yaml"
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: edit
spec:
title: 'Edit Kustomize Resource'
icon: flux
parameters:
//highligh-next-line
- default: 'chore: update $(.config.type)/$(.config.name)'
name: commit_message
```
</div>
<div>
```yaml title="delete-kubernetes-pod.yaml" apiVersion:
mission-control.flanksource.com/v1 kind: Playbook metadata: name: edit spec:
title: 'Edit Kustomize Resource' icon: flux parameters: //highligh-next-line
- default: 'chore: update $(.config.type)/$(.config.name)' name:
commit_message ```
</div>
</details>

### Go Templating

When templating `actions` with [Go Templates](/reference/scripting/gotemplate), the context variables are available as fields of the template's context object `.` eg `.config`, `.user.email`

<details summary="Templating Actions">
<div>
```yaml title="delete-kubernetes-pod.yaml" file=../../../modules/mission-control/fixtures/playbooks/scale-deployment.yaml {16}
```
</div>
<div>
```yaml title="delete-kubernetes-pod.yaml"
file=../../../modules/mission-control/fixtures/playbooks/scale-deployment.yaml{' '}
{16}
```
</div>
</details>

### Functions

| Function | Description | Return |
| ----------- | ---------------------------------------- | -------------------------------------------- |
|`getLastAction()` | Returns the result of the action that just run | Action Specific |
|`getAction({action})` | Return the result of a specific action |Action Specific |

| Function | Description | Return |
| --------------------- | ---------------------------------------------- | --------------- |
| `getLastAction()` | Returns the result of the action that just run | Action Specific |
| `getAction({action})` | Return the result of a specific action | Action Specific |

<details summary="Reusing Action Results">
<div>
```yaml title="action-results.yaml" file=../../../modules/mission-control/fixtures/playbooks/action-result.yaml
```
</div>
<div>
```yaml title="action-results.yaml"
file=../../../modules/mission-control/fixtures/playbooks/action-result.yaml
```
</div>
</details>
49 changes: 48 additions & 1 deletion mission-control/docs/reference/playbooks/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Playbooks
title: Playbook
sidebar_position: 6
---

Expand All @@ -22,6 +22,53 @@ sidebar_position: 6
| `approval` | Optional approvals required before a playbooks runs | [`Approval`](#approvals) |


## Run

<Fields
rows={[
{
field: 'id',
description: 'ID of the playbook run',
scheme: 'string',
},
{
field: 'playbook_id',
description: 'ID of the playbook',
scheme: 'string',
},
{
field: 'status',
description: 'Status of the playbook run',
scheme: 'string',
},
{
field: 'created_by',
description: 'ID of the user who created the playbook run',
scheme: 'string',
},
{
field: 'component_id',
description: 'ID of the component associated with the playbook run',
scheme: 'string',
},
{
field: 'check_id',
description: 'ID of the check associated with the playbook run',
scheme: 'string',
},
{
field: 'config_id',
description: 'ID of the config associated with the playbook run',
scheme: 'string',
},
{
field: 'agent_id',
description: 'ID of the agent that executed the playbook run',
scheme: 'string',
},
]}
/>

## Actions

| Field | Description | Scheme | Required |
Expand Down

0 comments on commit 6cd1100

Please sign in to comment.