Skip to content

Clear FailedNodes on successful node reconciliation - #381

Merged
kubernetes-prow[bot] merged 2 commits into
kubernetes-sigs:mainfrom
Ayush4958:clear-failednodes-on-reconcillation
Aug 19, 2026
Merged

Clear FailedNodes on successful node reconciliation#381
kubernetes-prow[bot] merged 2 commits into
kubernetes-sigs:mainfrom
Ayush4958:clear-failednodes-on-reconcillation

Conversation

@Ayush4958

@Ayush4958 Ayush4958 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Description

This fixes a state leak in the NodeReconciler where transient evaluation errors permanently leaked into rule.Status.FailedNodes.

When a transient error resolves and the node successfully evaluates on the next retry, the controller was forgetting to clear the old failure from the cached rule object. As a result, the status patch actively re-merged the stale error back into the API server

This fix adds the missing else block to processNodeAgainstAllRules to clear the failure upon success, matching the correct logic already present in the RuleReconciler's processAllNodesForRule. It also adds a unit test to prevent future regressions.

Related Issue

Fixes #376

Type of Change

/kind bug

Testing

Added a regression test in node_controller_test.go ("should clear FailedNodes entry when node evaluation succeeds after a prior transient failure") which simulates a transient failure followed by a successful evaluation, asserting that FailedNodes drops to empty.

Checklist

  • make test passes
  • make lint passes

Does this PR introduce a user-facing change?

Fixed a bug where transient errors during node reconciliation caused nodes to become permanently stuck in the `FailedNodes` status of a `NodeReadinessRule`.

@kubernetes-prow kubernetes-prow Bot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 9, 2026
@netlify

netlify Bot commented Aug 9, 2026

Copy link
Copy Markdown

Deploy Preview for node-readiness-controller ready!

Name Link
🔨 Latest commit d2f37c3
🔍 Latest deploy log https://app.netlify.com/projects/node-readiness-controller/deploys/6a85b2011b88c90008c7b53f
😎 Deploy Preview https://deploy-preview-381--node-readiness-controller.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 9, 2026
@kubernetes-prow

Copy link
Copy Markdown

Hi @Ayush4958. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 9, 2026
@Ayush4958

Copy link
Copy Markdown
Contributor Author

@ajaysundark @Karthik-K-N
PR is ready for review pls take time to review it

thanks ...

@rawadhossain

Copy link
Copy Markdown
Contributor

@Ayush4958 I think the Fixes 379 reference is incorrect here. It seems unrelated to the PR you raised.

@Ayush4958

Copy link
Copy Markdown
Contributor Author

@Ayush4958 I think the Fixes 379 reference is incorrect here. It seems unrelated to the PR you raised.

yh, my bad, pressed wrong number key

@DsThakurRawat

Copy link
Copy Markdown
Contributor

Ran this branch against the repro from #376. The fix in node_controller.go works, and latestRule persisted to the fake client clears FailedNodes as expected.

One quick heads-up on the unit test in node_controller_test.go: go test ./internal/... trips on line 1214:

FailedNodes must be cleared after successful evaluation
Expected <[]v1alpha1.NodeFailure | len:1>: [{NodeName: "recovery-node", ...}] to be empty

That happens because getApplicableRulesForNode returns rule.DeepCopy(). processNodeAgainstAllRules mutates the copy and persists it to the API server, so the in-memory rule pointer from test setup never gets modified in place.

The API server assertion at line 1220 (latestRule.Status.FailedNodes being empty) already proves the fix works. Dropping the assertion on rule at line 1214 (or asserting on latestRule only) should get the suite green when prow tests run.

@Ayush4958

Copy link
Copy Markdown
Contributor Author

thanks for it and u were right about memory pointer and
I had dropped that assertion and It passes the test

@ajaysundark

ajaysundark commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR!

Seems duplicate of #209 and #333. I'll check the status of either of them first and see if can be picked up.

@ajaysundark ajaysundark reopened this Aug 11, 2026
errs = append(errs, err)
metrics.Failures.WithLabelValues(rule.Name, string(metrics.FailureReasonEvaluationError)).Inc()
} else {
// Clear any stale failures from previous reconciliation attempts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you extract clearNodeFailure as a helper instead? ref #333.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It'd be good to give credits to previous authors with "Co-authored-by"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can you extract clearNodeFailure as a helper instead? ref #333.

Done! I had extracted clearNodeFailure into a helper & also included the co-authored-by

@ajaysundark

Copy link
Copy Markdown
Contributor

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 19, 2026
Co-authored-by: bhuvan-somisetty <bhuvan-somisetty@users.noreply.github.com>
@ajaysundark

Copy link
Copy Markdown
Contributor

Thanks for the patch!

/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 19, 2026
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ajaysundark, Ayush4958

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

The pull request process is described 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

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 19, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit e259c3f into kubernetes-sigs:main Aug 19, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

[BUG] NodeReconciler permanently leaks transient errors into Status.FailedNodes

4 participants