[Bug]: Former primary is evicted mid-handover during node drain because cnpg.io/instanceRole=unhealthy matches neither PDB
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go, kubernetes, postgresql
- Ambito
- devops, infrastructure
Direzione di ricerca
The two PDBs are built in pkg/specs/poddisruptionbudget.go; start by enumerating the selectors it emits for <cluster>-primary and <cluster>. Then read markOldPrimaryAsUnhealthy in internal/controller/replicas.go:224 and the switchover path at internal/controller/cluster_controller.go:409-421 to see when a pod carries cnpg.io/instanceRole=unhealthy and when it flips back to replica. The change is a third PDB with maxUnavailable: 0 selecting the unhealthy role when enablePDB is true; extend the PDB spec unit tests to assert it exists.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is there an existing issue already for this bug?
- I have searched for an existing issue, and could not find anything. I believe this is a new bug.
I have read the troubleshooting guide
- I have read the troubleshooting guide and I think this is a new bug.
I am running a supported version of CloudNativePG
- I am running a supported version of CloudNativePG.
Version
1.30.1 / 1.30.2 (Helm chart cloudnative-pg-0.29.1); verified on main at e9eec0d as well
What version of Kubernetes are you using?
1.35.7
What is your Kubernetes environment?
Cloud: Azure AKS
How did you install the operator?
Helm
What happened?
When a node hosting the primary instance is cordoned and drained (e.g., during an AKS node pool roll/upgrade), the operator triggers a switchover and immediately relabels the former primary Pod to cnpg.io/instanceRole=unhealthy (markOldPrimaryAsUnhealthy in internal/controller/replicas.go:224 and internal/controller/cluster_controller.go:409-421).
Neither of the operator's PodDisruptionBudgets (pkg/specs/poddisruptionbudget.go) matches that label:
<cluster>-primaryselectscnpg.io/instanceRole: primary<cluster>selectscnpg.io/instanceRole: replica
Because the former primary is now selected by no PDB, the ongoing kubectl drain immediately evicts the Pod mid-handover, while its instance manager is shutting down PostgreSQL to step down cleanly. Terminated mid-handover, the former primary never releases the primary lease; the promotion target then blocks waiting for the primary lease to expire, turning a ~4 s switchover into a ~40 s write outage.
Observed in production (2026-10-20, 3-instance cluster, enablePDB: true, node pool roll):
- Control switchover on the same roll 3 minutes earlier (
pg-2 → pg-1):pg-2finished demotion at04:52:37, was evicted at04:52:38, andpg-1acquired the primary lease at04:52:38.8(~4 s total, 0 failed requests). - Failing switchover (
pg-1 → pg-3):04:55:52: node carryingpg-1cordoned & drained04:55:55:SwitchingOverpg-1 → pg-304:55:56.5:pg-1"Shutting it down to allow it to be demoted"04:55:58: drain evictspg-1(Killing: Stopping container postgres) — 3 s into handover04:56:17:pg-3"Primary lease not yet acquired"04:56:36:pg-3"Acquired primary lease"(~40 s write outage; all client probes returned 503/connection errors between04:56:04and04:56:40)
Workaround that verified the root cause:
Adding an independent PDB selecting the unhealthy role with maxUnavailable: 0:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: pg-handover
spec:
selector:
matchLabels:
cnpg.io/cluster: pg
cnpg.io/instanceRole: unhealthy
maxUnavailable: 0
With default unhealthyPodEvictionPolicy: IfHealthyBudget, even a non-Ready former primary is held while labelled unhealthy. Once it finishes stepping down and releases the lease, the operator promotes the target and relabels the former primary to replica, at which point the drain proceeds under the replicas PDB.
Expected:
When enablePDB: true, the former primary should remain protected from voluntary eviction until handover completes (for example via an operator-managed handover PDB for cnpg.io/instanceRole=unhealthy, or equivalent protection until the primary lease is released and the pod transitions to replica).
(Note: this is distinct from #11897 and #10103, which concern the replicas PDB allowing a standby to be evicted; here the former primary itself is evicted mid-handover while carrying cnpg.io/instanceRole=unhealthy.)
Cluster resource
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: pg
spec:
instances: 3
enablePDB: true
primaryUpdateStrategy: unsupervised
primaryUpdateMethod: switchover
storage:
size: 50Gi
Relevant log output
# 2026-10-20 — node drain during AKS node pool roll
04:55:55 Cluster/pg SwitchingOver Switching over from pg-1 to pg-3
04:55:56.5 Pod/pg-1 instance-mgr Shutting it down to allow it to be demoted
04:55:58 Pod/pg-1 Killing Stopping container postgres
04:56:17 Pod/pg-3 instance-mgr Primary lease not yet acquired
04:56:36 Pod/pg-3 instance-mgr Acquired primary lease
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
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cloudnative-pg/cloudnative-pg
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
cloudnative-pg/cloudnative-pg#12059 · 3 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[Docs]: Document the egress traffic that instance pods need when a NetworkPolicy restricts egressForse di nuovo libera @fjvbn2003 l’ha presa 13 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cloudnative-pg/cloudnative-pg#11750 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: A failed plugin backup sets the deprecated `status.lastFailedBackup`, so `cnpg_collector_last_failed_backup_timestamp` stays newer than the last available backupForse di nuovo libera @fjvbn2003 l’ha presa 13 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
cloudnative-pg/cloudnative-pg#11749 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Managed role stays pending-reconciliation when a membership has several grantor rowsForse già presa @MatheuslFavaretto l’ha presa 45 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
cloudnative-pg/cloudnative-pg#11624 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: enablePDB=false deletes independently managed PDBs with matching namesForse già presa @WoahitsJoe l’ha presa 61 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
cloudnative-pg/cloudnative-pg#11600 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di cloudnative-pg/cloudnative-pg
Issue simili
-
feat(arithmetization): update `arithmetization` to ZkC version `v1.2.38`Forse già presa @DavePearce l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
LFDT-Lineth/lineth-monorepo#4679 ·
I maintainer di solito rispondono entro 1 giorno
-
macOS: MixMusic stalls as the GPU times out drawing frames, and the media keys fail to register at every startForse già presa @fzn0x l’ha presa oggi. Apertabug priority: high
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
funding: failure logs print `<nil>` error and zero channel IDForse già presa @litbot-9000 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
lightningnetwork/lnd#11676 ·
I maintainer di solito rispondono entro 1 giorno
-
effort:s impact:low raised-by:reviewer risk:low
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
medici-finance/assay#8050 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno