Skip to content

K8SPSMDB-1633 - protect CRDs from deletion via preserveCrds#901

Open
DrFaust92 wants to merge 5 commits into
percona:mainfrom
DrFaust92:K8SPSMDB-1633-protect-crds
Open

K8SPSMDB-1633 - protect CRDs from deletion via preserveCrds#901
DrFaust92 wants to merge 5 commits into
percona:mainfrom
DrFaust92:K8SPSMDB-1633-protect-crds

Conversation

@DrFaust92

@DrFaust92 DrFaust92 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves the psmdb part of #825 (K8SPSMDB-1633).

Adds an opt-in preserveCrds value to the psmdb-operator-crds chart. When enabled, the helm.sh/resource-policy: keep annotation is stamped onto all three CRDs, so a helm uninstall (or a GitOps tool like Flux/Argo CD accidentally pruning the release) leaves the CRDs — and every cluster stored under them — in place instead of deleting them.

Since these CRDs live in templates/ (so they can be upgraded), they are otherwise subject to deletion on uninstall — which, as the issue notes, can be devastating.

Changes

  • values.yaml: new preserveCrds: false (documented; disabled by default → no behavior change for existing users).
  • CRD templates: conditionally inject helm.sh/resource-policy: keep into metadata.annotations.
  • README.md: new "Protecting CRDs from Deletion" section + values table.
  • psmdb-operator-crd-sync-check.yaml: the content-sync check strips the templated annotation before diffing, so the CRD content is still validated against psmdb-operator/crds/crd.yaml.

Testing

  • helm template (default) → CRDs render identically to before (0 annotations).
  • helm template --set preserveCrds=true → all 3 CRDs get the annotation.
  • CRD content-sync diff → in sync ✓
  • helm lint → 0 failures.

Notes

Kept intentionally opt-in (false) to avoid changing uninstall behavior for existing users. Happy to default it to true if maintainers prefer safe-by-default. The sibling tickets (K8SPXC-1849 / K8SPS-677 / K8SPG-996) can follow the same pattern in separate PRs.


⚠️ Versioning note for maintainers

This is the first standalone change to the psmdb-operator-crds chart, which surfaced a conflict between two CI gates:

  • ct lint requires a chart version bump on any chart change.
  • psmdb-operator-crd-sync-check pinned the crds chart version to equal the operator appVersion.

Together these made a standalone crds-chart change impossible to land. I resolved it by:

  • Bumping psmdb-operator-crds chart version 1.22.0 → 1.22.1 (appVersion stays 1.22.0, pinned to the operator).
  • Relaxing the sync-check so the crds chart version only needs to share the operator appVersion's major.minor and may carry its own patch bump — mirroring how the operator chart version already floats above its appVersion. appVersion remains strictly pinned, and CRD content is still validated byte-for-byte by the existing content-sync diff.

Happy to adjust if you'd prefer a different versioning convention here.

Adds an opt-in `preserveCrds` value that stamps the
`helm.sh/resource-policy: keep` annotation onto the psmdb CRDs so they
(and every cluster stored under them) survive a `helm uninstall` of this
chart -- a safety net against a GitOps tool accidentally pruning it.

The CRD content-sync check strips the templated annotation before
diffing, so the CRD content is still validated against the operator's
crd.yaml.

Closes percona#825 (psmdb variant)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
DrFaust92 and others added 2 commits July 10, 2026 16:39
ct lint requires a chart version bump for the CRD-chart change, but the
crd-sync-check pinned the crds chart version to the operator appVersion.
Relax that rule so the crds chart version only needs to share the
operator appVersion's major.minor and may carry its own patch bump
(mirrors how the operator chart version floats above appVersion). The
crds appVersion stays pinned to the operator, and CRD content is still
validated independently by the content-sync diff.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread charts/psmdb-operator-crds/values.yaml Outdated
# `helm uninstall` of this chart. Set to true to guard against a GitOps tool
# (Flux, Argo CD, etc.) accidentally deleting the CRDs. See:
# https://helm.sh/docs/howto/charts_tips_and_tricks/#tell-helm-not-to-uninstall-a-resource
preserveCrds: false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if this should be true by default

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed -- I've flipped the default to true (89c5871).

The failure modes are asymmetric: with false, an accidental helm uninstall / GitOps prune cascades through the CRDs to every PerconaServerMongoDB and its data (irreversible). With true, the worst case is orphaned, cluster-scoped CRDs left after a teardown (recoverable with kubectl delete crd). Safe-by-default is also the ecosystem norm here (cert-manager, prometheus-operator both keep CRDs). And since helm.sh/resource-policy: keep only affects delete/uninstall -- not upgrade -- flipping the default doesn't touch the templated-CRD upgrade path these live in templates/ for.

One caveat worth flagging: it's a behavior change on uninstall, so ephemeral/CI flows that uninstall+reinstall expecting a clean cluster will now leave CRDs behind. I documented the opt-out (preserveCrds: false) in the README/values for that case.

I'll make the PXC/PS/PG siblings match once the pattern here is settled so all four charts stay consistent.

DrFaust92 and others added 2 commits July 23, 2026 09:21
Flip the preserveCrds default from false to true per maintainer review
(egegunes). The failure mode of leaving CRDs deletable is an accidental
`helm uninstall` / GitOps prune cascading through every cluster's data
(irreversible); the failure mode of keeping them is orphaned,
cluster-scoped CRDs after a teardown (recoverable with `kubectl delete
crd`). Given that asymmetry -- and that this matches the wider ecosystem
norm (cert-manager, prometheus-operator) -- safe-by-default is the better
default.

`helm.sh/resource-policy: keep` only affects delete/uninstall, not
upgrade, so this does not touch the templated-CRD upgrade path. README
and values docs updated to describe the new default and the opt-out
(`preserveCrds: false`) for ephemeral/CI clusters.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

operators a label used for the prs opened for the operators psmdb

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants