← Back to Pull requests

feat: enforce non-empty nodeSelector with CEL instead of the webhook #455

Closed
unknown closed this pull request without merging on Sep 19, 2026 18:09 UTC
View on GitHub
unknown unknown commented on Aug 25, 2026 04:12 UTC
Author

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.nodeSelector becomes labels.Everything(), so a rule carrying one taints every Node in the cluster. The only guard was validateSpec in 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 suggested nodeSelector: {} while the webhook forbade it.

The constraint now lives on the CRD:

// +kubebuilder:validation:XValidation:rule="(has(self.matchLabels) && size(self.matchLabels) > 0) || (has(self.matchExpressions) && size(self.matchExpressions) > 0)",message="nodeSelector must not be empty"

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 LabelSelectorAsSelector error check stays. CEL can tell that matchExpressions is 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 nodeSelector is caught by +required, not by this rule, because the field is omitempty,omitzero and 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 asserting spec.nodeSelector: Required value for 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 validation specs drive a real API server through envtest rather than calling the validator directly, since the point is that the API server enforces it now:

  • absent selector, rejected with spec.nodeSelector: Required value

  • selector present but empty, rejected with nodeSelector must not be empty

  • matchLabels: {} present but empty, rejected

  • matchExpressions: [] present but empty, rejected

  • matchLabels set, accepted and persisted

  • matchExpressions only, accepted
  • Full suite: 83 of 83 specs, up from 78. internal/webhook 37 specs green after the three migrated ones were reworked. internal/metrics and the reporter pass. golangci-lint v2.12.1 reports 0 issues and gofmt is clean.

    Checklist


  • make test passes

  • make lint passes
  • Does 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.
    ``

    Diff: 381 lines (+285 / -96) across 4 files Reviewer: Karthik-K-N Review duration: 36837m
    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
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    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.356
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #455"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 43.0% (MEDIUM) · Higher = larger blast radius
    43.0%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 18.6% · Safe to merge
    18.6%