← Back to Pull requests

fix: retry bootstrap completion when the annotation write fails #508

Open
lkhun9311 opened this pull request with 85 lines diff across 4 files
View on GitHub
lkhun9311 lkhun9311 commented on Nov 19, 2026 03:10 UTC
Author

Description

For a bootstrap-only rule, when a node satisfies the conditions and has no rule taint, evaluateRuleForNode only writes the bootstrap-completed annotation through markBootstrapCompleted. That helper logged a failed write and incremented failures_total{reason="AnnotationPatchFailed"}, but returned nothing. The evaluation was recorded as a success, the node was not in failedNodes, and the failure did not itself schedule a retry. If the condition later went unsatisfied, the rule tainted a node that had already bootstrapped.

markBootstrapCompleted now returns the error, and the default branch of evaluateRuleForNode returns it as failed to mark bootstrap completed: .... Both reconcilers already handle an evaluation error: they record the node in failedNodes with reason EvaluationError, increment failures_total{reason="EvaluationError"}, and requeue with backoff, the same as a failed taint patch. The helper's own log line and AnnotationPatchFailed counter, and the deferral when the taint is still present, are unchanged.

Related Issue

Fixes #507

Type of Change

/kind bug

Testing

  • New unit test in node_controller_test.go: a ready, untainted node on a fake client whose patches return Forbidden. evaluateRuleForNode must return the wrapped Forbidden error, record no evaluation, and leave no annotation. Without the change in nodereadinessrule_controller.go it fails with Expected an error to have occurred.

  • Existing calls to markBootstrapCompleted in the tests now check the returned error.

  • make test, make lint (0 issues) and hack/verify-all.sh pass.

  • On a kind cluster with the steps from the issue: with the node patch denied, the node is in failedNodes with failed to mark bootstrap completed: nodes "nrc-gpu-worker" is forbidden .... After the role is restored, a retry writes the annotation, and setting the condition to False leaves the node untainted. On main the same steps leave no annotation and the node gets tainted.
  • Checklist


  • make test passes

  • make lint passes
  • Does this PR introduce a user-facing change?

    ``release-note
    bootstrap-only rules now report a failed bootstrap-completion annotation write in status.failedNodes and requeue the reconcile with backoff. Previously the failure was recorded as a successful evaluation and did not itself schedule another attempt, so a later condition change could taint a node that had already bootstrapped.
    ``

    Generative AI Usage Disclosure


  • No AI tools were used

  • AI tools were used (complete below)
  • How they were used:
    An AI coding agent drafted the fix and the test. I reviewed the change and the test results.

    Diff: 85 lines (+74 / -11) across 4 files Reviewer: Karthik-K-N Review duration: 18118m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.34) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.34 · 85 lines diff across 4 files
    0.34
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 5 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.266
    Real PR Conversation Timeline
    18 items
    netlify[bot] netlify[bot] commented on Nov 19, 2026 03:10 UTC
    Bot

    <span aria-hidden="true">👷</span> Deploy request for node-readiness-controller pending review.


    Visit the deploys page to approve it

    | Name | Link |
    |:-:|------------------------|
    |<span aria-hidden="true">🔨</span> Latest commit | 08c22a875757a021ae4fe521c42ab7c4ecca0f9d |

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Nov 19, 2026 03:10 UTC
    Bot

    [APPROVALNOTIFIER] This PR is NOT APPROVED

    This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/node-readiness-controller/pull/508#" title="Author self-approved">lkhun9311</a>
    Once this PR has been reviewed and has the lgtm label, please assign sergeykanzhelev for approval. For more information see the Code Review Process.

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

    <details open>
    Needs approval from an approver in each of these files:

  • OWNERS
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":["sergeykanzhelev"]} -->

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Nov 19, 2026 03:10 UTC
    Bot

    Welcome @lkhun9311! <br><br>It looks like this is your first PR to <a href='https://github.com/kubernetes-sigs/node-readiness-controller'>kubernetes-sigs/node-readiness-controller</a> 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval. <br><br>You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation. <br><br>You can also check if kubernetes-sigs/node-readiness-controller has its own contribution guidelines. <br><br>You may want to refer to our testing guide if you run into trouble with your tests not passing. <br><br>If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs! <br><br>Thank you, and welcome to Kubernetes. :smiley:

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Nov 19, 2026 03:10 UTC
    Bot

    Hi @lkhun9311. 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.
    </details>

    ajaysundark ajaysundark commented on Nov 19, 2026 05:30 UTC
    Contributor

    looks reasonable to me.

    /cc @Karthik-K-N

    Karthik-K-N Karthik-K-N commented on Nov 19, 2026 07:24 UTC
    Reviewer

    Nice catch, Thanks for the PR
    /lgtm

    lkhun9311 lkhun9311 commented on Nov 20, 2026 13:07 UTC
    Author

    Thanks @Karthik-K-N. @ajaysundark, when you have a moment, could you add ok-to-test and approve if it still looks right to you?

    AnuragThePathak AnuragThePathak commented on code on Nov 21, 2026 15:46 UTC
    Code Review
    internal/controller/node_controller.go:1
    @@ -484,6 +485,7 @@ func (r *RuleReadinessController) markBootstrapCompleted(ctx context.Context, no
     	default:
     		log.V(4).Info("Bootstrap already completed", "node", nodeName, "rule", rule.Name, "uid", rule.GetUID())
     	}
    +	return err

    Why not return the error directly inside err != nil case? That felt more idiomatic to me.

    AnuragThePathak AnuragThePathak commented on code on Nov 21, 2026 15:50 UTC
    Code Review
    internal/controller/nodereadinessrule_controller.go:1
    @@ -503,7 +503,9 @@ func (r *RuleReadinessController) evaluateRuleForNode(ctx context.Context, rule
     			"shouldRemove", shouldRemoveTaint, "hasTaint", currentlyHasTaint)
     		// Mark bootstrap completed in bootstrap-only mode when conditions satisfied even if taint is already absent.
     		if rule.Spec.EnforcementMode == readinessv1alpha1.EnforcementModeBootstrapOnly {
    -			r.markBootstrapCompleted(ctx, node.Name, rule)
    +			if err := r.markBootstrapCompleted(ctx, node.Name, rule); err != nil {
    +				return fmt.Errorf("failed to mark bootstrap completed: %w", err)

    nit: 'bootstrap as completed' is probably what you wanted to write

    AnuragThePathak AnuragThePathak commented on Nov 21, 2026 16:06 UTC
    Reviewer

    rest LGTM to merge.

    lkhun9311 lkhun9311 commented on code on Nov 22, 2026 00:11 UTC
    Code Review
    internal/controller/node_controller.go:1
    @@ -484,6 +485,7 @@ func (r *RuleReadinessController) markBootstrapCompleted(ctx context.Context, no
     	default:
     		log.V(4).Info("Bootstrap already completed", "node", nodeName, "rule", rule.Name, "uid", rule.GetUID())
     	}
    +	return err

    @AnuragThePathak, thanks for the careful review.
    Done in 08c22a8: the err != nil case now returns the error itself, and the function returns nil after the other cases.

    lkhun9311 lkhun9311 commented on code on Nov 22, 2026 00:12 UTC
    Code Review
    internal/controller/nodereadinessrule_controller.go:1
    @@ -503,7 +503,9 @@ func (r *RuleReadinessController) evaluateRuleForNode(ctx context.Context, rule
     			"shouldRemove", shouldRemoveTaint, "hasTaint", currentlyHasTaint)
     		// Mark bootstrap completed in bootstrap-only mode when conditions satisfied even if taint is already absent.
     		if rule.Spec.EnforcementMode == readinessv1alpha1.EnforcementModeBootstrapOnly {
    -			r.markBootstrapCompleted(ctx, node.Name, rule)
    +			if err := r.markBootstrapCompleted(ctx, node.Name, rule); err != nil {
    +				return fmt.Errorf("failed to mark bootstrap completed: %w", err)

    Fixed: the message now reads "failed to mark bootstrap as completed", and the test that checks it is updated.

    AnuragThePathak AnuragThePathak commented on code on Nov 23, 2026 12:10 UTC
    Code Review
    internal/controller/node_controller.go:1
    @@ -484,6 +485,7 @@ func (r *RuleReadinessController) markBootstrapCompleted(ctx context.Context, no
     	default:
     		log.V(4).Info("Bootstrap already completed", "node", nodeName, "rule", rule.Name, "uid", rule.GetUID())
     	}
    +	return err

    LGTM you can mark the conversations as resolved

    lkhun9311 lkhun9311 commented on Nov 26, 2026 12:54 UTC
    Author

    @Karthik-K-N I pushed a small change for @AnuragThePathak's review, and that removed the lgtm. Could you take another look?
    @ajaysundark, an ok-to-test when you have a moment would be great.

    ajaysundark ajaysundark commented on Nov 26, 2026 15:13 UTC
    Contributor

    /ok-to-test

    AnuragThePathak AnuragThePathak commented on Nov 27, 2026 09:27 UTC
    Contributor

    /test pull-node-readiness-controller-verify-all

    AnuragThePathak AnuragThePathak commented on Nov 27, 2026 09:34 UTC
    Contributor

    /lgtm

    Reviewers
    Assignees
    lkhun9311 lkhun9311
    Labels
    risk: low confidence: 87.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 34% (LOW) · Higher = larger blast radius
    34%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.6% · Lower = rushed or shallow review
    87.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.2% · Safe to merge
    4.2%