cloudnative-pg / cloudnative-pg/charts

Add spec.deletionPolicy support to cluster chart values

Open
#909 0 comments 0 reactions 0 assignees View on GitHub
chart( cluster )
Dominant language
Go Template
Stars
621
Forks
265
Avg merge
7d 12h
Merged PRs (30d)
7

Description

The CNPG `Cluster` CRD supports `spec.deletionPolicy` (`retain` | `delete`) to control
whether PVCs are cascade-deleted when the `Cluster` CR is deleted. This is a critical
data-protection field, especially for GitOps/ArgoCD users where accidental cluster
deletion (e.g. a prune sync) can cause permanent data loss.

However, the `cnpg/cluster` Helm chart (v0.6.0) does not expose this field in its
`values.yaml` or template it in `cluster.yaml`. Setting `cluster.deletionPolicy: retain`
in Helm values has no effect — confirmed via `helm template | grep deletionPolicy`
returning empty output.

# Add to values.yaml
cluster:
deletionPolicy: retain

# Render the chart
helm template my-cluster cnpg/cluster --version 0.6.0 -f values.yaml \
| grep deletionPolicy

Output: (empty — field is silently ignored)

# Verify on running cluster
kubectl get cluster my-cluster -o jsonpath='{.spec.deletionPolicy}'

Output: (empty — default 'delete' is in effect)

# Impact:

With no way to set deletionPolicy: retain via Helm, any deletion of the Cluster CR
(ArgoCD prune, helm uninstall, accidental kubectl delete) cascade-deletes all PVCs
and all data with no warning or recovery path. This has caused production data loss
in real deployments.

Related issue in main repo: cloudnative-pg/cloudnative-pg#8442
Related discussion: cloudnative-pg/cloudnative-pg#5253

# Expected result:

cluster.deletionPolicy: retain in values.yaml should render as spec.deletionPolicy: retain
in the Cluster CR, identical to how other top-level spec fields like cluster.instances
and cluster.enablePDB are handled.

# Proposed Fix
In charts/cluster/templates/cluster.yaml, add:

spec:
{{- with .Values.cluster.deletionPolicy }}
deletionPolicy: {{ . }}
{{- end }}

And in charts/cluster/values.yaml, add with a safe default:

cluster:
-- Controls whether PVCs are deleted when the Cluster CR is deleted.
'delete' (default) cascade-deletes PVCs. 'retain' keeps PVCs safe.
**STRONGLY** recommended to set 'retain' in production.
deletionPolicy: delete

# Environment
Chart version: cnpg/cluster 0.6.0
CNPG operator version: 1.29.0
Kubernetes: GKE
Deployment: ArgoCD GitOps with ServerSideApply=true

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.