Repository navigation
feat(chart): persist the bundled broker - #411
Conversation
Keep the data of the bundled RabbitMQ in a PersistentVolumeClaim (broker.persistence: size, accessModes, storageClass, existingClaim), so that queued tasks survive restarts of its pod. The node name is fixed, as RabbitMQ keeps its data in a directory named after it. Values without a broker.persistence map keep the emptyDir. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The kubelet makes the files of claims group-readable for the pod's fsGroup on mounting them, and Erlang refuses a cookie that others than its owner can read, so the broker would not start again. Mount the claim at /var/lib/rabbitmq/mnesia only and keep the home (with the cookie) in the emptyDir. Also simplify the persistence helper (claim name only), reject zero sizes in the schema, cover more cases in tests and split the docs on the broker's persistence. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR adds configurable PVC-backed persistence for the bundled RabbitMQ, migrates the broker to a single-replica StatefulSet with a stable node name to prevent concurrent claim use, preserves backward-compatible emptyDir and helper behavior, and validates queue survival through CI, tests, schemas, and documentation. Sequence diagram for queued task survival across broker restartsequenceDiagram
participant CI
participant AppPod
participant Broker as RabbitMQ StatefulSet
participant PVC
participant Worker
CI->>Worker: scale deployment to zero
CI->>AppPod: Celery.send_task('ci.persistence_check')
AppPod->>Broker: publish persistent task to celery queue
Broker->>PVC: store queued task
CI->>Broker: delete broker pod
Broker->>PVC: remount persistent data
Broker-->>CI: StatefulSet becomes ready
CI->>Broker: list_queues
Broker-->>CI: celery queue contains task
CI->>Worker: scale deployment to one
Worker->>Broker: consume celery queue
Broker-->>Worker: deliver queued task
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 #411 +/- ##
=========================================
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:
|
Importing the example's worker entry point loads the whole app, which exceeded the memory limit of the app's container (exit code 137). Send the task with a bare Celery app and give the app more memory in the Celery installation of CI. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="charts/foca-common/templates/_broker.tpl" line_range="111-113" />
<code_context>
name: data
+ {{- if $claimName }}
+ # RabbitMQ's data, on the claim
+ - mountPath: /var/lib/rabbitmq/mnesia
+ name: persistent-data
+ {{- end }}
# Writable, as the root file system is read-only by default
- mountPath: /tmp
</code_context>
<issue_to_address>
**Broker pods can share queue data**
When a broker pod is deleted or evicted and its RabbitMQ process is still shutting down when its replacement starts on the same node, the Deployment can create a replacement while a deleted pod is still terminating; because `ReadWriteOnce` allows multiple pods on the same node to mount the claim, both RabbitMQ processes can access the same Mnesia files and corrupt the broker state.
Use a controller or replacement mechanism that waits for the old broker process to terminate before another process can access the Mnesia claim.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and with persistence enabled, queued Celery tasks remain on the PVC across broker pod replacements and can later be delivered to the worker, where task side effects may already have happened before a revert. Reverting removes the persistent mount but cannot undo tasks that were delivered or their effects.
Blocking findings: charts/foca-common/templates/_broker.tpl:113
A Deployment replaces a deleted or evicted pod while the old one still terminates, and a ReadWriteOnce claim can be mounted by both pods on one node, so two RabbitMQ processes could use the same data. A StatefulSet starts the new pod only once the old one is gone. The template is now foca-common.brokerStatefulSet; foca-common.brokerDeployment stays as a deprecated alias for app charts written for 0.1.0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="charts/foca-common/templates/_broker.tpl" line_range="188" />
<code_context>
+ labels:
+ {{- include "foca-common.labels" (dict "root" $root "component" "broker") | nindent 4 }}
+spec:
+ accessModes:
+ {{- toYaml ($persistence.accessModes | default (list "ReadWriteOnce")) | nindent 2 }}
+ resources:
</code_context>
<issue_to_address>
**Read-only storage prevents broker startup**
When `broker.persistence.accessModes` is set to `ReadOnlyMany` and the provisioner honors its read-only semantics, the claim receives a read-only volume, so RabbitMQ cannot write its Mnesia data and broker operations fail.
Reject read-only access modes for the broker data claim.
Also at `examples/petstore/chart/values.yaml:321`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and on upgrade, replacing the broker Deployment with a StatefulSet does not copy queued messages out of the old pod’s emptyDir, so tasks still queued during the rollout can be lost. Reverting cannot restore those messages.
Blocking findings: charts/foca-common/templates/_broker.tpl:188
The broker writes its data to the claim, so ReadOnlyMany would leave it unable to start. The schema now accepts writable access modes only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Status
Ready to merge except for one step. Sourcery's single finding (broker pods could share queue data) is fixed in a2227d7 (StatefulSet), and I replied in its thread. I could not resolve the thread: GraphQL calls are not permitted for the agent. Please resolve it (or confirm the fix), then mark the PR ready and squash-merge. CI is green on a2227d7, including the kind check that a queued task survives a broker restart.
Summary
Closes #408.
The bundled RabbitMQ of the
foca-commonlibrary chart (unreleased 0.2.0) now keeps its data in a PersistentVolumeClaim, so queued tasks survive restarts of its pod (upgrades, node drains).broker.persistence:enabled(true in the petstore example),size,accessModes(defaultReadWriteOnce),storageClass(empty means the cluster's default;-means no dynamic provisioning) andexistingClaim.foca-common.brokerPersistentVolumeClaimand helperfoca-common.brokerClaimName. The petstore example addstemplates/broker-pvc.yaml./var/lib/rabbitmq/mnesiaonly. RabbitMQ's home, which holds the Erlang cookie, stays in theemptyDir. The kubelet makes files on claims group-readable for the pod'sfsGroupwhen it mounts them, and Erlang refuses to use a cookie that anyone other than its owner can read.ReadWriteOnceclaim can be mounted by two pods on the same node; a StatefulSet starts the new pod only once the old one is gone.foca-common.brokerStatefulSet; the petstore template file is renamed tobroker-statefulset.yaml.foca-common.brokerDeploymentremains as a deprecated alias for app charts written for 0.1.0, and a test covers it.RABBITMQ_NODENAME=rabbit@localhostis now fixed. RabbitMQ keeps its data in a directory named after the node, and the default name follows the pod's host name, which changes with every pod.broker.persistencemap (written for 0.1.0), or withenabled: false, keep the previousemptyDir.persistenceobject. They reject zero or invalid sizes, unknown access modes and unknown keys.charts.yml), in the Celery installation:docs/helm-chart.md):rpc://results are transient);rabbitmqctl change_password, since the user is created only on first start;How it was verified
pytest charts/foca-common/tests: 182 passed (snapshots updated).ruff checkandruff format --check,mypy charts/foca-common/tests: clean.helm lint examples/petstore/chart: clean.mkdocs build --strict: clean.actionlint: clean.Declined review findings
mongodb.persistenceblock (medium, quality). Out of scope here, and a breaking change of app values. Better as a follow-up issue, to be decided by the maintainer.wait_forfunction (medium, quality). The other steps ofcharts.ymlare inline too. I added a comment naming the example's worker entry point instead.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Persist the bundled RabbitMQ broker's task data across pod restarts while maintaining backward-compatible chart configuration.
New Features:
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: