Skip to content

Decouple Cordoning from Draining to Avoid Uncordoning User-Cordoned Nodes in Preservation Flow - #1119

Open
thiyyakat wants to merge 10 commits into
gardener:masterfrom
thiyyakat:enh/separate-cordon-drain
Open

Decouple Cordoning from Draining to Avoid Uncordoning User-Cordoned Nodes in Preservation Flow#1119
thiyyakat wants to merge 10 commits into
gardener:masterfrom
thiyyakat:enh/separate-cordon-drain

Conversation

@thiyyakat

@thiyyakat thiyyakat commented Jul 15, 2026

Copy link
Copy Markdown
Member

What this PR does / why we need it:

This PR removes the cordoning activity from RunDrain allowing us to control the two activities separately. This also enables the cordoning during machine preservation's drain to be done without altering spec.Unschedulable, thereby ensuring a user's manual cordoning/uncordoning is always honoured.

The changes in the PR are:

  • Remove function RunCordonOrUncordon
  • Add a new function cordonNode() and call it in the callers of RunDrain().
  • For preservation of failed machines, use custom taint to cordon.
  • Add helper function updateMachineStatusForDrain to update machine status during drain across all drain-xxx functions.

Which issue(s) this PR fixes:
Fixes #1114

Special notes for your reviewer:

IT was run with provider-AWS

The changes were tested by running mcm and mcm-provider-aws locally, targeting a shoot cluster.

Scenarios tested:

  • Drain during rolling update
  • Drain during inplace update
  • Drain during scale-down
  • Drain when a machine transitions to Failed and is preserved
  • Drain when a preserved machine transitions to Failed
  • kubectl delete mc <machine-name> after labelling machine with force-deletion:True
  • Drain when machineDrainTimeout lapses (force drain)

Release note:

De-couple cordoning and drain in the various operations that involve draining such as updates and machine preservation. 

@thiyyakat
thiyyakat requested a review from a team as a code owner July 15, 2026 11:44
@gardener-prow gardener-prow Bot added do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 15, 2026
@thiyyakat
thiyyakat force-pushed the enh/separate-cordon-drain branch 2 times, most recently from 5299319 to 49ad362 Compare July 15, 2026 12:17
@thiyyakat thiyyakat changed the title De-couple Cordoning and Draining De-couple cordoning and draining Jul 15, 2026

@takoverflow takoverflow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, would it be possible as part of this PR to combine the three separate drain methods? Since it's getting harder to keep track of which one does what specifically.

Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
@aaronfern

Copy link
Copy Markdown
Member

/assign

Comment thread pkg/util/provider/machinecontroller/machine_util.go
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
@aaronfern

Copy link
Copy Markdown
Member

would it be possible as part of this PR to combine the three separate drain methods? Since it's getting harder to keep track of which one does what specifically.

This is needed, but I think it should not be done in this PR. The scope and complexity will increase considerably. Not to mention additional time to properly test it.
I can open an issue for it, so that it can be picked up separately, and I can pick this up
wdyt? @takoverflow

@takoverflow

Copy link
Copy Markdown
Member

This is needed, but I think it should not be done in this PR.

Alright, fair enough. That can be tackled later.

@gardener-prow gardener-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 17, 2026
@gardener-prow

gardener-prow Bot commented Jul 17, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from aaronfern. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Comment thread pkg/util/provider/machinecontroller/node.go
Comment thread pkg/util/provider/machinecontroller/node.go
@thiyyakat

Copy link
Copy Markdown
Member Author

/hold

Putting this PR on hold until #1118 gets merged. This PR will require some preservation related cordoning-uncordoning changes, and requires the changes in #1118 to be included first.

@gardener-prow gardener-prow Bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 17, 2026
@thiyyakat
thiyyakat force-pushed the enh/separate-cordon-drain branch from cbdbb69 to 164b58d Compare July 27, 2026 08:33
@gardener-prow gardener-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 27, 2026
@thiyyakat
thiyyakat force-pushed the enh/separate-cordon-drain branch 2 times, most recently from a8e0897 to 117fb4b Compare July 27, 2026 08:34
@thiyyakat

Copy link
Copy Markdown
Member Author

/unhold

The PR has been rebased with the preservation flow changes in master. The manual tests mentioned in the PR description have been repeated with the latest changes.

@gardener-prow gardener-prow Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 27, 2026
Comment thread pkg/util/provider/machinecontroller/machine_util.go
@thiyyakat thiyyakat changed the title De-couple cordoning and draining Decouple Cordoning from Draining to Avoid Uncordoning User-Cordoned Nodes in Preservation Flow Jul 28, 2026
@thiyyakat thiyyakat added the kind/bug Bug label Jul 28, 2026
@gardener-prow gardener-prow Bot removed the do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Jul 28, 2026
Comment thread pkg/util/provider/machinecontroller/node.go
Comment thread pkg/util/provider/machinecontroller/machine_util.go Outdated
@gagan16k

Copy link
Copy Markdown
Member

/lgtm

Thanks for the work on preservation fixes @thiyyakat !

@gardener-prow gardener-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 28, 2026
@gardener-prow

gardener-prow Bot commented Jul 28, 2026

Copy link
Copy Markdown

LGTM label has been added.

DetailsGit tree hash: 502c0449a9b41b7da9426dac74e423c58864bfc6

@gardener-prow gardener-prow Bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lgtm Indicates that a PR is ready to be merged. labels Jul 28, 2026
thiyyakat and others added 9 commits August 5, 2026 09:52
- Add a new function `cordonNode()` and call it in the callers of `RunDrain()``.
- For preservation of failed machines, use custom taint to cordon.
- Remove function `RunCordonOrUncordon`
- Add helper function `updateMachineStatusForDrain` to update machine status during drain across all drain-xxx functions.
- Replace "Cordoning" in descriptions with "Drain" on failure of `cordonNode()`.
- Correct return value from `stopPreservationIfActive()`.
- Move warning and early return due to empty node above condition check.
- Change comment as per reviewer's suggestion.
- Change error message on preservation-related taint failure to say "tainting" instead of "cordoning".
- Improve readability of `RemoveTaintOffNode` function call in `stopPreservationIfActive`.
- Correct warning on `NotFound` errors in drain functions.
- Change log in `cordonNode` to improve clarity.
- Add node details to warning when cordoning fails for the force-deletion case.
- Return early from `drainNode` when nodename is empty. Remove `skipDrain`.
- Remove unnecessary assignment to `err`.
- Move `cordonNode()` to `node.go`
- Return `err` from `cordonNode()` for errors other than NotFound errors.
- Remove `func uncordonNodeIfCordoned`. It is no longer needed.
- Modify preservation tests to check for taint
- Remove irrelevant code in `drainPreservedNode`.
- Remove `getNodePreserveAnnotationValue` since it is not used.
- Correct error return statement in `cordonNode`.
…ved with preserve=now in the Running phase, transitions to Failed. This results in the node not being tainted or drained.
Co-authored-by: Gagan <gagan.katla@sap.com>
@thiyyakat
thiyyakat force-pushed the enh/separate-cordon-drain branch from 0baf17e to 344631d Compare August 5, 2026 05:17
@gardener-prow gardener-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 5, 2026

@takoverflow takoverflow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor nit, thanks for the changes!

Comment thread pkg/util/provider/machinecontroller/machine_util.go
@takoverflow
takoverflow dismissed their stale review August 6, 2026 19:24

All comments already addressed

Comment thread pkg/util/provider/machinecontroller/node.go Outdated
Comment thread pkg/util/provider/machinecontroller/machine_util.go
Add log for successful cordoning of node.
@thiyyakat
thiyyakat force-pushed the enh/separate-cordon-drain branch from 6f3a032 to d9580d3 Compare August 10, 2026 07:24
@thiyyakat
thiyyakat requested a review from aaronfern August 11, 2026 04:48
@aaronfern

Copy link
Copy Markdown
Member

Changes seem fine to me, thanks for making the changes!
/lgtm

@gardener-prow gardener-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 11, 2026
@gardener-prow

gardener-prow Bot commented Aug 11, 2026

Copy link
Copy Markdown

LGTM label has been added.

DetailsGit tree hash: 50e773f057fe93069bd9805d6d6ed8ed0b4b6ef0

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

Labels

cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. kind/bug Bug lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

De-couple drain and uncordoning

5 participants