In the previous post about Handle CRDs with GitOps I showed that CRDs for a helm chart can be generated using the helm cli and this enabled us to manage the full lifecycle of CRDs. In this post I will show automation around this, so that a helm chart version update triggers updates to the CRDs aswell.
Requirements
helm
yq
Creating recipies for CRD generation
Considering our previous example for a HelmRelease for cert-manager
now any updates made to helm.yaml will trigger a generation and overwrite of crds.yaml if make is run.
Creating a Github action
I have now showed that we can update CRDs manually if our helm chart version changes using make. Now the choice of choosing make makes our life a little bit difficult. In the root of our project I will create one Makefile to call make on all other Makefile's
base_dir:=apps# path to our collection of HelmReleasescharts_with_crds:=$(shellfind$(base_dir)-name'Makefile'-printf"%h\n")all:$(charts_with_crds)$(charts_with_crds):@$(MAKE)-C$@.PHONY:all$(charts_with_crds)
above Makefile is really complex and wasn't fun to write at all. Let's finish with the Github Action
So now when updates are made to our helm.yaml files updated crds.yaml are commited back by above workflow. The benefit is that changes to CRDs becomes really transparent.