PR automation custom resources
Define your own Pull Request Automations with Kubernetes CRDs
You can use our CRD toolkit to easily generate new PR Automation flows. This can be as simple as generating pull requests to upgrade to a new Kubernetes version in Terraform, or it can involve more complex workflows. In this guide, we'll show how you can use it to provide self-service developer workspaces, a common use case for many enterprises.
Defining Templates
Most of the PR automation works off of Shopify's Liquid templating engine. It's a well-documented, widely used templating library that is frankly a bit nicer than Go's built-in text/template library. Plural provides a set of custom filters that can be used in your templates. For more information, see Liquid Filters in PR Automation.
For this example, a few templates are worth mentioning.
In templates/service.yaml.liquid:
apiVersion: deployments.plural.sh/v1alpha1
kind: ServiceDeployment
metadata:
name: {{ context.name }}
namespace: infra
spec:
namespace: {{ context.name }}
git:
folder: workspaces
ref: main
repositoryRef:
kind: GitRepository
name: infra
namespace: infra
configurationRef:
name: plural-pull-creds
namespace: infra
helm:
version: "0.x.x"
chart: workloads
valuesFiles:
- {{ context.name }}.yaml
repository:
namespace: infra
name: workloads
clusterRef:
kind: Cluster
name: mgmt
namespace: infraand workspace.yaml.liquid:
cluster: {{ context.cluster }}
gitRepository: {{ context.repo }}
access:
write:
- groupName: {{ context.group }}
workloads: {{ context.workloads }}The first generates a ServiceDeployment CRD (if you aren't familiar with this, see the docs for the Plural operator) that will ultimately create the workspace service. The second defines the Helm values file for that service. The variables in context are user-specified, and it also takes a list of workloads that will be the individual components spawned by that service -- the workspace is in fact an app-of-apps.