Skip to content

[master] Fix preservation reconciliation to prevent deviation from regular flow for non-preservation-bound machines and prevent machines getting stuck in creation flow beyond CreationTimeout#1118

Draft
gardener-ci-robot wants to merge 20 commits into
gardener:masterfrom
gardener-ci-robot:cherry-pick-1111-to-master
Draft

[master] Fix preservation reconciliation to prevent deviation from regular flow for non-preservation-bound machines and prevent machines getting stuck in creation flow beyond CreationTimeout#1118
gardener-ci-robot wants to merge 20 commits into
gardener:masterfrom
gardener-ci-robot:cherry-pick-1111-to-master

Conversation

@gardener-ci-robot

@gardener-ci-robot gardener-ci-robot commented Jul 10, 2026

Copy link
Copy Markdown

What this PR does / why we need it:
The previous implementation had several correctness issues in the machine preservation flow:

  1. Unconditional uncordon on every reconcile: uncordonNodeIfCordoned was called whenever IsMachineActive returned true and a node name was present. This meant any Running machine with a cordoned backing node — even one cordoned for reasons unrelated to preservation (e.g. Cluster Autoscaler scale-down) — would be unconditionally uncordoned on every reconcile pass.
  2. No gate for non-preservation-bound machines: Every machine was processed through the full preservation logic on every reconcile, even machines with no preservation state at all (no annotations, no PreserveExpiryTime). This caused unnecessary API calls on non-preserved machines.
  3. Stale clone causing conflict errors: The LastAppliedNodePreserveValueAnnotation sync in the defer compared annotations on a clone that had already been updated via UpdateStatus calls inside preserveMachine/stopPreservationIfActive. Because UpdateStatus returns the server's stored metadata (not the in-memory mutation), the annotation diff was never detected and the sync was silently dropped. On paths where the sync did fire, it was using a stale ResourceVersion, producing spurious conflict errors.

This PR fixes all of the above by:

  • Introducing preserveStateInfo struct populated by getPreserveStateInfo at the start of each reconcile, reading node and machine annotation state in a single pass and storing it for the rest of the function. This eliminates the double lister read and decouples the annotation sync from the defer.
  • Adding an explicit isMachinePreservationBound gate: machines with no preservation state (no PreserveExpiryTime, no preserve annotation on machine or node, no LastAppliedNodePreserveValueAnnotation) skip the entire preservation flow and return LongRetry, nil immediately.
  • Moving the LastAppliedNodePreserveValueAnnotation sync to an explicit updatePreserveAnnotationOnMachine call at the end of the function via shouldAnnotationsBeUpdatedOnMachine, rather than a defer that compared potentially stale annotation maps.
  • Moving uncordon logic into stopPreservationIfActive (step 4), so it fires only when preservation is actively being stopped for a Running machine — not on every reconcile of any active machine. The manageMachinePreservation path retains a narrower uncordon call gated on !preservationStopped && PreserveExpiryTime != nil && Phase == Running to handle the case where preserveMachine is called on a Running machine (e.g. preserve=now set by user).
  • Adding IsNotFound handling in the defer so transient not-found errors during preservation (e.g. machine deleted mid-reconcile) return LongRetryrather than ShortRetry.
  • Propagating the updated node object from removePreservationRelatedAnnotationsOnNode (now returns *corev1.Node) so that the subsequent uncordon step in stopPreservationIfActive operates on a current node object rather than a potentially stale one.
  • Removing the redundant PreventAutoPreserveAnnotationValues set in machineutils (it was identical to AllowedPreserveAnnotationValues minus ""); manageAutoPreservationOfFailedMachines in machineset.go now uses AllowedPreserveAnnotationValues directly.

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

Special notes for your reviewer:

Release note:

Fix preservation reconcile loop to avoid unconditionally uncordoning nodes unrelated to machine preservation, prevent spurious writes on non-preserved machines, and eliminate conflict errors caused by stale machine object comparison in the defer annotation sync.

thiyyakat added 20 commits July 10, 2026 05:41
…ines is not modified by `manageMachinePreservation`
…n manageMachinePreservation:

This call is made to uncordon nodes that are preserved with preserve=now and the machine has recovered to Running. Preservation is not stopped in this case.
…edByMCM` to `PreserveMachineAnnotationValueAutoPreserved`
- nits
- if not found, machine annotation value must be enforced
- if machine annotation value is invalid, log and continue assuming it does not exist
- gate `removePreserveAnnotationOnMachine` when node is not found
…encing happens in future edits. Add removed test.
@gardener-prow

gardener-prow Bot commented Jul 10, 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 assign gagan16k for approval. 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

@gardener-prow gardener-prow Bot added cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 10, 2026
@thiyyakat thiyyakat marked this pull request as draft July 10, 2026 05:43
@gardener-prow gardener-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 10, 2026
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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/bug Bug size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Machine stuck with no phase past CreationTimeout

2 participants