|
| 1 | +--- |
| 2 | +hip: "9999" |
| 3 | +title: "Helm CRD updating" |
| 4 | +authors: [ "George Jenkins <[email protected]>" ] |
| 5 | +created: "2024-12-19" |
| 6 | +type: "feature" |
| 7 | +status: "draft" |
| 8 | +helm-version: "4" |
| 9 | +--- |
| 10 | + |
| 11 | +## Abstract |
| 12 | + |
| 13 | +<!-- |
| 14 | +A short (~200 word) description of the technical issue being addressed. |
| 15 | +--> |
| 16 | + |
| 17 | +Helm has historically taken a conservative approach to Custom Resource Definitions (CRDs). |
| 18 | +The concerns detailed in [HIP-0011](./hip-0011.md). |
| 19 | + |
| 20 | +This HIP aims to improve Helm's support for CRD management, while remaining in line with the rationales in `HIP-0011`. |
| 21 | +Ensuring chart consumers can continue to safely operate charts that provide CRDs. |
| 22 | +But extending Helm's CRD management to enable updates to CRDs. |
| 23 | + |
| 24 | + |
| 25 | +## Motivation |
| 26 | + |
| 27 | +<!-- |
| 28 | +Clearly explain why the existing design is inadequate to address the problem |
| 29 | +that the HIP solves. |
| 30 | +--> |
| 31 | + |
| 32 | +This HIP aims to improve the experience for chart authors and operators by extending Helm's ability to manage CRDs. |
| 33 | +Helm's conservative approach to date has limited the abilty for Helm's users (both authors and chart operators) to package and use Kubernetes applications that make use of CRDs. |
| 34 | +Today, Helm will only install CRDs (from the `crds/` directory) when installing a chart. |
| 35 | +CRDs are otherwise ignored for additional operations, including upgrades. |
| 36 | + |
| 37 | +CRDs have become more commonly utilized to extend Kubernetes functionality beyond its core primatives. |
| 38 | +Being conservative ensured Helm erred on the side of safety and didn't create an irreversible position for Helm nor its users. |
| 39 | +But has limited Helm's users, both chart operators and authors, to produce charts that expect to be able to manage CRDs. |
| 40 | +As such, improvements to Helm's CRD management, that allows Helm and charts to better manage and update CRDs are desired. |
| 41 | + |
| 42 | +The solution here aims to extend Helm's CRD management, while adhering to the concerns detailed in [HIP-0011](./hip-0011.md). |
| 43 | +While providing for better CRD management, but continuing to provide for safe operation of charts by chart operators. |
| 44 | + |
| 45 | + |
| 46 | +## Rationale |
| 47 | + |
| 48 | +<!-- |
| 49 | +Describe why particular design decisions were made. |
| 50 | +--> |
| 51 | +The two main reasons inferred from [HIP-0011](./hip-0011.md) that Helm is conservative with CRDs are: |
| 52 | +1. CRDs are a cluster-wide resource. |
| 53 | + Changes to cluster wide resources can (more easily) break applications beyond the scope of the chart |
| 54 | +2. Custom Resources (CRs) can be used as a data store. |
| 55 | + And removing the CRDs for those will remove the CR and may cause data loss |
| 56 | + |
| 57 | +For 1., it is thought that Helm should not treat CRDs specially here. |
| 58 | +Helm will readily operate on many other cluster wide resources today. |
| 59 | +Cluster roles, priority classes, namespaces, etc. |
| 60 | +That the modification/removal of could easily cause breakage outside of the chart's release. |
| 61 | + |
| 62 | +And in general, Helm should not try and protect uses against unintended functional changes from a chart. |
| 63 | +As validating functional changes is well beyond the scope of a package manager. |
| 64 | +Helm should treat CRDs the same as other (cluster-wide) resources, where a Helm chart upgrade that causes unintended functional effects should be reverted (rolled back). |
| 65 | +And as long as that rollback path exists, this is a suitable path for users to mitigate breaking functional changes. |
| 66 | + |
| 67 | +For the purposes of this HIP, it is though that Helm may modify CRDs, as long as the change is functionally reversable to the operator (via rollback). |
| 68 | + |
| 69 | +For 2., Data loss should be treated more carefully. |
| 70 | +As data loss can be irrevocable or require significant effort to restore. |
| 71 | +And especially, an application/chart operator should not expect a chart upgrade to cause data loss. |
| 72 | +Helm can prevent Data loss can be prevented by ensuring CRDs are "appended" only (with special exceptions in the specification below). An in particular, appending allows a rollback to (effectively) restore existing cluster state. |
| 73 | +(It should also be noted that Helm will today remove other resources which may cause data loss e.g. secrets, config maps, namespace, etc. A special, hard-coded, exception does exist for persistent volumes) |
| 74 | + |
| 75 | + |
| 76 | +## Specification |
| 77 | + |
| 78 | +<!-- |
| 79 | +Describe the syntax and semantics of any new feature. |
| 80 | +--> |
| 81 | + |
| 82 | +_Note: This specification applies to CRDs in a chart's `crds/` directory only. CRDs deployed via `templates/` are out of scope. As Helm only considered CRDs released via the `crds/` directory to be managed by Helm_ |
| 83 | + |
| 84 | +When installing for upgrading, Helm will install new CRDs from the `crds/` directory if they don't exist in the cluster. |
| 85 | +If the CRD already exists, Helm will "append" or merge CRD updates into the cluster's existing CRD object with the logic detailed below. |
| 86 | + |
| 87 | +When rolling back, Helm will simply revert merge in the previously installed version. Effectively, this is reverting to the prior "storage" version only. |
| 88 | + |
| 89 | +When uninstalling: Helm will leave CRDs as is |
| 90 | + |
| 91 | +The append/merge logic is as follows. When updsting an existing CRD resource, Helm will: |
| 92 | + |
| 93 | +- merge/update CRDs metadata (labels, annotations etc) |
| 94 | +- merge/update `/spec/names` |
| 95 | +- append new versions to the `/versions` list |
| 96 | +- update existing versions with the exception of the schema field |
| 97 | + - If in the future, functionality exists that shows a CRD version schema changes are backwards compatible, Helm may allow updating CRD version's schema field |
| 98 | + - In particular, Helm will expect the update from the chart to correctly set a single version to `storage: true` |
| 99 | +- merge/update `/conversion` field |
| 100 | +- set `/preserveUnknownFields` if the incoming or existing preserveUnknownFields values is set (logical OR) |
| 101 | + |
| 102 | +If in the future, Kubernetes introduces new fields to the CRD API, Helm will ignore these fields by default. |
| 103 | +Helm will consider introducing new logic to update any new new field that follows the rationale section as appropriate. |
| 104 | + |
| 105 | +If the `--skip-crds` flag is supplied on install/upgrade/rollback, similar to today, Helm will ignore CRD changes. |
| 106 | + |
| 107 | +## Backwards compatibility |
| 108 | + |
| 109 | +The adjustment in CRD management behavior will be visible to end users. |
| 110 | +Chart upgrades which previously ignored CRD changes will now action them. |
| 111 | +Which may cause user facing behaviour |
| 112 | + |
| 113 | +These behavioural changes are consider to acceptable for Helm 4. |
| 114 | + |
| 115 | +## Security implications |
| 116 | + |
| 117 | +None determined. |
| 118 | + |
| 119 | +## How to teach this |
| 120 | + |
| 121 | +Helm's CRD handling docs need to be updated: <https://helm.sh/docs/chart_best_practices/custom_resource_definitions/> |
| 122 | + |
| 123 | +In particular, the merge logic described will need to be documented/described. |
| 124 | + |
| 125 | +## Reference implementation |
| 126 | + |
| 127 | +<!-- |
| 128 | +Link to any existing implementation and details about its state, e.g. |
| 129 | +proof-of-concept. |
| 130 | +--> |
| 131 | + |
| 132 | +## Rejected ideas |
| 133 | + |
| 134 | +<!-- |
| 135 | +Why certain ideas that were brought while discussing this HIP were not |
| 136 | +ultimately pursued. |
| 137 | +--> |
| 138 | + |
| 139 | +### Deleting CRDs / versions |
| 140 | + |
| 141 | +In order to prevent data loss, this HIP just considered how to update CRDs. |
| 142 | +And did not consider how to remove CRD versions nor CRDs themselves. |
| 143 | + |
| 144 | +## Open issues |
| 145 | + |
| 146 | +<!-- |
| 147 | +Any points that are still being decided/discussed. |
| 148 | +--> |
| 149 | + |
| 150 | +## References |
| 151 | + |
| 152 | +<!-- |
| 153 | +A collection of URLs or materials used as references through the HIP. |
| 154 | +--> |
| 155 | + |
| 156 | +- [HIP-0011: CRD Handling in Helm 3](./hip-0011.md) |
| 157 | +- Kubernetes CRD docuemntation: |
| 158 | + - <https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/> |
| 159 | + - <https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/> |
| 160 | + - <https://kubernetes.io/docs/reference/kubernetes-api/extend-resources/custom-resource-definition-v1/> |
0 commit comments