← Back to Pull requests

fix(webhook): honor pod nodeSelector when checking for repeated locality #6281

Open
unknown opened this pull request with 290 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 20, 2026 10:38 UTC
Author

Ⅰ. Describe what this PR does

The NodeAffinityWithCache webhook plugin skips injecting tiered locality affinity when the app pod already sets one of the locality labels itself, either in spec.affinity or in spec.nodeSelector (see docs/en/operation/tiered_locality_schedule.md). hasRepeatedLocality does that check.

In hasRepeatedLocality, when the pod has a nodeAffinity but no required terms, the function returned false immediately. The spec.nodeSelector check at the end of the function was never reached, so a pod that pinned its own locality label with nodeSelector (and had, for example, only a preferred node affinity on another label) still got the locality affinity injected on top. With the required policy that can produce two contradicting requirements (for example rack-b from the nodeSelector and rack-a from the injected affinity) and leave the pod Pending.

This PR only loops over the required terms when there are some and lets the function fall through to the nodeSelector check otherwise. Nothing else changes.

Ⅱ. Does this pull request fix one issue?

Fixes #6280

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

  • TestHasRepeatedLocality: two new cases, "preferred-only affinity on another label and node selector with same label" and "empty node affinity and node selector with same label". Both expect true.

  • TestTieredLocalitySkipMutateWhenPodNodeSelectorHasLocality: runs Mutate for a pod labeled sched: required with a rack nodeSelector and a preferred affinity on an unrelated label, and checks that no required affinity is injected and the preferred terms stay at 1.
  • All three cases fail on master and pass with this change. The other tests in the package still pass.

    Ⅳ. Describe how to verify it

    go test -gcflags=all=-l ./pkg/webhook/plugins/nodeaffinitywithcache/

    Ⅴ. Special notes for reviews

    Pods without a nodeSelector on a locality label, and pods with a required or preferred affinity on a locality label, behave as before. The only behaviour change is for pods that have a nodeAffinity without required terms and a locality label in nodeSelector: the webhook no longer injects locality affinity for them, which is what the docs describe.

    Diff: 290 lines (+217 / -73) across 3 files Reviewer: cheyang Review duration: 3426m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 290 lines diff across 3 files
    0.40
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.339
    Real PR Conversation Timeline
    1 comments
    "Review active on #6281"
    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: 39.9% (MEDIUM) · Higher = larger blast radius
    39.9%
    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: 21.2% · Safe to merge
    21.2%