fix(webhook): honor pod nodeSelector when checking for repeated locality #6281
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
cheyang
Ⅰ. Describe what this PR does
The
NodeAffinityWithCachewebhook plugin skips injecting tiered locality affinity when the app pod already sets one of the locality labels itself, either inspec.affinityor inspec.nodeSelector(seedocs/en/operation/tiered_locality_schedule.md).hasRepeatedLocalitydoes that check.In
hasRepeatedLocality, when the pod has anodeAffinitybut no required terms, the function returnedfalseimmediately. Thespec.nodeSelectorcheck at the end of the function was never reached, so a pod that pinned its own locality label withnodeSelector(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
nodeSelectorcheck 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 expecttrue.TestTieredLocalitySkipMutateWhenPodNodeSelectorHasLocality: runsMutatefor a pod labeledsched: requiredwith 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
nodeAffinitywithout required terms and a locality label innodeSelector: the webhook no longer injects locality affinity for them, which is what the docs describe.