← Back to Pull requests

Adding Webhook To Handle Snapshot Topology During Scheduling #1497

Open
unknown opened this pull request with 457 lines diff across 5 files
View on GitHub
unknown unknown commented on Oct 02, 2026 13:59 UTC
Author

What type of PR is this?

/kind feature

What this PR does / why we need it:

KEP-5943 records where a snapshot can be restored in VolumeSnapshotContent.spec.nodeAffinity. For Immediate binding, https://github.com/kubernetes-csi/external-provisioner/pull/1552 restricts provisioning to that topology. For WaitForFirstConsumer, the scheduler picks the node before the volume is provisioned, so nothing stops it from choosing a node where the snapshot can't be restored.

This PR adds snapshot-topology-webhook, an opt-in component behind the VolumeSnapshotTopology feature gate:

  • Pod mutating webhook: merges the snapshot topology into the pod's required node affinity at creation. If the topology isn't known yet, it adds a scheduling gate, and a leader-elected controller fills in the affinity and removes the gate once it is.

  • PVC validating webhook: rejects a volume.kubernetes.io/selected-node update to a node that the content's nodeAffinity doesn't allow.
  • Other Options Discarded

  • Implementing Logic in Default Scheduler:

  • - VolumeSnapshot and VolumeSnapshotContent are CRDs owned by external-snapshotter, so in-tree scheduler code can't depend on them.
  • Scheduler Plugin:

  • - This was our initial approach (PR). SIG Scheduling suggested moving the functionality to a SIG Storage-owned repo because they don't have the bandwidth to guarantee its maintenance, and at the Sept 17, 2026 SIG Storage meeting it was agreed this repo is the right place.
  • Webhook over Custom Scheduler:

  • - The webhook works with the default scheduler, so users don't need to deploy a second scheduler or replace the default one, and workloads don't need to set schedulerName.

    Special notes for your reviewer:

    Intentionally left the test files out so that reviewers can focus on the actual code first and not have an even larger diff. Hence the hold on the PR.

    Manual Testing

    Tested manually on a 3-zone kops cluster (Kubernetes 1.36) with the EBS CSI driver, the CRDs, snapshot-controller and csi-snapshotter sidecar built from this branch, cert-manager, and snapshot-topology-webhook (2 replicas, VolumeSnapshotTopology=true):

  • Restored WaitForFirstConsumer PVCs from snapshots with zone-only, region-only and zone+hostname nodeAffinity, both dynamically created and pre-provisioned. Pods landed only on allowed nodes.

  • Checked admission (affinity injected at creation, or the pod gated until the snapshot or PVC is ready) and controller ungating, including merging into existing affinity, the unrepresentable and term-cap fail-open paths, and --gate-timeout.

  • Checked that the selected-node guard denies a disallowed node and allows it after the content is widened, and that content changes reach gated pods but not already-injected ones.

  • Checked feature gate off, preset nodeName, readiness and the SIGTERM drain during a rollout, serving-cert renewal without a restart, --v levels, and the documented uninstall.
  • Does this PR introduce a user-facing change?:
    <!--
    If no, just write "NONE" in the release-note block below.
    If yes, a release note is required:
    Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
    -->
    ``release-note
    Added snapshot-topology-webhook, which keeps pods with WaitForFirstConsumer PVCs restored from a VolumeSnapshot on nodes allowed by the VolumeSnapshotContent's nodeAffinity.
    ``

    Diff: 457 lines (+342 / -115) across 5 files Reviewer: xing-yang Review duration: 43840m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.46) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 457 lines diff across 5 files
    0.46
    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
    Diff Size diff_size
    0.367
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1497"
    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: 45.5% (MEDIUM) · Higher = larger blast radius
    45.5%
    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: 24.3% · Safe to merge
    24.3%