Skip to content

[Bug]: Node cordon (unschedulable taint) causes a switchover #7799

Open

Description

@lgyurci

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

  1. added
    triage
    on Jun 10, 2025
  2. chris-gooch commented on Jun 27, 2025

    @chris-gooch

    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.

  3. lgyurci commented on Jun 27, 2025

    @lgyurci
    Author

    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

  4. chris-gooch commented on Jun 27, 2025

    @chris-gooch

    Both drain and cordon commands mark the node spec.unschedulable: true therefore, 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.

  5. github-actions commented on Sep 15, 2025

    @github-actions
    Contributor

    This issue is stale because it has been open for 60 days with no activity.

  6. rich0 commented on Sep 27, 2025

    @rich0

    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.

    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.

  7. rouke-broersma commented on Sep 29, 2025

    @rouke-broersma

    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).

    Rook by default sets noout on OSDs part of a draining node, does this not already achieve the desired effect?

    @chris-gooch

    Both drain and cordon commands mark the node spec.unschedulable: true therefore, there is no way for the CNPG operator to differentiate between them.

    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.

  8. kiberx commented on Nov 12, 2025

    @kiberx

    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

  9. rich0 commented on Nov 12, 2025

    @rich0

    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?

  10. github-actions commented on Jan 12, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open for 60 days with no activity.

  11. rouke-broersma commented on Jan 12, 2026

    @rouke-broersma

    Not stale

  12. 4 remaining items

  13. kiberx commented on Feb 11, 2026

    @kiberx

    Can anyone provide DRAIN_TAINTS, when node in cordon but still available?

  14. redbaron commented on Apr 7, 2026

    @redbaron
    Contributor

    It seems that DRAIN_TAINTS add extra taints to trigger drain, but do not disable default spec.Unschedulable handling: #9997

  15. github-actions commented on Jun 25, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open for 60 days with no activity.

  16. redbaron commented on Jun 25, 2026

    @redbaron
    Contributor

    activity

  17. legrandlegrand commented on Jul 2, 2026

    @legrandlegrand

    Could this be officially recognized as a bug ?
    Thanks in advance

  18. github-actions commented on Sep 6, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open for 60 days with no activity.

  19. redbaron commented on Sep 6, 2026

    @redbaron
    Contributor

    activity

  20. added and removed
    triage
    on Sep 10, 2026
  21. ardentperf commented on Oct 30, 2026

    @ardentperf
    Contributor

    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

  22. ardentperf commented on Oct 30, 2026

    @ardentperf
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions