Skip to content

Instantly share code, notes, and snippets.

@iMartyn
Last active May 5, 2020 10:01
Show Gist options
  • Save iMartyn/842b8cba758f0a554db87395f84cb9e6 to your computer and use it in GitHub Desktop.
Save iMartyn/842b8cba758f0a554db87395f84cb9e6 to your computer and use it in GitHub Desktop.
Create helm chart from cert-manager CRDs for pre-install

How to create a helm chart from the CRDs that jetstack provide

Requirements

  • curl
  • k8s-yaml-splitter (go get github.com/latchmihay/k8s-yaml-splitter)
  • gnu sed
  • yq (jq wrapper for yaml files - pip install yq)

Note

The attached script is for pre 1.15 k8s, if you're already on 1.15 remove the -legacy from the url.

Instructions

  1. Run helm create to create yourself a new chart
$ helm create cert-manager-pre
  1. Edit Chart.yaml to correctly describe the chart and match appversion to the version you want to install (script attached is for v0.14.3)
  2. Save update.sh into the same directory as Chart.yaml
  3. Delete the yaml files and test/ folder from templates/
  4. Empty the templates/NOTES.txt or make it say something nice and appropriate
  5. Run sh update.sh from the same directory as Chart.yaml

Instructions (update)

  • Edit Chart.yaml to update the appversion
  • Edit update.sh to point to the new version (check if you've upgraded to 1.15 k8s too, if so, remove -legacy)
  • Remove all the yaml files from the templates/ folder
  • Run the script again

Why isn't this provided by jetstack?

Very good question. Effort is pretty low, but I guess there's not that much call for it, most people only touch cert-manager to install it, or upgrade it. It'd be nice for jetstack to add something like the above to their CI. It'd be less involved for them as they probably have the source files.

#!/bin/sh
# requires curl, yq, k8s-yaml-splitter and gnu sed
pushd templates/
curl -L https://github.com/jetstack/cert-manager/releases/download/v0.14.3/cert-manager-legacy.crds.yaml > All-CRDs.yaml
k8s-yaml-splitter All-CRDs.yaml .
rm All-CRDs.yaml
for f in *.yaml; do
mv $f $f.orig
yq -y '.metadata.labels += {"xyzzy": "yzzxy"}' $f.orig > $f
sed -i s/'xyzzy: yzzxy'/'{{- include "certmanager-pre.labels" . | nindent 4 }}'/g $f
rm $f.orig
done
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment