← Back to Pull requests

feat!: Add webhook namespace-selector for multi-tenant deployments #3217

Closed
unknown closed this pull request without merging on Oct 13, 2026 18:45 UTC
View on GitHub
unknown unknown commented on Oct 02, 2026 03:15 UTC
Author

<!-- Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, check our contributor guidelines: https://www.kubeflow.org/docs/about/contributing
2. To know more about how to develop with the Spark operator, check the developer guide: https://spark.kubeflow.org/en/latest/contributor-guide/
3. If you want faster PR reviews, check how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
4. Please open an issue to discuss significant work before you start. We appreciate your contributions and don't want your efforts to go to waste!
-->

Purpose of this PR

Follow-up to #2943 / closes #2913. Completes webhook parity with the controller namespace selector from #2808 so multi-tenant Helm installs admit the same namespaces the controller reconciles.

Rebased onto current master and ported to typed admission.Defaulter / admission.Validator (NewWebhookManagedBy(mgr, obj)).

Proposed changes:

  • Webhook --namespace-selector plus process-side filtering (NamespaceFilteringDefaulter / NamespaceFilteringValidator) so mutate/validate use the same namespace matcher as the controller. --label-selector-filter stays so existing webhook args still start.

  • Helm has one knob, spark.jobNamespaceSelector:

  • - Must be an object (matchLabels / matchExpressions). The object drives admission webhook namespaceSelector and is converted to the --namespace-selector flag string for the controller and webhook processes.
    - Breaking change: the previous string form (e.g. "spark=enabled") is no longer accepted. Users must migrate to matchLabels / matchExpressions. The install fails with a clear migration message if a string is supplied.
  • When both a concrete jobNamespaces list and jobNamespaceSelector are set, each webhook is registered twice: one selector for the listed names, and one for the labels that excludes those names, so a namespace is admitted once. That matches the controller OR (listed namespaces or labeled namespaces).

  • Chart tests cover the object form and rejection of the string form.
  • Change Category

    <!-- Indicate the type of change by marking the applicable boxes. -->

  • Bug fix (non-breaking change which fixes an issue)

  • Feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that could affect existing functionality)

  • Documentation update
  • Rationale

    #2808 taught the controller to watch namespaces by label, but webhooks still used only a name-based namespaceSelector. In shared clusters, jobs in label-selected namespaces can reconcile while admission is skipped.

    A single webhook namespaceSelector cannot express "listed namespaces OR labeled namespaces". Two registrations cover that union. The chart value is an object because the webhook needs a LabelSelector; Helm converts that object into the controller/webhook flag string. The reverse (an arbitrary selector string into matchLabels / matchExpressions) is not reliable in Helm, so the string form is removed.

    spark:
      jobNamespaceSelector:
        matchLabels:
          spark: enabled
    

    Checklist

    <!-- Before submitting your PR, please review the following: -->

  • I have conducted a self-review of my own code.

  • I have updated documentation accordingly.

  • I have added tests that prove my changes are effective or that my feature works.

  • Existing unit tests pass locally with my changes.
  • Additional Notes

  • Supersedes / continues #2943 (original work by @kouzant).

  • Local verification: make helm-unittest, go test ./internal/webhook/ -count=1, go test ./test/kustomize/ -count=1.
  • Diff: 464 lines (+348 / -116) across 5 files Reviewer: tariq-hasan Review duration: 16770m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.69) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.69 · 464 lines diff across 5 files
    0.69
    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.367
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.069
    Real PR Conversation Timeline
    1 comments
    "Review active on #3217"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    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: 68.8% (HIGH) · Higher = larger blast radius
    68.8%
    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: 29.8% · Safe to merge
    29.8%