Skip to content

Fix for Machine (sometimes) getting stuck with empty phase when finalizer addition exhausts retry budget - #1142

Open
elankath wants to merge 3 commits into
gardener:masterfrom
elankath:finalizer-fix
Open

Fix for Machine (sometimes) getting stuck with empty phase when finalizer addition exhausts retry budget#1142
elankath wants to merge 3 commits into
gardener:masterfrom
elankath:finalizer-fix

Conversation

@elankath

Copy link
Copy Markdown
Member

What this PR does / why we need it:

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

Special notes for your reviewer:

Release note:

Fix for Machine getting stuck with empty phase when finalizer addition exhausts retry budget

@elankath elankath self-assigned this Aug 27, 2026
@elankath
elankath requested a review from a team as a code owner August 27, 2026 07:49
@gardener-prow gardener-prow Bot added do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 27, 2026
@gardener-prow

gardener-prow Bot commented Aug 27, 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 elankath. 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

Signed-off-by: elankath <tarun.ramakrishna.elankath@sap.com>
@elankath elankath added the kind/bug Bug label Aug 27, 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 Aug 27, 2026
@elankath
elankath marked this pull request as draft August 27, 2026 07:52
@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 Aug 27, 2026
…on 409 conflicts

Treat 409 Conflict in addMachineFinalizers as a no-op (return nil) so the worker
retry budget is not consumed by informer cache lag.

Fixes gardener#1141

Signed-off-by: elankath <tarun.ramakrishna.elankath@sap.com>
Fixes gardener#1141

Signed-off-by: elankath <tarun.ramakrishna.elankath@sap.com>
@elankath

elankath commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

NOTE: We have a flaky test "set LDRCBST annotation on the machineSet and TriggerDeletionByMCM annotation is not set on the machineSet" which is timing dependent and tends to fail. The fix for this test should be addressed in some other PR.

@elankath
elankath marked this pull request as ready for review August 27, 2026 09:50
@elankath elankath removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 27, 2026
// Informer cache is stale; the watch event will re-enqueue the machine once the
// cache catches up, so this is not a retriable error from the worker's perspective.
// Returning nil avoids burning a retry slot from the fixed budget (DefaultMaxRetries).
return machineutils.ShortRetry, nil

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.

There is a ConflictRetry timeout defined in utils. Would you instead want to use that is the 5s ShortRetry enough?

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.

I don't think it matters, the caller discards the retry period. Can we change the signature to return just an error then? The function is only used in one place which discards the retry period returned.

// had the MCM finalizer added would be silently dropped here. Re-enqueue it so
// reconcileClusterMachine is reached and the machine advances past the empty phase.
if !sets.NewString(oldMachine.Finalizers...).HasAll(newMachine.Finalizers...) {
klog.V(4).Infof("updateMachine: machine %q gained finalizer — re-enqueuing despite unchanged Generation", newMachine.Name)

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.

Would come handy when debugging

Suggested change
klog.V(4).Infof("updateMachine: machine %q gained finalizer — re-enqueuing despite unchanged Generation", newMachine.Name)
klog.V(3).Infof("updateMachine: machine %q gained finalizer — re-enqueuing despite unchanged Generation", newMachine.Name)

}

// Add finalizers if not present on machine object
_, err = c.addMachineFinalizers(ctx, machine)

@r4mek r4mek Sep 2, 2026

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.

I was wondering if we can just requeue the machine here like:

retryPeriod, err := c.addMachineFinalizers(ctx, machine)
if err != nil {
    c.enqueueMachineAfter(machine, time.Duration(retryPeriod), "failed to add MachineFinalizer")
	return nil
}

instead of tracking the update event and requeuing in updateMachine().
And I am not sure if we should proceed if the finalizer is not added on the machine (since we return nil for ConflictError in c.addMachineFinalizers()).

@r4mek r4mek Sep 3, 2026

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.

BTW I was wondering if MachineFinalizers should be added by machine controller or machineset controller. And if machine controller does add it, should we be requequing the machine or continue?

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

Labels

kind/bug Bug size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Machine can get permanently stuck with empty phase when finalizer addition exhausts retry budget

4 participants