feat: enforce non-empty nodeSelector with CEL instead of the webhook #455
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.43) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 381 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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
Diff Size
diff_size
0.356
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #455"
general
weight: 0.35
Karthik-K-N
Description
Continues the webhook to CEL migration from #449. This one is outside #451's scope, which covers the two bootstrap-only constraints.
An empty
spec.nodeSelectorbecomeslabels.Everything(), so a rule carrying one taints every Node in the cluster. The only guard wasvalidateSpecin the validating webhook, which is off by default, so a default install had nothing stopping it. #403 came at the same gap from the chart side, where the chart's own error text suggestednodeSelector: {}while the webhook forbade it.The constraint now lives on the CRD:
and the empty check is removed from the webhook rather than left beside it, since CRD validation runs before validating webhooks and the branch is unreachable once the rule is in place.
Two things I deliberately did not change:
The
LabelSelectorAsSelectorerror check stays. CEL can tell thatmatchExpressionsis non-empty but not whether the operator is one the parser accepts, so{key: k, operator: NotARealOperator}still needs Go. The webhook specs that used an empty selector as their invalid input now use an unparseable one instead, so they exercise what the webhook still owns.An absent
nodeSelectoris caught by+required, not by this rule, because the field isomitempty,omitzeroand serialises away so CEL never evaluates. I expected my rule to catch it and it does not, which is why there is a separate spec assertingspec.nodeSelector: Required valuefor that path.After this the only thing left in the webhook is cross-object taint conflict detection, which cannot move to CEL because it has to list other rules.
Related Issue
Fixes #454
Type of Change
/kind feature
/kind api-change
Testing
New
nodeSelector CEL validationspecs drive a real API server through envtest rather than calling the validator directly, since the point is that the API server enforces it now:spec.nodeSelector: Required valuenodeSelector must not be emptymatchLabels: {}present but empty, rejectedmatchExpressions: []present but empty, rejectedmatchLabelsset, accepted and persistedmatchExpressionsonly, acceptedFull suite: 83 of 83 specs, up from 78.
internal/webhook37 specs green after the three migrated ones were reworked.internal/metricsand the reporter pass.golangci-lintv2.12.1 reports 0 issues andgofmtis clean.Checklist
make testpassesmake lintpassesDoes this PR introduce a user-facing change?
``
release-note
``NodeReadinessRule now rejects an empty spec.nodeSelector through CRD validation rather than only through the optional admission webhook, so a rule can no longer be created that silently taints every node on clusters where the webhook is not deployed.