Repository navigation
feat(helm): apply CRDs on helm upgrade via pre-upgrade Job - #385
Closed
WentingWu666666 wants to merge 1 commit into
Closed
WentingWu666666 wants to merge 1 commit into
WentingWu666666 wants to merge 1 commit into
Conversation
Helm 3 installs files from the chart's crds/ directory on first install but never touches them on subsequent `helm upgrade` calls. CRD schema bumps in a new chart release therefore silently fail to reach the cluster, causing 'unknown field' errors on CRs. Add a pre-install / pre-upgrade hook Job that renders the chart's CRDs into a ConfigMap and runs `kubectl apply --server-side --force-conflicts` against each one. The Job is gated by `crdUpgradeJob.enabled` (default true) so GitOps setups managing CRDs separately can opt out. CRD deletion on `helm uninstall` is intentionally NOT wired up: it would cascade-delete every DocumentDB / Backup / ScheduledBackup CR and silently destroy data. Refs documentdb#381 Co-authored-by: Copilot <[email protected]>
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningeffort from diff stats (185+0 LOC, 2 files); LLM: Adds a new Helm pre-upgrade hook Job and supporting RBAC resources to handle CRD schema upgrades that Helm 3 natively skips, touching chart templates and values config within one component. If a label is wrong, remove it manually and ping |
15 of 29 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a pre-install / pre-upgrade hook
Jobthat applies the chart's CRDs against the cluster, so chart upgrades that bump CRD schemas don't silently leave the old schema in place.Why
Helm 3 installs files from a chart's
crds/directory only on the firsthelm installand then refuses to touch them on subsequenthelm upgradecalls (see Helm docs: Limitations of CRDs). Today, bumping the chart with a schema change ships the new CRD incrds/but the live cluster keeps the old one users hit silentunknown fielderrors on CRs and assume the operator is broken.What
templates/00_crd_upgrade.yamlrenders, aspre-install+pre-upgradehooks (weight -15 / -10):ConfigMapcontaining all CRDs fromcrds/*.yamlvia.Files.GlobServiceAccount+ClusterRole+ClusterRoleBindingscoped to CRDget/list/create/patch/updateJobthat loops over the CRDs and runskubectl apply --server-side --force-conflictshelm.sh/hook-delete-policy: before-hook-creation,hook-succeededso they clean themselves up.crdUpgradeJob.{enabled,image,imagePullSecrets,backoffLimit,ttlSecondsAfterFinished}, defaultenabled: true.crds/directory so fresh installs still bootstrap CRDs the standard Helm way; the Job is then a no-op on first install and the upgrade fix on subsequent runs.Deliberately out of scope
DocumentDB/Backup/ScheduledBackupCR in the cluster a data-loss footgun. Users who want that behavior shouldkubectl delete crdexplicitly.Test
helm linthelm templaterenders 4 hook-annotated resourceshelm upgradeon local kind:kubectl get crd dbs.documentdb.io -o jsonpath='{.metadata.managedFields[*].manager}'reportshelm kubectl kube-apiserverthe newkubectlmanager confirms the Job patched the CRDhook-succeededdelete policyNotes for reviewers
alpine/k8s:1.30.5(multi-arch, has shell + kubectl). Override viacrdUpgradeJob.imageif you mirror images internally.Refs #381