Skip to main content

GitOps Action

GitOps action allows you to make commits and push to a remote repository.

update-pod-namespace.yaml
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: update-pod-namespace
spec:
parameters:
- name: namespace
label: The new namespace
configs:
- type: Kubernetes::Pod
actions:
- name: Modify namespace
gitops:
repo:
url: https://github.com/example/repo
connection: connection://github/example
base: master
branch: playbooks-branch-{{.params.namespace}}
commit:
email: john@doe.com
author: John Doe
message: |
Modifying namespace from {{.config.namespace}} to {{.params.namespace}}
pr:
title: 'chore: Update namespace to {{.params.namespace}}'
tags:
- low
patches:
- path: navidrome.yaml
yq: '.metadata.namespace = "{{.params.namespace}}"'
files:
- path: { { .config.namespace } }
content: $delete
- path: '{{.params.namespace}}/namespace.yaml'
content: |
apiVersion: v1
kind: Namespace
metadata:
name: {{.params.namespace}}
info

On Github and Azure Devops, it's possible to create Pull Requests as well.

FieldDescriptionSchemeRequired
repoRepository detailsRepositoryDetailtrue
commitCommit detailsCommittrue
prPull Request details (Valid only for GitHub & Azure Devops)PullRequest
patchesList of patches to apply[]Patch
filesList of files to create[]File
note

At least a patch or files config is required.

Repository Detail

FieldDescriptionSchemeRequiredTemplated
connectionConnection name to use the credentials for the git repostring
urlURL of the git repositorystring
baseBranch to clone. (Defaults to "main")stringtrue
branchThe new branch to create. (Defaults to base branch specified above)stringtrue
note

Either the connection or the url is required

Commit Detail

FieldDescriptionSchemeRequiredTemplated
authorAuthor namestringtruetrue
emailAuthor emailstringtrue
messageCommit messagestringtrue

Pull Request

FieldDescriptionSchemeRequiredTemplated
titleTitle of the Pull requeststringtruetrue
tagsTags to add to the PR[]stringtrue

Patch

Patches modify existing files on the git repo. You can either use yq to modify yaml files or jq to modify json files.

FieldDescriptionSchemeRequiredTemplated
pathPath to patchstringtruetrue
yqyq querystringfalsetrue
jqjq querystringfalsetrue

File

Files create or delete existing files on the git repo.

FieldDescriptionSchemeRequiredTemplated
pathPath to filestringtruetrue
contentContent of the file. Use the $delete keyword to delete an existing filestringtruetrue

Templating

The following fields are templatable

  • commit.message
  • files.content
  • files.path
  • patches.jq
  • patches.path
  • patches.yq
  • pr.tags
  • pr.title
  • repo.base
  • repo.branch

The template receives a environment variable that contain details about the corresponding config, check or component and the parameter(if applicable).

info

See the reference to see what fields are templatable

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