Skip to content

fix(controller): handle node deletion, label selector unmatching, and status drift in NodeReconciler - #339

Open
bhuvan-somisetty wants to merge 2 commits into
kubernetes-sigs:mainfrom
bhuvan-somisetty:fix-node-deletion-and-selector-unmatch
Open

fix(controller): handle node deletion, label selector unmatching, and status drift in NodeReconciler#339
bhuvan-somisetty wants to merge 2 commits into
kubernetes-sigs:mainfrom
bhuvan-somisetty:fix-node-deletion-and-selector-unmatch

Conversation

@bhuvan-somisetty

@bhuvan-somisetty bhuvan-somisetty commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Description

This PR resolves issue #338 by fixing systemic node lifecycle state management, orphaned taint cleanup, and status synchronization bugs across NodeReconciler and RuleReconciler:

  1. Node Deletion Cleanup: When a node is deleted from the cluster, NodeReconciler.Reconcile handles the apierrors.IsNotFound(err) condition via handleNodeDeletion(ctx, nodeName). It purges the deleted node from rule.Status.NodeEvaluations, rule.Status.AppliedNodes, and rule.Status.FailedNodes across all cached rules and updates Prometheus node_readiness_nodes_by_state gauge metrics.
  2. Comprehensive cleanupDeletedNodes: Updated RuleReconciler.cleanupDeletedNodes to filter AppliedNodes and FailedNodes alongside NodeEvaluations.
  3. Orphaned Taint Removal on Selector Unmatch: In processNodeAgainstAllRules, when a node's labels change such that it no longer matches a rule's spec.NodeSelector, the controller checks if the node holds rule.Spec.Taint or has status entries. If so, it invokes removeTaintBySpec to remove the orphaned taint and strips the node from rule status.
  4. Real-time AppliedNodes Synchronization: Updated NodeReconciler status patch logic to append matching nodes to rule.Status.AppliedNodes upon successful evaluation or remove them if evaluation fails/unmatches.

Related Issue

Fixes #338

Type of Change

/kind bug

Testing

  • Unit and integration tests added in internal/controller/node_controller_test.go and internal/controller/nodereadinessrule_controller_test.go covering node deletion handling, label selector unmatch taint removal, and AppliedNodes status synchronization.
  • Verified test suite passes locally.

Checklist

  • make test passes
  • make lint passes

Does this PR introduce a user-facing change?

Fix state inconsistency, orphaned readiness taints, and status drift in NodeReconciler on node deletion and label selector changes.

Signed-off-by: bhuvan-somisetty somisettybhuvan5@gmail.com

@kubernetes-prow kubernetes-prow Bot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/bug Categorizes issue or PR as related to a bug. labels Aug 2, 2026
@netlify

netlify Bot commented Aug 2, 2026

Copy link
Copy Markdown

Deploy Preview for node-readiness-controller canceled.

Name Link
🔨 Latest commit c3bb1da
🔍 Latest deploy log https://app.netlify.com/projects/node-readiness-controller/deploys/6a739eb6d929440008258b7f

@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bhuvan-somisetty
Once this PR has been reviewed and has the lgtm label, please assign tallclair 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

@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 2, 2026
@kubernetes-prow

Copy link
Copy Markdown

Hi @bhuvan-somisetty. 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 2, 2026
@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix-node-deletion-and-selector-unmatch branch from 1128043 to 6c6a68e Compare August 2, 2026 07:23
@kubernetes-prow

Copy link
Copy Markdown

@bhuvan-somisetty: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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.

@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix-node-deletion-and-selector-unmatch branch from 6c6a68e to 9e9a1d1 Compare August 2, 2026 07:23
@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

/retest

@kubernetes-prow

Copy link
Copy Markdown

@bhuvan-somisetty: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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.

@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix-node-deletion-and-selector-unmatch branch from 9e9a1d1 to acfc6f7 Compare August 2, 2026 07:25
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Aug 2, 2026
@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

Hi @ajaysundark @vitorfloriano @Priyankasaggu11929,

Could you please take a look at this PR when you get a chance?

This PR resolves issue #338 by fixing node deletion cleanup, label selector unmatching taint removal, and real-time \AppliedNodes\ status synchronization across \NodeReconciler\ and \RuleReconciler.

Thanks!

@Priyankasaggu11929

Copy link
Copy Markdown
Member

Thanks for the PR @bhuvan-somisetty!

I'll spend some time understanding the reported issue (because I've a feeling that atleast Orphaned Taints on Node Label Selector Unmatch is done by design so far.)

will drop some comments by EOD tomorrow.

@Priyankasaggu11929 Priyankasaggu11929 self-assigned this Aug 3, 2026
@Priyankasaggu11929

Copy link
Copy Markdown
Member

/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 3, 2026
@ajaysundark

ajaysundark commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

we are looking to move away from per-node status updates in NRC #89, this could wait until the per-node api is landed? also it is a good idea to send small PRs with reviewable context than to push multiple orthogonal changes into a single PR.

xref -- #338 (comment)

cc @Priyankasaggu11929 @Karthik-K-N

@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

Good call, dropped the AppliedNodes real-time sync piece since it's per-node status work that #89 is going to replace anyway. Also pulled the selector-unmatch taint cleanup out into its own issue (#342) per your comment on #338, so this PR is now scoped to just node deletion handling + making cleanupDeletedNodes cover AppliedNodes/FailedNodes too, not just NodeEvaluations. Pushed the update.

@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix-node-deletion-and-selector-unmatch branch from 0f0a49a to 6337954 Compare August 5, 2026 06:15
@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 5, 2026
Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
Drop the selector-unmatch taint cleanup (split into kubernetes-sigs#342 for its own
design discussion) and the AppliedNodes real-time sync (deferred since
kubernetes-sigs#89 plans to move per-node status out of rule.status entirely). This
keeps the change scoped to handling node deletion and making
cleanupDeletedNodes cover AppliedNodes/FailedNodes, not just
NodeEvaluations.
@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix-node-deletion-and-selector-unmatch branch from 6337954 to c3bb1da Compare August 5, 2026 20:36
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 5, 2026
@bhuvan-somisetty

Copy link
Copy Markdown
Contributor Author

Rebased onto main to resolve the conflict in node_controller.go and pushed. All checks (test, test-e2e, verify-all) are passing now, ready for review.

@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 15, 2026
@kubernetes-prow

Copy link
Copy Markdown

PR needs rebase.

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

Copy link
Copy Markdown

@bhuvan-somisetty: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-node-readiness-controller-scale-test-binary-1000-continuous c3bb1da link true /test pull-node-readiness-controller-scale-test-binary-1000-continuous
pull-node-readiness-controller-lint c3bb1da link true /test pull-node-readiness-controller-lint

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Handle node deletion, label selector unmatching, and status drift in NodeReconciler

3 participants