Repository navigation
feat(chart): keep MongoDB data on uninstall - #427
Conversation
Add persistence.resourcePolicy (keep or empty, as in common charts) to the shared PVC helper: with keep, the claim is annotated with helm.sh/resource-policy: keep, so that Helm keeps it when the release is uninstalled or the claim is removed from it. It defaults to keep for MongoDB (also for values without it, as for 0.1.0) and to empty for the broker, whose queue can be rebuilt. A new release of the same name and namespace adopts the kept claim. Closes #425 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Install a release on kind, write a document to MongoDB, uninstall and reinstall the release, and check that the claim is the same, the document is still there and the app user works (helm test). Refs #425 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Helm checks the keep annotation of the live claim on upgrades, so a release of 0.1.0 is protected only after its first upgrade to 0.2.0: say so in the docs, values and schema, and in the migration notes, which also describe uninstalling and reinstalling. A release of another name gets a new claim instead of failing. Test the broker's resourcePolicy in the schema, and make the CI check of MongoDB's data take only mongosh's last line. Refs #425 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A release of another name with the same resource names (e.g., the same fullnameOverride) fails on the kept claim instead of getting a new one. Set pipefail in the CI check of MongoDB's data, so that failures of kubectl exec are reported as such. Refs #425 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR introduces a shared Sequence diagram for MongoDB data surviving Helm reinstallationsequenceDiagram
participant CI
participant Helm
participant Kubernetes
participant MongoDB
CI->>Helm: helm install petstore-keep
Helm->>Kubernetes: Create PVC with helm.sh/resource-policy: keep
Kubernetes-->>Helm: PVC ready
CI->>MongoDB: mongosh db.getSiblingDB(...).insertOne(...)
MongoDB-->>CI: Document stored
CI->>Helm: helm uninstall petstore-keep --wait
Helm->>Kubernetes: Delete release resources
Kubernetes-->>Helm: Kept MongoDB PVC remains
CI->>Helm: helm install petstore-keep
Helm->>Kubernetes: Adopt existing PVC
Kubernetes-->>Helm: Same PVC and data available
CI->>MongoDB: mongosh ...countDocuments(...)
MongoDB-->>CI: Document still present
CI->>Helm: helm test petstore-keep
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #427 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 2869 2869
=========================================
Hits 2869 2869
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docs/helm-chart.md" line_range="515-516" />
<code_context>
+ the claim of a release installed with foca-common 0.1.0 (or with an
+ empty `resourcePolicy`) is annotated only by the next upgrade: disable
+ persistence or switch to an `existingClaim` in a later upgrade, or
+ annotate the claim first (`kubectl annotate pvc my-app-mongodb
+ helm.sh/resource-policy=keep`). With an empty `resourcePolicy`, Helm
+ deletes the claim (and, with the usual reclaim policy `Delete`, the data)
+ with the release or when it is removed from it. The broker's claim is not
</code_context>
<issue_to_address>
**Legacy claims are deleted during upgrade**
When a release installed before this change annotates its live PVC and removes that PVC from the chart in the same upgrade, `helm upgrade` evaluates the old release manifest, which lacks the keep annotation, when deleting the PVC; annotating only the live claim does not protect it, so the claim and, with the usual `Delete` reclaim policy, its data are removed.
Require a separate upgrade that records the keep annotation in the release manifest before removing the PVC, and remove the manual-annotation alternative unless it is verified to protect this upgrade path.
Also at `docs/migration-0.17.md:167-168`.
</issue_to_address>
### Comment 2
<location path="charts/foca-common/templates/_helpers.tpl" line_range="424" />
<code_context>
{{- include "foca-common.labels" (dict "root" .root "component" .component) | nindent 4 }}
+ {{- if eq (toString $resourcePolicy) "keep" }}
+ annotations:
+ helm.sh/resource-policy: keep
+ {{- end }}
spec:
</code_context>
<issue_to_address>
**Rollback removes the keep annotation**
When an operator rolls back to a release revision rendered before this annotation and later uninstalls the release, the rollback restores a manifest without the annotation and removes it from the live PVC, so a later uninstall deletes the claim and, with the usual `Delete` reclaim policy, its data.
Document that operators must reapply the keep annotation after such a rollback and before uninstalling.
</issue_to_address>
### Comment 3
<location path="docs/helm-chart.md" line_range="517" />
<code_context>
+ persistence or switch to an `existingClaim` in a later upgrade, or
+ annotate the claim first (`kubectl annotate pvc my-app-mongodb
+ helm.sh/resource-policy=keep`). With an empty `resourcePolicy`, Helm
+ deletes the claim (and, with the usual reclaim policy `Delete`, the data)
+ with the release or when it is removed from it. The broker's claim is not
+ kept by default, as its queue can be rebuilt
</code_context>
<issue_to_address>
**Kept claims survive removal**
When an upgrade removes persistence or switches to an existing claim while changing `resourcePolicy` from `keep` to empty, helm uses the previous release manifest’s keep annotation when removing the PVC, so it retains the claim despite the empty setting and the operator’s attempt to delete its data leaves the PVC behind.
Document that operators must remove the keep annotation in a separate upgrade before removing persistence or switching to an existing claim.
Also at `examples/petstore/chart/values.yaml:206`, `charts/foca-common/templates/_helpers.tpl:415`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and MongoDB claims get helm.sh/resource-policy: keep by default, so uninstalling a release can leave its database data behind instead of deleting it. This changes the default data-retention policy for every affected release, and reverting the chart will not remove claims already kept.
Blocking findings: docs/helm-chart.md:516, charts/foca-common/templates/_helpers.tpl:424, docs/helm-chart.md:517
A rollback to a revision without the keep annotation removes it from MongoDB's claim, and emptying resourcePolicy only takes effect on the claim's removal in a later upgrade. Refs #425 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Closes #425.
helm uninstallno longer deletes the bundled MongoDB's database volume (maintainer decision on a finding declined in #422):foca-common.persistentVolumeClaimgetspersistence.resourcePolicy, named as in Bitnami's charts:keepannotates the claim withhelm.sh/resource-policy: keep, and empty leaves the annotation off. It is in the shared schema definition, so bothmongodb.persistenceandbroker.persistencehave it.keepfor MongoDB, empty for the broker, whose queue can be rebuilt. Operators turn it off withmongodb.persistence.resourcePolicy: "".existingClaim). Upgrades check the live claim, so releases from 0.1.0 are protected only after their first upgrade to 0.2.0. The docs and the migration notes say so.fullnameOverride) fails on the kept claim, unless it sets it as itsexistingClaim.CI
petstore-keepwithci/test-values.yamland writes a document with mongosh. It then uninstalls the release (--wait) and checks that the claim (UID) is kept. After a reinstall, it checks that the claim is the same and that the document is still there, and runshelm test(the app user is still there, as the init script does not run again).ct installruns with--skip-clean-up, so it never uninstalls, and the kind cluster is discarded with the runner, so kept claims leave nothing behind.Verification
pytest charts/foca-common/tests(Helm 3.22.1): 196 passed. Snapshots updated: only the MongoDB claim's annotation.helm lint --stricton the library chart, and on the petstore chart with everyci/*-values.yaml: pass.ruff check,ruff format --check,mypyandmkdocs build --strict: pass.Declined review findings
A generic
persistence.annotationsinstead ofresourcePolicy:resourcePolicyis the common-chart convention for exactly this. Arbitrary annotations can be added later if needed.Sourcery, "Legacy claims are deleted during upgrade": on upgrade, Helm checks the live claim's annotation (it refreshes each removed resource with
info.Get()before checking it), not the old manifest. Annotating the claim by hand before the upgrade therefore protects it. The rollback and empty-resourcePolicycases Sourcery raised are now documented.Open questions
None.
🤖 Generated with Claude Code