Repository navigation
Description
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 have read the troubleshooting guide and I think this is a new bug.
Contact Details
No response
Version
1.26 (latest patch)
What version of Kubernetes are you using?
1.31
What is your Kubernetes environment?
Other
How did you install the operator?
Helm
What happened?
Cordoning a kubernetes node causes the operator to perform a switchover, even if the primaryUpdateStrategy is set to "supervised". While I believe this is intended, I would still consider this "feature" as a bug, since you do not normally expect in a kubernetes environment, that a cordon affects existing workloads.
I'm aware, that you can turn on the maintenance window for a given database, but we manage a lot of database clusters, and manually turning these on every time we conduct some form of maintenance that requires a node cordon is suboptimal.
I'm also aware, that instead of cordoning (which is equivalent to adding the node.kubernetes.io/unschedulable:NoSchedule taint), you could add a custom taint with the NoSchedule effect, so you could achieve the same thing, while it being ignored by the operator. While this is a good workaround, I do not believe this should be the way to go, since it's not a thing people are generally aware of. Therefore, leaving taints on the nodes unintentionally could be common, or even worse, cordoning a node running a primary instance, and performing an unintended switchover.
While a switchover normally causes little to negligible downtime, in some cases, this could very much disturb sensitive workloads, so I believe at least there should be an option (ideally, on the operator level) to disable automated switchover, if a cordon is issued on a node.
Cluster resource
Relevant log output
{"level":"info","ts":"2025-06-10T07:19:30.066361654Z","msg":"Primary is running on an unschedulable node, will try switching over","controller":"cluster","controllerGroup":"postgresql.cnpg.io","controllerKi
nd":"Cluster","Cluster":{"name":"cluster","namespace":"cluster-namespace"},"namespace":"cluster-namespace","name":"cluster","reconcileID":"9b6e086d-48a6-4e62-8799-9a2634a2c419","node":"node1","primary":"cluster-1"}Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
chris-gooch commentedon Jun 27, 2025
The role switchover is required in order to move the blocking primary pod disruption budget to a suitable replica, else this PDB blocks node draining indefinitely when a cluster has
enablePDB: true.A recent feature was also introduced to honor additional autoscaler drain taints (e.g. Karpenter) in v1.26.
lgyurci commentedon Jun 27, 2025
Isn't there a way to reliably determine if the node is only cordoned, or actually being drained? It would make sense to differentiate, since these are very different operations.
I believe there should be at least an option to disable this behavior in cnpg. I wouldn't really mind if the drain gets blocked, because then I can at least determine the fate of the databases manually
chris-gooch commentedon Jun 27, 2025
Both drain and cordon commands mark the node
spec.unschedulable: truetherefore, there is no way for the CNPG operator to differentiate between them.I would just cordon or drain the nodes when you need the planned maintenance.
github-actions commentedon Sep 15, 2025
This issue is stale because it has been open for 60 days with no activity.
rich0 commentedon Sep 27, 2025
I'm actually having the exact opposite issue as you are, related to this. I use a custom taint, and I WANT CNPG to notice it and treat the node as being cordoned and migrate the primary to another node, without having to cordon it. (My use case is that I taint nodes ahead of planned maintenance so that workloads avoid it, but I use a custom taint so that Rook/Ceph OSDs running on the node can still operate (those rely on local storage, and are highly available so they can be interrupted during maintenance without issue). Right now I just apply cordon before draining a node to migrate CNPG primary roles off of it, and tell Ceph to not try to recover from outages while the node is cordoned (since data migration of multiple disks is not desired if an OSD goes down and can no longer restart in a planned outage).
This seems like the sort of thing that would benefit from a configuration setting. Then we could both have our cake and eat it too.
rouke-broersma commentedon Sep 29, 2025
Rook by default sets noout on OSDs part of a draining node, does this not already achieve the desired effect?
@chris-gooch
I would expect CNPG operator to catch the eviction event and failover based on that during the termination grace period, not check node schedulable status.
kiberx commentedon Nov 12, 2025
Hello,
We mark kubernetes node to cordon for a couple of minutes to debug another application and got many cnpg databases as unavailable. We didn't expect that!
Cordoning a node marks it as unschedulable, preventing new pods from being assigned to the node. Existing pods continue to run.
It's a strange behavior.
cloudnative-pg:1.26
rich0 commentedon Nov 12, 2025
Well, it does make sense to have some way to migrate CNPG of a node in an orderly way. Shouldn't take long though.
Maybe have a setting for a taint or label it watches for? Or a toleration for the reverse behavior?
github-actions commentedon Jan 12, 2026
This issue is stale because it has been open for 60 days with no activity.
rouke-broersma commentedon Jan 12, 2026
Not stale
4 remaining items
kiberx commentedon Feb 11, 2026
Can anyone provide DRAIN_TAINTS, when node in cordon but still available?
redbaron commentedon Apr 7, 2026
It seems that
DRAIN_TAINTSadd extra taints to trigger drain, but do not disable defaultspec.Unschedulablehandling: #9997github-actions commentedon Jun 25, 2026
This issue is stale because it has been open for 60 days with no activity.
redbaron commentedon Jun 25, 2026
activity
legrandlegrand commentedon Jul 2, 2026
Could this be officially recognized as a bug ?
Thanks in advance
github-actions commentedon Sep 6, 2026
This issue is stale because it has been open for 60 days with no activity.
redbaron commentedon Sep 6, 2026
activity
ardentperf commentedon Oct 30, 2026
seems like the the underlying problem is the mechanism k8s uses for both cordon and drain -- marking the node unschedulable. currently CNPG implements drain by watching for the node to be unschedulable... which also gets hit by cordon
poking around w an agent and it's suggesting we might be able to have a webhook intercept pod/eviction requests and trigger switchover based on that, rather than the unscheduleable node state.
this does add a new challenge though - if we're waiting until the drain to trigger failovers, then we have an issue where k8s can kill the old primary pod before it has finished uploading its final WAL to object storage which might not be ideal either. the only thing blocking k8s from killing the pod is the PDB, but as soon as the primary label moves, the PDB disappears
ardentperf commentedon Oct 30, 2026
thinking this through, i have two ideas.
first:
an unschedulable/cordoned node should not be eligible as a failover/promotion target. today, cordon can move the primary away, but nothing prevents CNPG from moving it right back of the new primary fails before the drain. Issue #11794 might be related to this. AI is telling me that rolling update and failover paths might not be considering DRAIN_TAINTS right now
second:
maybe there could be a new "old-primary" label which enables us to use PDBs to protect nodes from getting killed early during drains, and maybe then we could intercept pod/eviction instead of using drain taints to trigger switchovers