shaynhornik opened a new pull request, #912:
URL: https://github.com/apache/solr-operator/pull/912
## Summary
Fixes #793.
Adds an optional `SolrCloud.spec.dataStorage.persistent.pvcRetentionPolicy`
with `whenDeleted` and `whenScaled` (`Retain` or `Delete`), which is passed to
the `persistentVolumeClaimRetentionPolicy` of the Solr StatefulSet.
`reclaimPolicy` keeps its type and meaning, so nothing changes for existing
manifests.
```yaml
spec:
dataStorage:
persistent:
pvcRetentionPolicy:
whenDeleted: Retain
whenScaled: Delete
```
## How it behaves
1. **Not set (every existing SolrCloud):** `reclaimPolicy` works as today,
including the storage finalizer, the orphan PVC cleanup after scale-down and
the deletion of all PVCs with the SolrCloud. The StatefulSet gets no policy
from the operator, and Kubernetes defaults it to Retain/Retain.
2. **Set:** the policy is passed to the StatefulSet as is; an omitted
sub-field defaults to `Retain`. Kubernetes then manages the PVCs:
`reclaimPolicy` is ignored, the operator does not delete PVCs itself, and an
existing storage finalizer is removed.
3. **No update loop:** `CopyStatefulSetFields` compares the policies with
the Kubernetes defaults filled in, so "no policy wanted" equals both a missing
policy and Retain/Retain.
4. **Removed again:** the StatefulSet goes back to Retain/Retain and
`reclaimPolicy` applies again.
The API type is the operator's own struct with enum and default markers,
using the upstream `PersistentVolumeClaimRetentionPolicyType` for both fields.
Reusing the upstream struct directly generates plain strings, so `whenDeleted:
delete` would pass the CRD and then fail every StatefulSet update.
## Questions for you
I proposed this shape on the issue; I'm happy to change it.
- **Replace or combine?** Here the policy replaces `reclaimPolicy` when set.
Combining them (a PVC is deleted if either says Delete) would mean
`reclaimPolicy: Delete` with `whenDeleted: Retain` still deletes data, so I did
not do that.
- **Hand-patched StatefulSets.** Because of point 4, a policy that someone
patched onto the StatefulSet by hand is reset to Retain/Retain when the option
is not set. I chose that so removing the option cannot leave a stale `Delete`
policy behind, and added a v0.11.0 upgrade note. The alternative is to leave
the field alone when the option is not set, as `IngressClassName` is handled;
that is a small change if you prefer it.
- **`whenDeleted: Delete` also applies when only the StatefulSet is
deleted**, for example with `kubectl delete statefulset`, not only when the
SolrCloud is deleted. That is how Kubernetes defines it; the docs say so.
- **Kubernetes version.** The policy is on by default from Kubernetes 1.27
and stable in 1.32, while the charts allow 1.22+. On older clusters the API
server drops the field, so nothing is deleted. The docs state the requirement;
there is no version guard.
Also included: regenerated CRDs and deepcopy, docs (`solr-cloud-crd.adoc`, a
sentence on scaling to zero in `scaling.adoc`, the upgrade note), the `solr`
Helm chart (`dataStorage.persistent.pvcRetentionPolicy`, README rows) and
changelog entries in both charts.
## Test plan
- Unit tests for the StatefulSet generation and for `CopyStatefulSetFields`
(unset equals nil and Retain/Retain; a change is detected and copied).
- A new envtest context in `solrcloud_controller_storage_test.go`: the
policy reaches the StatefulSet, a change updates it, no storage finalizer is
added with `reclaimPolicy: Delete`, and removing the option resets the policy.
The spec fails with any one of the three code changes reverted.
- `go test ./controllers -v`: 88 of 88 specs pass. `go test ./api/...
./controllers/util/...` passes.
- `make manifests generate`, `check-format`, `check-manifests`,
`check-generated`, `vet`, `check-docs` and `./hack/check_license.sh` pass.
- `helm lint` and `helm template` on `helm/solr`: the policy renders only
when set and storage is persistent. `ah lint` passes.
- Not run: the e2e/kind tests. envtest has no StatefulSet controller, so no
test covers Kubernetes actually deleting the PVCs.
This and #911 both replace the placeholder changelog block in
`helm/solr/Chart.yaml`, so whichever lands second needs a rebase there; I'll do
that.
Generated-by: Claude Code (Claude Fable 5.2). I reviewed and tested the
change.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]