← Back to Pull requests

Add RuleEvaluationSummary to NodeReadinessRule status and CRD #502

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 11, 2026 20:24 UTC
Author

<!-- Thanks for sending a pull request! Here are some tips for you:

  • If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide

  • If you want faster PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews

  • If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests

  • -->

    Description

    Currently the NodeReadinessRule reports the impact of the rule across the cluster through the nodeEvaluations field. For people leveraging prometheus, there are metrics to provide that information numerically. However, there's no numerical representation of that for kubectl users, or someone using tools like Lens. While working on Headlamp also we had this exact requirement and we ended up iterating through the nodeEvaluations array to calculate this information per rule.

    This PR addresses that gap, by introducing an evaluationSummary field in NodeReadinessRule status. The RuleEvaluationSummary struct contains 3 integer fields -

  • Targeted: Total number of nodes in cluster the Rule's NodeSelector matches.

  • Satisfied: Number of nodes that satisfy the rule as per the ConditionPolicy and ConditionRequirements (bootstrap-completed scenario is also considered as satisfied).

  • Unsatisfied: Number of nodes that do not satisfy the rule (opposite of satisfied)
  • Targeted = Satisfied + Unsatisfied

    Also added Kubebuilder printcolumns to display Targeted and Satisfied (priority=1) in kubectl get nrr -o wide.

    This paves a clear pathway for deprecation of nodeEvaluations field in combination with NRE. NRE provides fine-tuned Node level evaluation results, while RuleEvaluationSummary provides rule specific evaluation results statistics. FailedNodes is yet another unaddressed area still.

    Trade-offs considered

    Originally proposed idea in #484, explored around the idea of using nodeEvaluation to calculate the summary on the fly inside processAllNodesForRule and processNodeAgainstAllRules. After that there was another evolution to populate the satisfied and unsatisfied stats from spec directly and using nodeFailure for the failure count. Both these methods had a serious drawback of triggering O(n) loop for every node event and O(n) status write risk for n node events.

    This experience led us to look for references in upstream projects -

  • Kueue style In-Memory Scorecard: This model operates on the idea of O(1) writes in-memory against an event using the concept of a map. Only the value against the impacted key/keys are updated directly instead of having to iterate through the whole workloads (in Kueue). Of course, for writing the update to the CRD status requires handling through separate channel/event setup because if you go to write to Etcd after performing the computation in O(1) in-memory, you will end up with net negative result.

  • Debounced Workqueue Coalescing from CAPI and EndpointSlice: This model accepts the cost of having to iterate through the workload or child resource in O(n) time per evaluation. Instead it aims to minimize the number of evaluation loops by Coalescing multiple events against a parent resource. The actual implementation of EndpointSlice controller involves a few more steps as they have slightly trickier constraints but this core pattern is consistent.
  • Why we went with Debounced Workqueue Coalescing pattern: Our constraints were 5k nodes at max and a humanly manageable number of rules, and it seemed like per node event, it would be highly optimal to map nodes to applicable rules and queue the rules combined with coalescing rules in the queue over a 1-2 second window.
    O(n) node iteration for evaluation is still there but when you limit the frequency and consider the other constraints, it no longer remains the bottleneck rather the etcd API write to update the rule status. This was convincing enough to not to opt for the Kueue style pattern.

    How we adopted it here:

    It was identified that rule reconciler should be in charge of writing to rules. As part of that, the rule reconciler was configured to have a secondary watch on the node resources with appropriate predicates to filter out the noise, then perform node to rule mapping and queue the rules for reconciliation but with TypedDelayingInterface.AddAfter which puts a handbrake on the standard rate at which reconciliation happens and allows duplicate queue items to merge. For now we have resorted to a window of 2 seconds, considering the fact the evaluation summary is meant for human inspection purpose mainly.

    Also because we had to accommodate the change within the existing reconcile method for Rule Reconciler, we used check on Generation != ObservedGeneration to detect whether it is triggered by pre-existing Rule GenerationChangedPredicate event or the new Node events. In case we find the spec has changed (Generation != ObservedGeneration) we follow the existing flow, accompanied by RuleEvaluationSummary computation which ends up in a single status write anyway for the whole updated status. If it's not a Rule GenerationChangedPredicate event, then we compute the RuleEvaluationSummary only and write the status to etcd and complete the reconciliation process. In case of merger of a node event driven reconciliation request and rule GenerationChangedPredicate driven request, the first path is taken and it's intentional only.

    Also it may be worth noting that, we avoid API status write for the summary only path when there's no changes in the counts of any field.

    There is also a new method named nodeSatisfiesRule been added with this PR, which actually may be useful for avoiding duplication of same logic in multiple places.

    Tests that could have been written as pure unit functions and benefit heavily from repetition of same setup are added as go-style unit tests only in separate files, keeping in mind the increasing size of nodereadinessrule_controller_test.go file.

    The original issue, requests for an error count too. However during active development it was observed that errors appear purely from the network failure, RBAC or other kind of infra platform failures while applying/removing taints etc and not anywhere in the process of evaluation of nodes against the rules. That forced us to rely on nodeFailures of the status field. However, technically speaking nodeFailures in the worst case scenario of cluster wide failure can also lead to high memory usage pushing beyond 1.5MiB limit, and also the fact that it can trigger a rule write on each node event, makes it not so suitable field to retain in the long run just like nodeEvaluation. There were some other considerations around possible successor. However the final decision was to exclude error or failure count from initial RuleEvaluationSummary, because first of all the main purpose and name justifies that (because error is actually not associated with evaluation process directly) and to considering the fact that removing an existing field is harder than adding a new one (to not introduce tech debt now by using nodeFailure + to keep choices open for v1alpha2).

    Related Issue


    <!--
    Automatically closes linked issue when PR is merged.
    Usage: Fixes #<issue number>, or Fixes (paste link of issue).

    or

    None
    -->

    Fixes #483

    Type of Change

    <!--
    Add one of the following kinds:
    /kind bug
    /kind cleanup
    /kind documentation
    /kind feature
    /kind design

    Optionally add one or more of the following kinds if applicable:
    /kind api-change
    /kind deprecation
    /kind failing-test
    /kind flake
    /kind regression
    -->
    /kind feature
    /kind api-change

    Testing


    <!-- How was this tested? -->

    Tested with KWOK running the local build.

    <img width="1091" height="352" alt="Screenshot 2026-11-14 at 2 54 31 AM" src="https://github.com/user-attachments/assets/aae15414-fb4b-467b-b23f-20aa53433ad9" />

    <img width="507" height="325" alt="Screenshot 2026-11-14 at 2 56 30 AM" src="https://github.com/user-attachments/assets/23ebf6ae-d458-4362-9cb3-0ae64ef3a329" />

    Checklist


  • make test passes

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

    <!--
    If no, just write "NONE" in the release-note block below.
    If yes, a release note is required:
    1. Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
    2. Add 'Doc #(issue)' after the block if there is a follow up
    For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
    -->

    ``release-note
    Add RuleEvaluationSummary to NodeReadinessStatus, presenting Targeted, Satisfied, and Unsatisfied node count against a Rule.
    ``

    Generative AI Usage Disclosure


    <!--
    If you used AI tools in preparing this PR, please disclose and how they were used.

    Using AI tools to help write your PR is acceptable, but as the author, you are responsible for understanding every change in your contribution.

    Please write the PR description in your words. Do not submit AI-generated summary and analysis and do not leave the first review of AI generated changes to the reviewers, please verify the changes (code review, local testing, etc.) before submitting your PR.

    For more details please review guidelines on responsible Generative AI usage:
    https://www.linuxfoundation.org/legal/generative-ai
    https://www.kubernetes.dev/docs/guide/pull-requests/#ai-guidance

    -->

  • No AI tools were used

  • AI tools were used (complete below)
  • How they were used:*
    <!-- Describe what the AI helped with (e.g., code generation, refactoring, documentation, tests) and which parts of the PR were affected -->
    AI was used to fetch references from upstream projects and other kind of information combined with reference quotation for me to review and understand. Also leveraged it for idea exploration including design options, and bootstrapping of code wherever applicable. Also used for test environment setup with Kwok and more.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: ajaysundark Review duration: 25003m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #502"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 27.7% · Safe to merge
    27.7%