feat: add persistentVolumeClaimRetentionPolicy to Dragonfly CRD#448
feat: add persistentVolumeClaimRetentionPolicy to Dragonfly CRD#448rafaelperoco wants to merge 1 commit intodragonflydb:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support in the Dragonfly operator for configuring persistentVolumeClaimRetentionPolicy on the underlying StatefulSet, enabling users to control PVC deletion/retention behavior on delete and scale-down.
Changes:
- Extend
DragonflySpecwith aPersistentVolumeClaimRetentionPolicyfield and wire it into the generated deepcopy logic. - Propagate the new spec field into the generated
StatefulSetinGenerateDragonflyResources. - Regenerate the CRD OpenAPI schema to expose the new
spec.persistentVolumeClaimRetentionPolicyfield, and apply minor gofmt alignment in the controller.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/resources/resources.go | Wires spec.persistentVolumeClaimRetentionPolicy from the Dragonfly CR into the StatefulSet.Spec.PersistentVolumeClaimRetentionPolicy. |
| internal/controller/dragonfly_instance.go | gofmt alignment of redis.Options.Addr fields; no functional changes. |
| config/crd/bases/dragonflydb.io_dragonflies.yaml | Updates CRD schema and descriptions to expose spec.persistentVolumeClaimRetentionPolicy.whenDeleted and .whenScaled to users. |
| api/v1alpha1/zz_generated.deepcopy.go | Updates autogenerated deepcopy to correctly copy the new PersistentVolumeClaimRetentionPolicy pointer field. |
| api/v1alpha1/dragonfly_types.go | Extends DragonflySpec with the PersistentVolumeClaimRetentionPolicy field using appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if df.Spec.PersistentVolumeClaimRetentionPolicy != nil { | ||
| statefulset.Spec.PersistentVolumeClaimRetentionPolicy = df.Spec.PersistentVolumeClaimRetentionPolicy |
There was a problem hiding this comment.
The new PersistentVolumeClaimRetentionPolicy behavior in GenerateDragonflyResources isn’t covered by tests, even though this function already has unit tests in internal/resources/image_test.go. To prevent regressions (e.g., the field silently not being propagated to the StatefulSet in future refactors), consider adding a test that sets DragonflySpec.PersistentVolumeClaimRetentionPolicy and asserts that the resulting StatefulSet.Spec.PersistentVolumeClaimRetentionPolicy reflects the same value.
|
Hi @rafaelperoco thanks for contributing ! I checked PR, and it's important that e2e tests passes, it would be also a good idea to add e2e test to cover this patch update, like here e.g https://github.com/dragonflydb/dragonfly-operator/pull/353/changes I see that changes in your PR are similar to #353 but there we have e2e test coverage, maybe to try to improve it a little bit ? Let's stay in touch |
|
@rafaelperoco, can you please fix the conflicts? |
|
gentle reminder, pls fix the conflicts :) |
Summary
Add support for
persistentVolumeClaimRetentionPolicyfield in the Dragonfly CRD, allowing users to configure whether PVCs are automatically deleted when the StatefulSet is deleted or scaled down.Fixes #340
Changes
PersistentVolumeClaimRetentionPolicyfield toDragonflySpecinapi/v1alpha1/dragonfly_types.gointernal/resources/resources.goExample Usage
Testing
Tested on kind cluster (Kubernetes v1.35.0):
persistentVolumeClaimRetentionPolicyacceptedwhenDeleted: Delete, whenScaled: Retaingo test ./internal/...)