[Bug]: enablePDB=false deletes independently managed PDBs with matching names

Aperta Adatta ai principianti
#11,600 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@WoahitsJoe ci sta già lavorando.

Dal 1/10/2026.

  • #11601 di @WoahitsJoe — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, kubernetes, postgresql

Direzione di ricerca

Inizia in internal/controller/cluster_create.go, in deletePodDisruptionBudgetIfExists, e verifica come i builder di PDB impostano la proprietà del controller. Riproduci il comportamento con i manifest Cluster e PDB forniti, quindi verifica che la pulizia rimuova i budget controllati da CNPG lasciando intatto un PDB gestito indipendentemente con lo stesso nome.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Is there an existing issue already for this bug?
  • I searched for an existing report and did not find one covering this deletion behavior.
Troubleshooting and supported releases
  • I read the troubleshooting and supported-release guidance.
Version

1.30.1. The same deletion path is present on main at 9c8de1b9e1af2b71f74a808c543c7be988d27baf.

Kubernetes version and environment

Kubernetes 1.35.6 on Google GKE. The operator is installed through Helm.

What happened?

With spec.enablePDB: false, the operator deletes an independently managed PDB whose name matches the Cluster name. The custom PDB has no owner references. Argo CD recreates it, then CNPG deletes it again, producing reconciliation churn and gaps in disruption-budget coverage.

The cleanup also targets <cluster-name>-primary. Neither deletion checks whether the PDB is controlled by the Cluster.

Expected: disabling CNPG's built-in PDBs removes its own budgets and leaves independently managed budgets intact.

Minimal reproduction

On a cluster with CNPG installed, apply these resources and observe the PDB and Cluster events:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: pdb-example
spec:
  instances: 2
  enablePDB: false
  storage:
    size: 1Gi
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: pdb-example
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      cnpg.io/cluster: pdb-example
      cnpg.io/podRole: instance

The manifests above use an example name. In the affected deployment, the custom PDB's metadata.ownerReferences is absent, but the Cluster receives DeletingPodDisruptionBudget events naming that PDB.

Relevant code

deletePodDisruptionBudgetIfExists gets the PDB by name and deletes it without checking ownership. CNPG's PDB builders already set a controller owner reference to the Cluster.

A small possible fix is to check metav1.IsControlledBy(&targetPdb, cluster) before deleting. This would preserve the existing cleanup for CNPG-owned budgets without introducing another annotation or API setting.

The current workaround is to give the custom PDB a different name.

Contribution

I'd like to work on this. Please confirm whether checking the existing controller owner reference is the preferred approach and assign the issue if appropriate.

This report and proposed approach were prepared with OpenAI Codex assistance and reviewed against the affected deployment and upstream source.

Code of Conduct
  • I agree to follow this project's Code of Conduct.
Lingua principale
Go
Stelle
9.7k
Fork
826
Merge medio
2g 1h
PR unite (30g)
122

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudnative-pg/cloudnative-pg

Tutte le issue di cloudnative-pg/cloudnative-pg

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.