-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
After my POC on dynamic review environments, I encountered unavoidable duplications in my ObjectTemplate:
---
apiVersion: templates.kluctl.io/v1alpha1
kind: ObjectTemplate
metadata:
name: stas-tenant-review
spec:
serviceAccountName: gitops-reconciler
prune: true
matrix:
- name: mr
object:
ref:
apiVersion: templates.kluctl.io/v1alpha1
kind: ListGitlabMergeRequests
name: stas-tenant
jsonPath: status.mergeRequests
expandLists: true
templates:
- object:
apiVersion: accurate.cybozu.com/v2
kind: SubNamespace
metadata:
name: "stas-rev-{{ matrix.mr.source_branch | slugify }}"
- object:
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: "stas-rev-{{ matrix.mr.source_branch | slugify }}"
spec:
interval: 1m0s
url: https://gitlab.statnett.no/stas/stas-tenant.git
ref:
branch: "{{ matrix.mr.source_branch }}"
- object:
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: "stas-rev-{{ matrix.mr.source_branch | slugify }}"
spec:
force: false
interval: 60m0s
path: ./review
prune: true
retryInterval: 2m0s
sourceRef:
kind: GitRepository
name: "stas-rev-{{ matrix.mr.source_branch | slugify }}"
targetNamespace: "stas-rev-{{ matrix.mr.source_branch | slugify }}"
timeout: 3m0s
wait: trueWhile this works, I had to repeat the Jinja expression for review namespace multiple times. I wonder if we could/should add a new feature to extract variables that the templates could use. With this example, it could be as simple as:
---
apiVersion: templates.kluctl.io/v1alpha1
kind: ObjectTemplate
metadata:
name: stas-tenant-review
spec:
serviceAccountName: gitops-reconciler
prune: true
matrix:
- name: mr
object:
ref:
apiVersion: templates.kluctl.io/v1alpha1
kind: ListGitlabMergeRequests
name: stas-tenant
jsonPath: status.mergeRequests
expandLists: true
vars:
branch: "{{ matrix.mr.source_branch }}"
namespace: "stas-rev-{{ matrix.mr.source_branch | slugify }}"
templates:This will make the templates easier to read, reduce the risk of minor errors/typos (Jinjia is hard), and allow for easier patching of OTs with e.g. Kustomize.
codablock
Metadata
Metadata
Assignees
Labels
No labels