design/20240206.helm-resource-policy.md
This checklist contains actions which must be completed before a PR implementing this design can be merged.
Using Helm to install CRDs is difficult. We cannot use the Helm crds/ folder to install CRDs because then CRDs are not upgraded when the Helm chart is upgraded. For that reason, we use the templates/ folder to install CRDs. However, this means that the CRDs are removed when the Helm chart is uninstalled. This is not ideal because it means that all custom resources are removed too.
There are two use cases we want to support:
Right now, we have different Helm chart CRD options for the different cert-manager projects, we want a standardised solution across most of these projects:
/
I would like to introduce the following options to all Helm charts that install CRDs (based on https://github.com/cert-manager/cert-manager/pull/5777):
crds:
# This option decides if the CRDs should be installed
# as part of the Helm installation.
enabled: true
# This option makes it so that the "helm.sh/resource-policy": keep
# annotation is added to the CRD. This will prevent Helm from uninstalling
# the CRD when the Helm release is uninstalled.
# WARNING: when the CRDs are removed, all cert-manager custom resources
# (Certificates, Issuers, ...) will be removed too by the garbage collector.
keep: true
NOTE 1: For backwards compatibility, the crds.enabled option would be false for the cert-manager chart.
NOTE 2: For the cert-manager chart, instead of introducing two new options, we could use the existing installCRDs option and add a new keepCRDs option.
Possible breaking change: This change will change the default uninstall behavior of the Helm chart. Before, the CRDs were removed when the Helm chart was uninstalled. Now, the CRDs will be kept by default. If the user wants to remove the CRDs too, they will have to manually delete them. This is a breaking change because it changes the default behavior of the Helm chart, but it will also make the lives of a lot of users much easier. I think the benefits outweigh the costs.
Info about the "helm.sh/resource-policy" annotation: Since we are using the templates/ folder to manage CRDs, which is required to allow templating and up-dating, the CRDs will be removed when we uninstall the chart. However, this annotation allows us to keep the resource even after the chart was uninstalled. We want to keep the CRDs to prevent accidental deletion of the custom resources.
The challenge with having only CRDs in a cluster, no webhooks:
After uninstalling the Helm chart, we are left with only the CRDs. The ValidatingWebhookConfiguration and the MutatingWebhookConfiguration are removed too. This means that the CRs will be freely editable, potentially causing inconsistencies. Also, the cmctl check api command will still return successfully, because it can create CRs without any issues. A potential fix for the second problem would be to check that the webhook performs the required mutations/ validations.
This change will introduce new required steps in the following scenarios:
kubectl delete <crd1> <crd2> …Install CRDs separately (e.g., using kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.1/cert-manager.crds.yaml or using a separate Helm chart) and manage them separately from the Helm chart.
This would require us to publish a separate Helm chart for the CRDs or a static manifest for the CRDs.