[Bug]: Former primary is evicted mid-handover during node drain because cnpg.io/instanceRole=unhealthy matches neither PDB
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- go, kubernetes, postgresql
- 領域
- devops, infrastructure
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Go
- スター
- 9.7k
- フォーク
- 826
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 122
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudnative-pg/cloudnative-pg のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
cloudnative-pg/cloudnative-pg#12059 · コメント 3 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Docs]: Document the egress traffic that instance pods need when a NetworkPolicy restricts egress再び着手できるかも @fjvbn2003 が 13 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudnative-pg/cloudnative-pg#11750 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: A failed plugin backup sets the deprecated `status.lastFailedBackup`, so `cnpg_collector_last_failed_backup_timestamp` stays newer than the last available backup再び着手できるかも @fjvbn2003 が 13 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
cloudnative-pg/cloudnative-pg#11749 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Managed role stays pending-reconciliation when a membership has several grantor rows対応中かも @MatheuslFavaretto が 45 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
cloudnative-pg/cloudnative-pg#11624 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: enablePDB=false deletes independently managed PDBs with matching names対応中かも @WoahitsJoe が 61 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
cloudnative-pg/cloudnative-pg#11600 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
cloudnative-pg/cloudnative-pg の issue をすべて見る
似ている issue
-
[Bug]: Azure SAS signing uses local time instead of UTC, shifting validity window on non-UTC hosts対応中かも @huanghaoyuanhhy が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
zilliztech/milvus-backup#1418 ·
メンテナーはふだん 1 日以内に返信
-
good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
eugenioenko/ttt#1909 ·
メンテナーはふだん 1 日以内に返信
-
ColumnIndex max truncation returns a value smaller than the real max when the prefix is all 0xFFオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
parquet-go/parquet-go#819 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
-
feat(arithmetization): update `arithmetization` to ZkC version `v1.2.38`対応中かも @DavePearce が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
LFDT-Lineth/lineth-monorepo#4679 ·
メンテナーはふだん 1 日以内に返信