Repository navigation
feat(chart): add persistence settings for MongoDB - #422
Conversation
Move the broker's PersistentVolumeClaim and claim name into the generic helpers foca-common.persistentVolumeClaim and foca-common.claimName, so that MongoDB can use them, too. The rendered broker resources are unchanged (snapshot tests). Refs #419 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add mongodb.persistence with the keys of broker.persistence (enabled, size, accessModes, storageClass, existingClaim), rendered by the shared PVC helper. Persistence stays on by default, also without the map (as in values written for foca-common 0.1.0); without it, the data is kept in an emptyDir limited to the size. The claim keeps its name. mongodb.volumeSize is a deprecated alias of mongodb.persistence.size; rendering fails if both are set, so that neither is ignored silently. Both schemas share a persistence definition; the petstore example switches to the new values. Closes #419 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #419 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Name the fix in the error for a deprecated mongodb.volumeSize set with mongodb.persistence.size, and document it, the emptyDir without a size, and that disabling persistence or switching to an existing claim deletes the chart's claim on upgrade, unless it is annotated with helm.sh/resource-policy: keep first. Split the alias tests and cover the emptyDir with the alias and without a size. An integer mongodb.volumeSize (bytes) is now rendered as an integer (e.g., 1073741824 instead of 1.073741824e+09), the same quantity. Refs #419 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideAdds MongoDB persistence settings matching the broker’s configuration model, while preserving the default claim and name for existing releases. The implementation introduces shared Helm helpers, supports existing claims and an emptyDir fallback, migrates the deprecated volumeSize setting with explicit conflict errors, and updates schemas, examples, documentation, and tests. Sequence diagram for MongoDB persistence settings renderingsequenceDiagram
participant Helm
participant MongoDBTemplate
participant PersistenceHelper
participant Kubernetes
Helm->>MongoDBTemplate: mongodbDeployment
MongoDBTemplate->>PersistenceHelper: mongodbPersistence
PersistenceHelper->>PersistenceHelper: claimName
alt persistence enabled
MongoDBTemplate->>PersistenceHelper: persistentVolumeClaim
PersistenceHelper-->>Kubernetes: PersistentVolumeClaim and Deployment volume
else persistence disabled
MongoDBTemplate->>PersistenceHelper: emptyDir
PersistenceHelper-->>Kubernetes: Deployment volume using emptyDir
end
Flow diagram for MongoDB persistence volume selectionflowchart TD
A[MongoDB deployment renders persistence settings] --> B{mongodb.persistence.enabled}
B -->|unset| C[Persistence enabled by default]
B -->|true| C
B -->|false| D[Mount emptyDir]
D --> E[Apply persistence.size as size limit if set]
C --> F{existingClaim set}
F -->|yes| G[Mount existingClaim]
F -->|no| H[Render PersistentVolumeClaim]
H --> I[Claim name app-mongodb]
H --> J[Use persistence.size accessModes and storageClass]
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 #422 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 2777 2777
=========================================
Hits 2777 2777
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 4 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="472-473" />
<code_context>
+ to an `existingClaim` for an existing release deletes the chart's claim
+ (and, with the usual reclaim policy `Delete`, its data) on upgrade. To
+ keep the claim, e.g., to manage it outside the release under its name,
+ annotate it first (`kubectl annotate pvc my-app-mongodb
+ helm.sh/resource-policy=keep`), then set it as `existingClaim`.
+
+ `mongodb.volumeSize`, the setting up to foca-common 0.1.0, is
</code_context>
<issue_to_address>
**PVC preservation instruction still deletes data**
When an operator follows the documented annotation step and then upgrades an existing release to use `mongodb.persistence.existingClaim`, the operator adds `helm.sh/resource-policy: keep` only to the live PVC, while Helm determines upgrade deletions from the prior release manifest. `mongodbPersistentVolumeClaim` omits the PVC after `existingClaim` is set, so Helm deletes the claim and, with the usual `Delete` reclaim policy, its data.
Ensure the keep annotation is present in a release manifest before removing the PVC, or provide a chart mechanism to add it and document the required preparatory upgrade.
</issue_to_address>
### Comment 2
<location path="charts/foca-common/templates/_mongodb.tpl" line_range="279" />
<code_context>
+{{- if and (not (kindIs "invalid" $size)) (ne (toString $size) "") -}}
+{{- fail "mongodb.persistence.size and the deprecated mongodb.volumeSize are both set: set only mongodb.persistence.size (rename volumeSize in your values; if the app chart's values set volumeSize, unset it with null, e.g., --set-json mongodb.volumeSize=null)" -}}
+{{- end -}}
+{{- $size = ternary $volumeSize (int64 $volumeSize | toString) (kindIs "string" $volumeSize) -}}
+{{- end -}}
+{{- dict "persistence" $persistence "name" (include "foca-common.mongodbFullname" .) "enabledByDefault" true "size" $size "key" "mongodb.persistence" | toJson -}}
</code_context>
<issue_to_address>
**Invalid legacy sizes reach Kubernetes**
When `mongodb.volumeSize` is malformed or nonpositive, `mongodbPersistence` assigns the value to `$size` without validating it, so `persistentVolumeClaim` emits an invalid PVC request or `emptyDir` size limit and Kubernetes rejects the release.
Validate the legacy value’s quantity and positivity before assigning it to `$size`.
</issue_to_address>
### Comment 3
<location path="charts/foca-common/templates/_mongodb.tpl" line_range="277" />
<code_context>
+{{- $volumeSize := get $mongodb "volumeSize" -}}
+{{- if and (not (kindIs "invalid" $volumeSize)) (ne (toString $volumeSize) "") -}}
+{{- if and (not (kindIs "invalid" $size)) (ne (toString $size) "") -}}
+{{- fail "mongodb.persistence.size and the deprecated mongodb.volumeSize are both set: set only mongodb.persistence.size (rename volumeSize in your values; if the app chart's values set volumeSize, unset it with null, e.g., --set-json mongodb.volumeSize=null)" -}}
+{{- end -}}
+{{- $size = ternary $volumeSize (int64 $volumeSize | toString) (kindIs "string" $volumeSize) -}}
</code_context>
<issue_to_address>
**Suggested unset command fails validation**
When an upgrade retains `mongodb.volumeSize` and the caller follows the suggested `--set-json mongodb.volumeSize=null` command, the app-values schema permits only strings and integers for `mongodb.volumeSize`, so Helm rejects `null` before `mongodbPersistence` can clear the legacy value and the documented upgrade command cannot render.
Allow `null` for the deprecated key in the app-values schema so the suggested command can clear it.
Also at `docs/helm-chart.md:481`.
</issue_to_address>
### Comment 4
<location path="charts/foca-common/tests/test_templates.py" line_range="855" />
<code_context>
+ "existingClaim": {
+ "type": "string",
+ "description": "Existing PersistentVolumeClaim to use instead of the component's own"
+ }
+ },
+ "description": "Volume with a component's data: a PersistentVolumeClaim if enabled, otherwise an emptyDir"
</code_context>
<issue_to_address>
**Integer rendering regression passes**
When an integer `mongodb.volumeSize` is rendered as an exactly equivalent floating-point quantity, in `test_mongodb_volume_size_alias`, the dictionary equality compares the parsed storage value with an integer, but Python considers an exactly representable float equal to that integer. A regression rendering the byte quantity in scientific notation therefore passes without verifying the intended integer output.
Assert that the parsed storage value has integer type, or assert the rendered YAML scalar preserves integer formatting.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and setting persistence to false or switching to an existing claim stops rendering the release-managed PVC, so an upgrade can delete it and its MongoDB data under the usual reclaim policy. Reverting the setting cannot recover data already deleted.
Blocking findings: docs/helm-chart.md:473, charts/foca-common/templates/_mongodb.tpl:279, charts/foca-common/templates/_mongodb.tpl:277, charts/foca-common/tests/test_templates.py:855
Validate mongodb.volumeSize like the other sizes (a positive quantity or number of bytes, or null to unset it), and check that numbers of bytes are rendered as integers. Refs #419 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cover mongodb.persistence of foca-common 0.2.0 (#422): replacing volumeSize in app charts and deployments, and keeping the claim when switching to an existing claim (#417). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Closes #419.
The bundled MongoDB of
foca-commongets the persistence settings of the bundled broker (#411):mongodb.persistencewith the keys ofbroker.persistence:enabled,size,accessModes(ReadWriteOnceif not set),storageClass(the cluster's default if empty,-for no dynamic provisioning) andexistingClaim.mongodb.persistence.enabledor the whole map (values written for 0.1.0), as MongoDB always had its claim. Withenabled: false, the data is kept in anemptyDirlimited tosize, if set (e.g., for tests).mongodb.volumeSizeis a deprecated alias ofmongodb.persistence.size. Rendering fails if both are set, with a message naming the fix (move the size topersistence.size; unset avolumeSizeof the app chart's values with--set-json mongodb.volumeSize=null), so that neither value is silently ignored. A silently ignored override would also shrink the claim, which Kubernetes rejects.<app name>-mongodb), so upgrades keep the data. An integervolumeSize(bytes) is now rendered as an integer (1073741824instead of1.073741824e+09), the same quantity.foca-common.persistentVolumeClaim, withfoca-common.claimName); the broker's templates call it, with unchanged output. Both schemas share apersistencedefinition.existingClaimdeletes the chart's claim on upgrade unless it is annotated withhelm.sh/resource-policy: keepfirst.Verification
pytest charts/foca-common/tests(Helm 3.22.1): 193 passed. The snapshots are unchanged, so the rendered broker and MongoDB resources of every snapshot case are identical.helm lint --strict charts/foca-common, and of the petstore chart with everyci/*-values.yaml: pass.ruff check,ruff format --check,mypyandmkdocs build --strict: pass.chart-v0.1.0(withvolumeSizeand withoutmongodb.persistence) with the library ofchart-v0.1.0and with the library of this branch. I used the default values and each of itsci/*-values.yaml. MongoDB's resources are identical in every case; the only differences are the broker's StatefulSet from feat(chart): persist the bundled broker #411.Declined review findings
volumeSizewin over (or lose to)persistence.sizeinstead of failing (both reviewers): either order silently ignores one value in a plausible upgrade, an old override against new app chart defaults or an old app chart default against a new override. Failing names the fix, and the docs describe it.existingClaimis the chart's own claim name (round 1). I added the check, then dropped it after round 2: it blocks the standard way to detach the claim from the release (annotate it withhelm.sh/resource-policy: keep, then set it asexistingClaim). The docs describe that procedure instead.helm.sh/resource-policy: keepto MongoDB's claim by default: it would change the rendered output and the uninstall behaviour of existing releases. That would be a separate decision.helm uninstallgoes by the release manifest. The documented order (annotate the claim, then switch toexistingClaim) is therefore safe.foca-common.mongodbPersistence(low): there are only two uses, and they sit next to each other.Open questions
None.
🤖 Generated with Claude Code