← Back to Pull requests

Add snapshot topology support for Immediate binding (KEP-5943) #1552

Open
mdzraf opened this pull request with 4010 lines diff across 51 files
View on GitHub
mdzraf mdzraf commented on Jul 29, 2026 22:49 UTC
Author

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR introduces the changes necessary in the provisioner to be able to check for Volume Snapshot Topology and see if there is any intersection between the snapshot's NodeAffinity and StorageClass.AllowedTopologies. This functionality is gated behind the VolumeSnapshotTopology feature gate.

This is part of the implementation for https://github.com/kubernetes/enhancements/issues/5943

Special notes for your reviewer:

/hold

As noted in the TODO comment, the current implementation references a custom fork of the external snapshotter and will be switched to the released version of it once the PR to introduce topology for volume snapshots is merged.

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
Introduce VolumeSnapshotTopology Feature Gate Along with Functionality to Check for Topology Intersection
``

Diff: 4010 lines (+3908 / -102) across 51 files Reviewer: xing-yang Review duration: 178069m
All Vouch review confidence checks passed
Residual risk 0.09 = Change Risk (0.79) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.79 · 4010 lines diff across 51 files
0.79
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 5 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
88%
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.400
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
32 items
kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 29, 2026 22:49 UTC
Bot

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: <a href="https://github.com/kubernetes-csi/external-provisioner/pull/1552#" title="Author self-approved">mdzraf</a>
Once this PR has been reviewed and has the lgtm label, please assign xing-yang for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

<details open>
Needs approval from an approver in each of these files:

  • OWNERS
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":["xing-yang"]} -->

    Copilot Copilot commented on code on Jul 31, 2026 15:35 UTC
    Code Review
    pkg/controller/topology.go:1
    @@ -692,6 +692,61 @@ func toCSITopology(terms []topologyTerm) []*csi.Topology {
     	return out
     }
     
    +// intersectSnapshotTopology computes the intersection of the StorageClass's
    +// AllowedTopologies and a snapshot's NodeAffinity (both expressed as
    +// []v1.TopologySelectorTerm), returning the result as CSI Topology terms
    +// suitable for CreateVolumeRequest.AccessibilityRequirements.Preferred /
    +// Requisite.
    +//
    +// Used for Immediate volume binding where there is no
    +// scheduler step to reconcile the snapshot's topology with
    +// the StorageClass.
    +//
    +// Semantics:
    +//   - Each input is an OR of terms; within a term, label expressions are ANDed
    +//     and a label expression's values are ORed. We flatten both inputs to the
    +//     same disjunctive-normal-form (a list of fully-specified topologyTerms),
    +//     then keep the flattened StorageClass terms that are a superset of (i.e.
    +//     satisfy) at least one flattened snapshot term.
    +//   - If the snapshot has no NodeAffinity, the StorageClass terms are returned
    +//     unchanged (no additional constraint from the snapshot).
    +//   - If the StorageClass has no AllowedTopologies, the snapshot terms are
    +//     returned (the snapshot is the only constraint).
    +//   - A nil, empty result means the two constraints are incompatible; callers
    +//     should treat this as a fatal provisioning error.
    +func intersectSnapshotTopology(scTopology, snapTopology []v1.TopologySelectorTerm) []*csi.Topology {
    +	scTerms := flatten(scTopology)
    +	snapTerms := flatten(snapTopology)
    +
    +	if len(snapTerms) == 0 {
    +		return toCSITopology(scTerms)
    +	}
    +	if len(scTerms) == 0 {
    +		return toCSITopology(snapTerms)
    +	}
    +
    +	var intersected []topologyTerm
    +	for _, snapTerm := range snapTerms {
    +		for _, scTerm := range scTerms {
    +			// snapTerm.subset(scTerm) is true when every segment in the
    +			// snapshot term is present in the StorageClass term, i.e. the
    +			// StorageClass term provisions into a topology the snapshot is
    +			// accessible from. Keep the more-specific StorageClass term.
    +			if snapTerm.subset(scTerm) {
    +				intersected = append(intersected, scTerm)
    +			} else if scTerm.subset(snapTerm) {
    +				// The snapshot term is more specific (e.g. SC allows a whole
    +				// region, snapshot pins a zone within it). Keep the snapshot term.
    +				intersected = append(intersected, snapTerm)
    +			}
    +		}
    +	}
    +
    +	slices.SortFunc(intersected, topologyTerm.compare)
    +	intersected = slices.CompactFunc(intersected, slices.Equal)
    +	return toCSITopology(intersected)

    slices.CompactFunc is being passed slices.Equal, but slices.Equal compares two slices (signature func([]E, []E) bool) and does not match CompactFunc’s required element-equality function (func(E, E) bool). This will not compile. Use an element comparator (e.g., based on topologyTerm.compare) when compacting the sorted list.

    Copilot Copilot commented on code on Jul 31, 2026 15:35 UTC
    Code Review
    pkg/controller/topology.go:1
    @@ -692,6 +692,61 @@ func toCSITopology(terms []topologyTerm) []*csi.Topology {
     	return out
     }
     
    +// intersectSnapshotTopology computes the intersection of the StorageClass's
    +// AllowedTopologies and a snapshot's NodeAffinity (both expressed as
    +// []v1.TopologySelectorTerm), returning the result as CSI Topology terms
    +// suitable for CreateVolumeRequest.AccessibilityRequirements.Preferred /
    +// Requisite.
    +//
    +// Used for Immediate volume binding where there is no
    +// scheduler step to reconcile the snapshot's topology with
    +// the StorageClass.
    +//
    +// Semantics:
    +//   - Each input is an OR of terms; within a term, label expressions are ANDed
    +//     and a label expression's values are ORed. We flatten both inputs to the
    +//     same disjunctive-normal-form (a list of fully-specified topologyTerms),
    +//     then keep the flattened StorageClass terms that are a superset of (i.e.
    +//     satisfy) at least one flattened snapshot term.
    +//   - If the snapshot has no NodeAffinity, the StorageClass terms are returned
    +//     unchanged (no additional constraint from the snapshot).
    +//   - If the StorageClass has no AllowedTopologies, the snapshot terms are
    +//     returned (the snapshot is the only constraint).
    +//   - A nil, empty result means the two constraints are incompatible; callers
    +//     should treat this as a fatal provisioning error.

    The comment says a “nil, empty result” signals incompatibility, but this function always returns a non-nil slice (toCSITopology initializes out to an empty slice). Consider updating the doc to only mention an empty result, to match actual behavior and the tests below.

    Copilot Copilot commented on code on Jul 31, 2026 15:35 UTC
    Code Review
    pkg/controller/controller.go:1
    @@ -737,6 +739,19 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
     			return nil, controller.ProvisioningNoChange, fmt.Errorf("error generating accessibility requirements: %v", err)
     		}
     		req.AccessibilityRequirements = requirements
    +
    +		if utilfeature.DefaultFeatureGate.Enabled(features.VolumeSnapshotTopology) &&
    +			rc.snapshot && selectedNodeName == "" && len(snapshotNodeAffinity) > 0 {
    +			intersected := intersectSnapshotTopology(sc.AllowedTopologies, snapshotNodeAffinity)
    +			if len(intersected) == 0 {
    +				return nil, controller.ProvisioningFinished, fmt.Errorf("no compatible topology: snapshot %s NodeAffinity does not intersect StorageClass %s AllowedTopologies, so the volume cannot be provisioned where the snapshot is accessible", dataSource.Name, sc.Name)
    +			}
    +			req.AccessibilityRequirements = &csi.TopologyRequirement{
    +				Requisite: intersected,
    +				Preferred: intersected,
    +			}
    +			klog.V(2).Infof("prepareProvision: constrained snapshot-sourced PVC %s to %d topology terms from the intersection of snapshot NodeAffinity and StorageClass.AllowedTopologies", claim.Name, len(intersected))
    +		}

    The new VolumeSnapshotTopology feature-gated path in prepareProvision (intersecting snapshot NodeAffinity with StorageClass.AllowedTopologies for Immediate binding) doesn’t appear to be covered by existing provisioning tests (e.g., TestProvisionFromSnapshot). There is a unit test for intersectSnapshotTopology, but a controller-level test should assert the CreateVolumeRequest.AccessibilityRequirements are overridden (and that provisioning fails fast on empty intersection) when the feature gate is enabled and selectedNodeName is empty.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Jul 31, 2026 15:35 UTC
    Reviewer

    Pull request overview

    This PR adds alpha-gated support for VolumeSnapshot topology during Immediate volume binding by intersecting a snapshot’s topology constraints with StorageClass.AllowedTopologies, ensuring volumes restored from snapshots are provisioned where the snapshot is accessible (KEP-5943). It also temporarily vendors a fork of the external-snapshotter client to consume the new snapshot topology fields.

    Changes:

  • Introduces the VolumeSnapshotTopology feature gate and wires it into provisioning to constrain CreateVolume accessibility requirements for snapshot-sourced PVCs with Immediate binding.

  • Adds intersectSnapshotTopology logic (plus unit tests) to compute the intersection of snapshot NodeAffinity and StorageClass.AllowedTopologies.

  • Vendors a forked external-snapshotter client containing new API fields (VolumeSnapshotContentSpec.NodeAffinity, VolumeSnapshotClass.AllowedTopologies), and updates module replacement metadata.
  • Reviewed changes

    Copilot reviewed 5 out of 9 changed files in this pull request and generated 3 comments.

    <details>
    <summary>Show a summary per file</summary>

    | File | Description |
    | ---- | ----------- |
    | vendor/modules.txt | Updates vendoring metadata to reflect replacing external-snapshotter client with a fork. |
    | vendor/github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1/zz_generated.deepcopy.go | Updates deepcopy generation for new snapshot API fields. |
    | vendor/github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1/types.go | Adds new alpha topology fields to VolumeSnapshot API types (vendored). |
    | pkg/features/features.go | Adds the VolumeSnapshotTopology feature gate definition and default state. |
    | pkg/controller/topology.go | Implements snapshot/StorageClass topology intersection used for Immediate binding. |
    | pkg/controller/snapshot_topology_test.go | Adds unit tests for intersectSnapshotTopology. |
    | pkg/controller/controller.go | Threads snapshot NodeAffinity from VolumeSnapshotContent into provisioning and applies intersection when the feature gate is enabled. |
    | go.sum | Updates checksums for the forked external-snapshotter client module. |
    | go.mod | Adds a temporary replace to a forked external-snapshotter client pending upstream release. |
    </details>

    ---

    💡 <a href="/kubernetes-csi/external-provisioner/new/master?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.

    xing-yang xing-yang commented on code on Aug 11, 2026 15:20 UTC
    Code Review
    pkg/controller/controller.go:1
    @@ -737,6 +739,19 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
     			return nil, controller.ProvisioningNoChange, fmt.Errorf("error generating accessibility requirements: %v", err)
     		}
     		req.AccessibilityRequirements = requirements
    +
    +		if utilfeature.DefaultFeatureGate.Enabled(features.VolumeSnapshotTopology) &&
    +			rc.snapshot && selectedNodeName == "" && len(snapshotNodeAffinity) > 0 {
    +			intersected := intersectSnapshotTopology(sc.AllowedTopologies, snapshotNodeAffinity)
    +			if len(intersected) == 0 {
    +				return nil, controller.ProvisioningFinished, fmt.Errorf("no compatible topology: snapshot %s NodeAffinity does not intersect StorageClass %s AllowedTopologies, so the volume cannot be provisioned where the snapshot is accessible", dataSource.Name, sc.Name)
    +			}
    +			req.AccessibilityRequirements = &csi.TopologyRequirement{
    +				Requisite: intersected,
    +				Preferred: intersected,
    +			}

    This silently drops all the results generated by GenerateAccessibilityRequirements().

    xing-yang xing-yang commented on code on Aug 11, 2026 15:25 UTC
    Code Review
    pkg/controller/controller.go:1

    This will trigger a reschedule even in cases where the snapshot-topology intersection could have resolved things locally without needing that lookup.

    mdzraf mdzraf commented on code on Sep 01, 2026 20:08 UTC
    Code Review
    pkg/controller/topology.go:1
    @@ -692,6 +692,61 @@ func toCSITopology(terms []topologyTerm) []*csi.Topology {
     	return out
     }
     
    +// intersectSnapshotTopology computes the intersection of the StorageClass's
    +// AllowedTopologies and a snapshot's NodeAffinity (both expressed as
    +// []v1.TopologySelectorTerm), returning the result as CSI Topology terms
    +// suitable for CreateVolumeRequest.AccessibilityRequirements.Preferred /
    +// Requisite.
    +//
    +// Used for Immediate volume binding where there is no
    +// scheduler step to reconcile the snapshot's topology with
    +// the StorageClass.
    +//
    +// Semantics:
    +//   - Each input is an OR of terms; within a term, label expressions are ANDed
    +//     and a label expression's values are ORed. We flatten both inputs to the
    +//     same disjunctive-normal-form (a list of fully-specified topologyTerms),
    +//     then keep the flattened StorageClass terms that are a superset of (i.e.
    +//     satisfy) at least one flattened snapshot term.
    +//   - If the snapshot has no NodeAffinity, the StorageClass terms are returned
    +//     unchanged (no additional constraint from the snapshot).
    +//   - If the StorageClass has no AllowedTopologies, the snapshot terms are
    +//     returned (the snapshot is the only constraint).
    +//   - A nil, empty result means the two constraints are incompatible; callers
    +//     should treat this as a fatal provisioning error.

    Fixed in new rev

    mdzraf mdzraf commented on code on Sep 01, 2026 20:09 UTC
    Code Review
    pkg/controller/controller.go:1
    @@ -737,6 +739,19 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
     			return nil, controller.ProvisioningNoChange, fmt.Errorf("error generating accessibility requirements: %v", err)
     		}
     		req.AccessibilityRequirements = requirements
    +
    +		if utilfeature.DefaultFeatureGate.Enabled(features.VolumeSnapshotTopology) &&
    +			rc.snapshot && selectedNodeName == "" && len(snapshotNodeAffinity) > 0 {
    +			intersected := intersectSnapshotTopology(sc.AllowedTopologies, snapshotNodeAffinity)
    +			if len(intersected) == 0 {
    +				return nil, controller.ProvisioningFinished, fmt.Errorf("no compatible topology: snapshot %s NodeAffinity does not intersect StorageClass %s AllowedTopologies, so the volume cannot be provisioned where the snapshot is accessible", dataSource.Name, sc.Name)
    +			}
    +			req.AccessibilityRequirements = &csi.TopologyRequirement{
    +				Requisite: intersected,
    +				Preferred: intersected,
    +			}
    +			klog.V(2).Infof("prepareProvision: constrained snapshot-sourced PVC %s to %d topology terms from the intersection of snapshot NodeAffinity and StorageClass.AllowedTopologies", claim.Name, len(intersected))
    +		}

    Addressed in new rev by adding TestProvisionFromSnapshotWithTopology tests

    mdzraf mdzraf commented on code on Sep 01, 2026 20:10 UTC
    Code Review
    pkg/controller/controller.go:1
    @@ -737,6 +739,19 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist
     			return nil, controller.ProvisioningNoChange, fmt.Errorf("error generating accessibility requirements: %v", err)
     		}
     		req.AccessibilityRequirements = requirements
    +
    +		if utilfeature.DefaultFeatureGate.Enabled(features.VolumeSnapshotTopology) &&
    +			rc.snapshot && selectedNodeName == "" && len(snapshotNodeAffinity) > 0 {
    +			intersected := intersectSnapshotTopology(sc.AllowedTopologies, snapshotNodeAffinity)
    +			if len(intersected) == 0 {
    +				return nil, controller.ProvisioningFinished, fmt.Errorf("no compatible topology: snapshot %s NodeAffinity does not intersect StorageClass %s AllowedTopologies, so the volume cannot be provisioned where the snapshot is accessible", dataSource.Name, sc.Name)
    +			}
    +			req.AccessibilityRequirements = &csi.TopologyRequirement{
    +				Requisite: intersected,
    +				Preferred: intersected,
    +			}

    Good catch, fixed in new rev, intersection is now fed into GenerateAccessibilityRequirements as its allowedTopologies input, so GenerateAccessibilityRequirements aggregation and preferred-ordering results are preserved and not dropped.

    mdzraf mdzraf commented on code on Sep 01, 2026 20:14 UTC
    Code Review
    pkg/controller/controller.go:1

    In the new rev an empty intersection fails with ProvisioningFinished so we never reach this line for that case. The ProvisioningReschedule here remains the pre-existing path for when GenerateAccessibilityRequirements can't find the node/CSINode object (apierrors.IsNotFound), which is unchanged by this PR.

    Copilot Copilot commented on code on Sep 13, 2026 15:35 UTC
    Code Review
    pkg/controller/topology.go:1
    @@ -692,6 +692,88 @@ func toCSITopology(terms []topologyTerm) []*csi.Topology {
     	return out
     }
     
    +// intersectSnapshotTopology computes the intersection of the StorageClass's
    +// AllowedTopologies and a snapshot's NodeAffinity (both expressed as
    +// []v1.TopologySelectorTerm) and returns it as []v1.TopologySelectorTerm.
    +//
    +// The result is passed as the allowedTopologies argument to
    +// GenerateAccessibilityRequirements for Immediate volume binding, so that the
    +// snapshot's accessible topology is reconciled with the cluster the same way an
    +// explicit StorageClass.AllowedTopologies would be (aggregation, preferred
    +// ordering, etc.) rather than bypassing that logic.
    +//
    +// Semantics:
    +//   - Each input is an OR of terms; within a term, label expressions are ANDed
    +//     and a label expression's values are ORed. We flatten both inputs to the
    +//     same disjunctive-normal-form (a list of fully-specified topologyTerms),
    +//     then for each (StorageClass, snapshot) term pair where one is a subset of
    +//     the other, keep the more-specific term: the StorageClass term when the
    +//     snapshot term is a subset of it, or the snapshot term when it is a subset
    +//     of the StorageClass term (e.g. the StorageClass allows a whole region and
    +//     the snapshot pins a zone within it). Terms are compared by exact
    +//     (key, value) segments; a pair where neither is a subset of the other
    +//     (including disjoint topology keys) contributes nothing, matching how the
    +//     regular volume path treats topology segments as opaque per-driver keys.
    +//   - If the snapshot has no NodeAffinity, the StorageClass terms are returned
    +//     unchanged (no additional constraint from the snapshot).
    +//   - If the StorageClass has no AllowedTopologies, the snapshot terms are
    +//     returned (the snapshot is the only constraint).
    +//   - An empty result means the two constraints are incompatible; callers
    +//     should treat this as a fatal provisioning error.
    +func intersectSnapshotTopology(scTopology, snapTopology []v1.TopologySelectorTerm) []v1.TopologySelectorTerm {
    +	scTerms := flatten(scTopology)
    +	snapTerms := flatten(snapTopology)
    +
    +	if len(snapTerms) == 0 {
    +		return topologyTermsToSelectorTerms(scTerms)
    +	}
    +	if len(scTerms) == 0 {
    +		return topologyTermsToSelectorTerms(snapTerms)
    +	}

    The early checks conflate an empty selector list (no restriction) with a non-empty list containing an empty term (matches no objects; the core API explicitly distinguishes these). Because flatten drops empty terms, a StorageClass of [{}] and a snapshot term such as zone=a incorrectly falls back to zone=a instead of producing an empty intersection, and the reverse case incorrectly falls back to the StorageClass terms. Check the raw input lengths first, then return an empty result when a non-empty input flattens to zero terms.

    Copilot Copilot commented on code on Sep 13, 2026 15:35 UTC
    Code Review
    pkg/controller/topology.go:1
    @@ -692,6 +692,88 @@ func toCSITopology(terms []topologyTerm) []*csi.Topology {
     	return out
     }
     
    +// intersectSnapshotTopology computes the intersection of the StorageClass's
    +// AllowedTopologies and a snapshot's NodeAffinity (both expressed as
    +// []v1.TopologySelectorTerm) and returns it as []v1.TopologySelectorTerm.
    +//
    +// The result is passed as the allowedTopologies argument to
    +// GenerateAccessibilityRequirements for Immediate volume binding, so that the
    +// snapshot's accessible topology is reconciled with the cluster the same way an
    +// explicit StorageClass.AllowedTopologies would be (aggregation, preferred
    +// ordering, etc.) rather than bypassing that logic.
    +//
    +// Semantics:
    +//   - Each input is an OR of terms; within a term, label expressions are ANDed
    +//     and a label expression's values are ORed. We flatten both inputs to the
    +//     same disjunctive-normal-form (a list of fully-specified topologyTerms),
    +//     then for each (StorageClass, snapshot) term pair where one is a subset of
    +//     the other, keep the more-specific term: the StorageClass term when the
    +//     snapshot term is a subset of it, or the snapshot term when it is a subset
    +//     of the StorageClass term (e.g. the StorageClass allows a whole region and
    +//     the snapshot pins a zone within it). Terms are compared by exact
    +//     (key, value) segments; a pair where neither is a subset of the other
    +//     (including disjoint topology keys) contributes nothing, matching how the
    +//     regular volume path treats topology segments as opaque per-driver keys.
    +//   - If the snapshot has no NodeAffinity, the StorageClass terms are returned
    +//     unchanged (no additional constraint from the snapshot).
    +//   - If the StorageClass has no AllowedTopologies, the snapshot terms are
    +//     returned (the snapshot is the only constraint).
    +//   - An empty result means the two constraints are incompatible; callers
    +//     should treat this as a fatal provisioning error.
    +func intersectSnapshotTopology(scTopology, snapTopology []v1.TopologySelectorTerm) []v1.TopologySelectorTerm {
    +	scTerms := flatten(scTopology)
    +	snapTerms := flatten(snapTopology)
    +
    +	if len(snapTerms) == 0 {
    +		return topologyTermsToSelectorTerms(scTerms)
    +	}
    +	if len(scTerms) == 0 {
    +		return topologyTermsToSelectorTerms(snapTerms)
    +	}
    +
    +	var intersected []topologyTerm
    +	for _, snapTerm := range snapTerms {
    +		for _, scTerm := range scTerms {
    +			// snapTerm.subset(scTerm) is true when every segment in the
    +			// snapshot term is present in the StorageClass term, i.e. the
    +			// StorageClass term provisions into a topology the snapshot is
    +			// accessible from. Keep the more-specific StorageClass term.
    +			if snapTerm.subset(scTerm) {
    +				intersected = append(intersected, scTerm)
    +			} else if scTerm.subset(snapTerm) {
    +				// The snapshot term is more specific (e.g. SC allows a whole
    +				// region, snapshot pins a zone within it). Keep the snapshot term.
    +				intersected = append(intersected, snapTerm)
    +			}
    +		}
    +	}

    This only keeps a pair when one flattened term is a subset of the other, but topology selector requirements are ANDed by key. Terms such as StorageClass {region=us-west-2} and snapshot {zone=us-west-2a} are compatible on nodes carrying both labels even though neither is a subset, so this code returns an empty intersection and permanently rejects a valid restore. Merge non-conflicting segments and reject only same-key/different-value pairs; please add a test for partially overlapping keys.

    Copilot Copilot commented on code on Sep 13, 2026 15:35 UTC
    Code Review
    pkg/controller/snapshot_topology_test.go:1
    @@ -0,0 +1,133 @@
    +/*
    +Copyright 2026 The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package controller
    +
    +import (
    +	"testing"
    +
    +	"github.com/google/go-cmp/cmp"
    +	v1 "k8s.io/api/core/v1"
    +)
    +
    +const (
    +	snapRegionKey = "topology.kubernetes.io/region"
    +	snapZoneKey   = "topology.kubernetes.io/zone"
    +)
    +
    +func zoneTerm(values ...string) v1.TopologySelectorTerm {
    +	return v1.TopologySelectorTerm{
    +		MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +			{Key: snapZoneKey, Values: values},
    +		},
    +	}
    +}
    +
    +// singleZoneTerm builds a term with one single-value zone expression, matching
    +// the flattened shape intersectSnapshotTopology returns.
    +func singleZoneTerm(value string) v1.TopologySelectorTerm {
    +	return zoneTerm(value)
    +}
    +
    +// TestIntersectSnapshotTopology covers the Immediate-binding intersection of
    +// StorageClass.AllowedTopologies with a snapshot's NodeAffinity (KEP-5943).
    +// The result is a flattened []v1.TopologySelectorTerm (one single-value
    +// expression per key) suitable to pass to GenerateAccessibilityRequirements.
    +func TestIntersectSnapshotTopology(t *testing.T) {
    +	testcases := map[string]struct {
    +		scTopology   []v1.TopologySelectorTerm
    +		snapTopology []v1.TopologySelectorTerm
    +		expected     []v1.TopologySelectorTerm
    +	}{
    +		"no snapshot topology falls back to StorageClass terms": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: nil,
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"no StorageClass topology falls back to snapshot terms": {
    +			scTopology:   nil,
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2c"),
    +			},
    +		},
    +		"overlapping zones intersect to the common subset": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2b", "us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"identical single zone": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +			},
    +		},
    +		"disjoint zones yield empty intersection": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2d")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b", "us-west-2c")},
    +			expected:     nil,
    +		},
    +		"snapshot zone within StorageClass region keeps the more specific snapshot term": {
    +			scTopology: []v1.TopologySelectorTerm{{
    +				MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +					{Key: snapRegionKey, Values: []string{"us-west-2"}},
    +				},
    +			}},
    +			snapTopology: []v1.TopologySelectorTerm{{
    +				MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +					{Key: snapRegionKey, Values: []string{"us-west-2"}},
    +					{Key: snapZoneKey, Values: []string{"us-west-2a"}},
    +				},
    +			}},
    +			// Segments are sorted by key within a flattened term: region, then zone.
    +			expected: []v1.TopologySelectorTerm{{
    +				MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +					{Key: snapRegionKey, Values: []string{"us-west-2"}},
    +					{Key: snapZoneKey, Values: []string{"us-west-2a"}},
    +				},
    +			}},
    +		},
    +	}
    +
    +	for name, tc := range testcases {
    +		t.Run(name, func(t *testing.T) {
    +			got := intersectSnapshotTopology(tc.scTopology, tc.snapTopology)
    +			if !cmp.Equal(got, tc.expected) {
    +				t.Errorf("intersectSnapshotTopology() mismatch (-got +want):\n%s",
    +					cmp.Diff(got, tc.expected))
    +			}
    +		})
    +	}
    +}
    +
    +// TestIntersectSnapshotTopologyEmptyIsFatalSignal documents that an empty (but
    +// non-nil) result is the signal callers use to fail provisioning fast when the
    +// snapshot and StorageClass topologies are incompatible.

    The result is not necessarily non-nil: topologyTermsToSelectorTerms returns nil when there are no terms, so this test description contradicts the implementation. Remove “but non-nil” to keep the documented fatal signal accurate.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 13, 2026 15:35 UTC
    Reviewer

    🟡 Changes recommended

    Topology intersection issues can reject valid restores and mishandle empty selector terms.

    Get a fresh assessment by requesting another Copilot review.

    <details>
    <summary>Review details</summary>

    Suppressed comments (1)

    pkg/features/features.go:63

  • The new alpha feature gate is user-facing, but the README Feature status table lists the existing CrossNamespaceVolumeDataSource alpha gate and then says all other features are GA. Add VolumeSnapshotTopology and its enablement flag to keep the branch documentation accurate and tell users how to opt in.

  • 	VolumeSnapshotTopology featuregate.Feature = "VolumeSnapshotTopology"
    

  • Files reviewed: 6/10 changed files

  • Comments generated: 3

  • Review effort level: Lite

  • </details>

    jsafrane jsafrane commented on code on Sep 16, 2026 12:12 UTC
    Code Review
    pkg/controller/snapshot_topology_test.go:1
    @@ -0,0 +1,133 @@
    +/*
    +Copyright 2026 The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package controller
    +
    +import (
    +	"testing"
    +
    +	"github.com/google/go-cmp/cmp"
    +	v1 "k8s.io/api/core/v1"
    +)
    +
    +const (
    +	snapRegionKey = "topology.kubernetes.io/region"
    +	snapZoneKey   = "topology.kubernetes.io/zone"
    +)
    +
    +func zoneTerm(values ...string) v1.TopologySelectorTerm {
    +	return v1.TopologySelectorTerm{
    +		MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +			{Key: snapZoneKey, Values: values},
    +		},
    +	}
    +}
    +
    +// singleZoneTerm builds a term with one single-value zone expression, matching
    +// the flattened shape intersectSnapshotTopology returns.
    +func singleZoneTerm(value string) v1.TopologySelectorTerm {
    +	return zoneTerm(value)
    +}
    +
    +// TestIntersectSnapshotTopology covers the Immediate-binding intersection of
    +// StorageClass.AllowedTopologies with a snapshot's NodeAffinity (KEP-5943).
    +// The result is a flattened []v1.TopologySelectorTerm (one single-value
    +// expression per key) suitable to pass to GenerateAccessibilityRequirements.
    +func TestIntersectSnapshotTopology(t *testing.T) {
    +	testcases := map[string]struct {
    +		scTopology   []v1.TopologySelectorTerm
    +		snapTopology []v1.TopologySelectorTerm
    +		expected     []v1.TopologySelectorTerm
    +	}{
    +		"no snapshot topology falls back to StorageClass terms": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: nil,
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"no StorageClass topology falls back to snapshot terms": {
    +			scTopology:   nil,
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2c"),
    +			},
    +		},
    +		"overlapping zones intersect to the common subset": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2b", "us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"identical single zone": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +			},
    +		},
    +		"disjoint zones yield empty intersection": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2d")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b", "us-west-2c")},
    +			expected:     nil,
    +		},
    +		"snapshot zone within StorageClass region keeps the more specific snapshot term": {

    Add a test with disjunct topology:
    SC wants: zone: us-east-2a (user explicitly wants just a single zone)
    snapshot wants: region: us-east-2 (the snapshots are regional)

    The final topology should require both - region: us-east-2 && zone: us-east-2a.

    jsafrane jsafrane commented on code on Sep 16, 2026 12:14 UTC
    Code Review
    pkg/controller/snapshot_topology_test.go:1
    @@ -0,0 +1,133 @@
    +/*
    +Copyright 2026 The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package controller
    +
    +import (
    +	"testing"
    +
    +	"github.com/google/go-cmp/cmp"
    +	v1 "k8s.io/api/core/v1"
    +)
    +
    +const (
    +	snapRegionKey = "topology.kubernetes.io/region"
    +	snapZoneKey   = "topology.kubernetes.io/zone"
    +)
    +
    +func zoneTerm(values ...string) v1.TopologySelectorTerm {
    +	return v1.TopologySelectorTerm{
    +		MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +			{Key: snapZoneKey, Values: values},
    +		},
    +	}
    +}
    +
    +// singleZoneTerm builds a term with one single-value zone expression, matching
    +// the flattened shape intersectSnapshotTopology returns.
    +func singleZoneTerm(value string) v1.TopologySelectorTerm {
    +	return zoneTerm(value)
    +}
    +
    +// TestIntersectSnapshotTopology covers the Immediate-binding intersection of
    +// StorageClass.AllowedTopologies with a snapshot's NodeAffinity (KEP-5943).
    +// The result is a flattened []v1.TopologySelectorTerm (one single-value
    +// expression per key) suitable to pass to GenerateAccessibilityRequirements.
    +func TestIntersectSnapshotTopology(t *testing.T) {
    +	testcases := map[string]struct {
    +		scTopology   []v1.TopologySelectorTerm
    +		snapTopology []v1.TopologySelectorTerm
    +		expected     []v1.TopologySelectorTerm
    +	}{
    +		"no snapshot topology falls back to StorageClass terms": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: nil,
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"no StorageClass topology falls back to snapshot terms": {
    +			scTopology:   nil,
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2c"),
    +			},
    +		},
    +		"overlapping zones intersect to the common subset": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2b", "us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"identical single zone": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +			},
    +		},
    +		"disjoint zones yield empty intersection": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2d")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b", "us-west-2c")},
    +			expected:     nil,
    +		},
    +		"snapshot zone within StorageClass region keeps the more specific snapshot term": {

    Add a test with "impossible" topology.
    SC wants: zone: us-west-1c (user explicitly wants just a single zone)
    snapshot wants: region: us-east-2 (the snapshots are regional)

    The external provisioner should merge them in the same way as above - region: us-west-1c && zone: us-east-2a, because it has no knowledge about the real topology. It's IMO the driver's job to reject it.

    jsafrane jsafrane commented on code on Sep 16, 2026 12:15 UTC
    Code Review
    pkg/controller/topology.go:1
    @@ -692,6 +692,88 @@ func toCSITopology(terms []topologyTerm) []*csi.Topology {
     	return out
     }
     
    +// intersectSnapshotTopology computes the intersection of the StorageClass's
    +// AllowedTopologies and a snapshot's NodeAffinity (both expressed as
    +// []v1.TopologySelectorTerm) and returns it as []v1.TopologySelectorTerm.
    +//
    +// The result is passed as the allowedTopologies argument to
    +// GenerateAccessibilityRequirements for Immediate volume binding, so that the
    +// snapshot's accessible topology is reconciled with the cluster the same way an
    +// explicit StorageClass.AllowedTopologies would be (aggregation, preferred
    +// ordering, etc.) rather than bypassing that logic.
    +//
    +// Semantics:
    +//   - Each input is an OR of terms; within a term, label expressions are ANDed
    +//     and a label expression's values are ORed. We flatten both inputs to the
    +//     same disjunctive-normal-form (a list of fully-specified topologyTerms),
    +//     then for each (StorageClass, snapshot) term pair where one is a subset of
    +//     the other, keep the more-specific term: the StorageClass term when the
    +//     snapshot term is a subset of it, or the snapshot term when it is a subset
    +//     of the StorageClass term (e.g. the StorageClass allows a whole region and
    +//     the snapshot pins a zone within it). Terms are compared by exact
    +//     (key, value) segments; a pair where neither is a subset of the other
    +//     (including disjoint topology keys) contributes nothing, matching how the
    +//     regular volume path treats topology segments as opaque per-driver keys.
    +//   - If the snapshot has no NodeAffinity, the StorageClass terms are returned
    +//     unchanged (no additional constraint from the snapshot).
    +//   - If the StorageClass has no AllowedTopologies, the snapshot terms are
    +//     returned (the snapshot is the only constraint).
    +//   - An empty result means the two constraints are incompatible; callers
    +//     should treat this as a fatal provisioning error.
    +func intersectSnapshotTopology(scTopology, snapTopology []v1.TopologySelectorTerm) []v1.TopologySelectorTerm {
    +	scTerms := flatten(scTopology)
    +	snapTerms := flatten(snapTopology)
    +
    +	if len(snapTerms) == 0 {
    +		return topologyTermsToSelectorTerms(scTerms)
    +	}
    +	if len(scTerms) == 0 {
    +		return topologyTermsToSelectorTerms(snapTerms)
    +	}

    This looks like a valid comment to me.

    jsafrane jsafrane commented on code on Sep 16, 2026 12:15 UTC
    Code Review
    pkg/controller/topology.go:1
    @@ -692,6 +692,88 @@ func toCSITopology(terms []topologyTerm) []*csi.Topology {
     	return out
     }
     
    +// intersectSnapshotTopology computes the intersection of the StorageClass's
    +// AllowedTopologies and a snapshot's NodeAffinity (both expressed as
    +// []v1.TopologySelectorTerm) and returns it as []v1.TopologySelectorTerm.
    +//
    +// The result is passed as the allowedTopologies argument to
    +// GenerateAccessibilityRequirements for Immediate volume binding, so that the
    +// snapshot's accessible topology is reconciled with the cluster the same way an
    +// explicit StorageClass.AllowedTopologies would be (aggregation, preferred
    +// ordering, etc.) rather than bypassing that logic.
    +//
    +// Semantics:
    +//   - Each input is an OR of terms; within a term, label expressions are ANDed
    +//     and a label expression's values are ORed. We flatten both inputs to the
    +//     same disjunctive-normal-form (a list of fully-specified topologyTerms),
    +//     then for each (StorageClass, snapshot) term pair where one is a subset of
    +//     the other, keep the more-specific term: the StorageClass term when the
    +//     snapshot term is a subset of it, or the snapshot term when it is a subset
    +//     of the StorageClass term (e.g. the StorageClass allows a whole region and
    +//     the snapshot pins a zone within it). Terms are compared by exact
    +//     (key, value) segments; a pair where neither is a subset of the other
    +//     (including disjoint topology keys) contributes nothing, matching how the
    +//     regular volume path treats topology segments as opaque per-driver keys.
    +//   - If the snapshot has no NodeAffinity, the StorageClass terms are returned
    +//     unchanged (no additional constraint from the snapshot).
    +//   - If the StorageClass has no AllowedTopologies, the snapshot terms are
    +//     returned (the snapshot is the only constraint).
    +//   - An empty result means the two constraints are incompatible; callers
    +//     should treat this as a fatal provisioning error.
    +func intersectSnapshotTopology(scTopology, snapTopology []v1.TopologySelectorTerm) []v1.TopologySelectorTerm {
    +	scTerms := flatten(scTopology)
    +	snapTerms := flatten(snapTopology)
    +
    +	if len(snapTerms) == 0 {
    +		return topologyTermsToSelectorTerms(scTerms)
    +	}
    +	if len(scTerms) == 0 {
    +		return topologyTermsToSelectorTerms(snapTerms)
    +	}
    +
    +	var intersected []topologyTerm
    +	for _, snapTerm := range snapTerms {
    +		for _, scTerm := range scTerms {
    +			// snapTerm.subset(scTerm) is true when every segment in the
    +			// snapshot term is present in the StorageClass term, i.e. the
    +			// StorageClass term provisions into a topology the snapshot is
    +			// accessible from. Keep the more-specific StorageClass term.
    +			if snapTerm.subset(scTerm) {
    +				intersected = append(intersected, scTerm)
    +			} else if scTerm.subset(snapTerm) {
    +				// The snapshot term is more specific (e.g. SC allows a whole
    +				// region, snapshot pins a zone within it). Keep the snapshot term.
    +				intersected = append(intersected, snapTerm)
    +			}
    +		}
    +	}

    Again, pretty good catch

    jsafrane jsafrane commented on code on Sep 16, 2026 12:15 UTC
    Code Review
    pkg/controller/snapshot_topology_test.go:1
    @@ -0,0 +1,133 @@
    +/*
    +Copyright 2026 The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package controller
    +
    +import (
    +	"testing"
    +
    +	"github.com/google/go-cmp/cmp"
    +	v1 "k8s.io/api/core/v1"
    +)
    +
    +const (
    +	snapRegionKey = "topology.kubernetes.io/region"
    +	snapZoneKey   = "topology.kubernetes.io/zone"
    +)
    +
    +func zoneTerm(values ...string) v1.TopologySelectorTerm {
    +	return v1.TopologySelectorTerm{
    +		MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +			{Key: snapZoneKey, Values: values},
    +		},
    +	}
    +}
    +
    +// singleZoneTerm builds a term with one single-value zone expression, matching
    +// the flattened shape intersectSnapshotTopology returns.
    +func singleZoneTerm(value string) v1.TopologySelectorTerm {
    +	return zoneTerm(value)
    +}
    +
    +// TestIntersectSnapshotTopology covers the Immediate-binding intersection of
    +// StorageClass.AllowedTopologies with a snapshot's NodeAffinity (KEP-5943).
    +// The result is a flattened []v1.TopologySelectorTerm (one single-value
    +// expression per key) suitable to pass to GenerateAccessibilityRequirements.
    +func TestIntersectSnapshotTopology(t *testing.T) {
    +	testcases := map[string]struct {
    +		scTopology   []v1.TopologySelectorTerm
    +		snapTopology []v1.TopologySelectorTerm
    +		expected     []v1.TopologySelectorTerm
    +	}{
    +		"no snapshot topology falls back to StorageClass terms": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: nil,
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"no StorageClass topology falls back to snapshot terms": {
    +			scTopology:   nil,
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2c"),
    +			},
    +		},
    +		"overlapping zones intersect to the common subset": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2b", "us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"identical single zone": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +			},
    +		},
    +		"disjoint zones yield empty intersection": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2d")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b", "us-west-2c")},
    +			expected:     nil,
    +		},
    +		"snapshot zone within StorageClass region keeps the more specific snapshot term": {
    +			scTopology: []v1.TopologySelectorTerm{{
    +				MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +					{Key: snapRegionKey, Values: []string{"us-west-2"}},
    +				},
    +			}},
    +			snapTopology: []v1.TopologySelectorTerm{{
    +				MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +					{Key: snapRegionKey, Values: []string{"us-west-2"}},
    +					{Key: snapZoneKey, Values: []string{"us-west-2a"}},
    +				},
    +			}},
    +			// Segments are sorted by key within a flattened term: region, then zone.
    +			expected: []v1.TopologySelectorTerm{{
    +				MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +					{Key: snapRegionKey, Values: []string{"us-west-2"}},
    +					{Key: snapZoneKey, Values: []string{"us-west-2a"}},
    +				},
    +			}},
    +		},
    +	}
    +
    +	for name, tc := range testcases {
    +		t.Run(name, func(t *testing.T) {
    +			got := intersectSnapshotTopology(tc.scTopology, tc.snapTopology)
    +			if !cmp.Equal(got, tc.expected) {
    +				t.Errorf("intersectSnapshotTopology() mismatch (-got +want):\n%s",
    +					cmp.Diff(got, tc.expected))
    +			}
    +		})
    +	}
    +}
    +
    +// TestIntersectSnapshotTopologyEmptyIsFatalSignal documents that an empty (but
    +// non-nil) result is the signal callers use to fail provisioning fast when the
    +// snapshot and StorageClass topologies are incompatible.

    It's maybe valid, but much less concerning than the two AI comments above.

    mdzraf mdzraf commented on code on Sep 21, 2026 13:25 UTC
    Code Review
    pkg/controller/snapshot_topology_test.go:1
    @@ -0,0 +1,133 @@
    +/*
    +Copyright 2026 The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package controller
    +
    +import (
    +	"testing"
    +
    +	"github.com/google/go-cmp/cmp"
    +	v1 "k8s.io/api/core/v1"
    +)
    +
    +const (
    +	snapRegionKey = "topology.kubernetes.io/region"
    +	snapZoneKey   = "topology.kubernetes.io/zone"
    +)
    +
    +func zoneTerm(values ...string) v1.TopologySelectorTerm {
    +	return v1.TopologySelectorTerm{
    +		MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +			{Key: snapZoneKey, Values: values},
    +		},
    +	}
    +}
    +
    +// singleZoneTerm builds a term with one single-value zone expression, matching
    +// the flattened shape intersectSnapshotTopology returns.
    +func singleZoneTerm(value string) v1.TopologySelectorTerm {
    +	return zoneTerm(value)
    +}
    +
    +// TestIntersectSnapshotTopology covers the Immediate-binding intersection of
    +// StorageClass.AllowedTopologies with a snapshot's NodeAffinity (KEP-5943).
    +// The result is a flattened []v1.TopologySelectorTerm (one single-value
    +// expression per key) suitable to pass to GenerateAccessibilityRequirements.
    +func TestIntersectSnapshotTopology(t *testing.T) {
    +	testcases := map[string]struct {
    +		scTopology   []v1.TopologySelectorTerm
    +		snapTopology []v1.TopologySelectorTerm
    +		expected     []v1.TopologySelectorTerm
    +	}{
    +		"no snapshot topology falls back to StorageClass terms": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: nil,
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"no StorageClass topology falls back to snapshot terms": {
    +			scTopology:   nil,
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2c"),
    +			},
    +		},
    +		"overlapping zones intersect to the common subset": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2b", "us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"identical single zone": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +			},
    +		},
    +		"disjoint zones yield empty intersection": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2d")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b", "us-west-2c")},
    +			expected:     nil,
    +		},
    +		"snapshot zone within StorageClass region keeps the more specific snapshot term": {

    Added in new rev ✅

    mdzraf mdzraf commented on code on Sep 21, 2026 13:25 UTC
    Code Review
    pkg/controller/snapshot_topology_test.go:1
    @@ -0,0 +1,133 @@
    +/*
    +Copyright 2026 The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package controller
    +
    +import (
    +	"testing"
    +
    +	"github.com/google/go-cmp/cmp"
    +	v1 "k8s.io/api/core/v1"
    +)
    +
    +const (
    +	snapRegionKey = "topology.kubernetes.io/region"
    +	snapZoneKey   = "topology.kubernetes.io/zone"
    +)
    +
    +func zoneTerm(values ...string) v1.TopologySelectorTerm {
    +	return v1.TopologySelectorTerm{
    +		MatchLabelExpressions: []v1.TopologySelectorLabelRequirement{
    +			{Key: snapZoneKey, Values: values},
    +		},
    +	}
    +}
    +
    +// singleZoneTerm builds a term with one single-value zone expression, matching
    +// the flattened shape intersectSnapshotTopology returns.
    +func singleZoneTerm(value string) v1.TopologySelectorTerm {
    +	return zoneTerm(value)
    +}
    +
    +// TestIntersectSnapshotTopology covers the Immediate-binding intersection of
    +// StorageClass.AllowedTopologies with a snapshot's NodeAffinity (KEP-5943).
    +// The result is a flattened []v1.TopologySelectorTerm (one single-value
    +// expression per key) suitable to pass to GenerateAccessibilityRequirements.
    +func TestIntersectSnapshotTopology(t *testing.T) {
    +	testcases := map[string]struct {
    +		scTopology   []v1.TopologySelectorTerm
    +		snapTopology []v1.TopologySelectorTerm
    +		expected     []v1.TopologySelectorTerm
    +	}{
    +		"no snapshot topology falls back to StorageClass terms": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: nil,
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"no StorageClass topology falls back to snapshot terms": {
    +			scTopology:   nil,
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2c"),
    +			},
    +		},
    +		"overlapping zones intersect to the common subset": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2b", "us-west-2c")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2b"),
    +			},
    +		},
    +		"identical single zone": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a")},
    +			expected: []v1.TopologySelectorTerm{
    +				singleZoneTerm("us-west-2a"),
    +			},
    +		},
    +		"disjoint zones yield empty intersection": {
    +			scTopology:   []v1.TopologySelectorTerm{zoneTerm("us-west-2d")},
    +			snapTopology: []v1.TopologySelectorTerm{zoneTerm("us-west-2a", "us-west-2b", "us-west-2c")},
    +			expected:     nil,
    +		},
    +		"snapshot zone within StorageClass region keeps the more specific snapshot term": {

    Added in new rev ✅

    mdzraf mdzraf commented on Sep 21, 2026 14:11 UTC
    Author

    /retest

    xing-yang xing-yang commented on code on Sep 26, 2026 03:39 UTC
    Code Review
    pkg/controller/controller.go:1
    @@ -1627,17 +1664,45 @@ func (p *csiProvisioner) checkNode(ctx context.Context, claim *v1.PersistentVolu
     				return false, err
     			}
     		}
    -		if sc.VolumeBindingMode == nil ||
    -			*sc.VolumeBindingMode != storagev1.VolumeBindingImmediate ||
    -			!p.nodeDeployment.ImmediateBinding {
    +		if !isImmediateBinding(sc) || !p.nodeDeployment.ImmediateBinding {
     			return false, nil
     		}
     
    -		// If the storage class has AllowedTopologies set, then
    -		// it must match our own. We can find out by trying to
    -		// create accessibility requirements.  If that fails,
    -		// we should not become the owner.
    -		if len(sc.AllowedTopologies) > 0 && p.supportsTopology() {
    +		// The StorageClass topology, plus snapshot topology for Immediate
    +		// snapshot restores, must match this node before it can become owner.
    +		allowedTopologies := sc.AllowedTopologies
    +		if p.supportsTopology() &&
    +			utilfeature.DefaultFeatureGate.Enabled(features.VolumeSnapshotTopology) {
    +			dataSource, err := p.dataSource(ctx, claim)
    +			if err != nil {
    +				if logger.Enabled() {
    +					logger.Infof("%s: deferring snapshot topology check for PVC %s/%s until provisioning: %v", caller, claim.Namespace, claim.Name, err)
    +				}
    +			} else if dataSource != nil &&
    +				dataSource.Kind == snapshotKind &&
    +				dataSource.APIVersion == snapshotAPIGroup &&
    +				p.snapshotClient != nil &&
    +				p.controllerCapabilities[csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT] {
    +				_, snapshotNodeAffinity, err := p.getSnapshotSource(ctx, claim, sc, dataSource)

    checkNode is called frequently. Can you use VolumeSnapshot and VolumeSnapshotContent listers instead of calling getSnapshotSource() which gets them from the API server?

    xing-yang xing-yang commented on code on Sep 26, 2026 03:42 UTC
    Code Review
    vendor/modules.txt:1
    @@ -1667,3 +1659,4 @@ sigs.k8s.io/yaml
     # k8s.io/cri-streaming => k8s.io/cri-streaming v0.36.1
     # k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.36.1
     # k8s.io/streaming => k8s.io/streaming v0.36.1
    +# github.com/kubernetes-csi/external-snapshotter/client/v8 => github.com/mdzraf/external-snapshotter/client/v8 v8.4.1-0.20260730192112-9610545fc807

    I suppose we can't merge this before the snapshotter PR.

    mdzraf mdzraf commented on code on Sep 28, 2026 01:35 UTC
    Code Review
    vendor/modules.txt:1
    @@ -1667,3 +1659,4 @@ sigs.k8s.io/yaml
     # k8s.io/cri-streaming => k8s.io/cri-streaming v0.36.1
     # k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.36.1
     # k8s.io/streaming => k8s.io/streaming v0.36.1
    +# github.com/kubernetes-csi/external-snapshotter/client/v8 => github.com/mdzraf/external-snapshotter/client/v8 v8.4.1-0.20260730192112-9610545fc807

    Yes, that is why I have the hold on this one

    mdzraf mdzraf commented on code on Sep 28, 2026 01:40 UTC
    Code Review
    pkg/controller/controller.go:1
    @@ -1627,17 +1664,45 @@ func (p *csiProvisioner) checkNode(ctx context.Context, claim *v1.PersistentVolu
     				return false, err
     			}
     		}
    -		if sc.VolumeBindingMode == nil ||
    -			*sc.VolumeBindingMode != storagev1.VolumeBindingImmediate ||
    -			!p.nodeDeployment.ImmediateBinding {
    +		if !isImmediateBinding(sc) || !p.nodeDeployment.ImmediateBinding {
     			return false, nil
     		}
     
    -		// If the storage class has AllowedTopologies set, then
    -		// it must match our own. We can find out by trying to
    -		// create accessibility requirements.  If that fails,
    -		// we should not become the owner.
    -		if len(sc.AllowedTopologies) > 0 && p.supportsTopology() {
    +		// The StorageClass topology, plus snapshot topology for Immediate
    +		// snapshot restores, must match this node before it can become owner.
    +		allowedTopologies := sc.AllowedTopologies
    +		if p.supportsTopology() &&
    +			utilfeature.DefaultFeatureGate.Enabled(features.VolumeSnapshotTopology) {
    +			dataSource, err := p.dataSource(ctx, claim)
    +			if err != nil {
    +				if logger.Enabled() {
    +					logger.Infof("%s: deferring snapshot topology check for PVC %s/%s until provisioning: %v", caller, claim.Namespace, claim.Name, err)
    +				}
    +			} else if dataSource != nil &&
    +				dataSource.Kind == snapshotKind &&
    +				dataSource.APIVersion == snapshotAPIGroup &&
    +				p.snapshotClient != nil &&
    +				p.controllerCapabilities[csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT] {
    +				_, snapshotNodeAffinity, err := p.getSnapshotSource(ctx, claim, sc, dataSource)

    Sure, going to swap for listers and have that in the next rev, leaving this thread open until that rev is out.

    mdzraf mdzraf commented on Sep 28, 2026 18:12 UTC
    Author

    /retest

    mdzraf mdzraf commented on code on Sep 28, 2026 19:23 UTC
    Code Review
    pkg/controller/controller.go:1
    @@ -1627,17 +1664,45 @@ func (p *csiProvisioner) checkNode(ctx context.Context, claim *v1.PersistentVolu
     				return false, err
     			}
     		}
    -		if sc.VolumeBindingMode == nil ||
    -			*sc.VolumeBindingMode != storagev1.VolumeBindingImmediate ||
    -			!p.nodeDeployment.ImmediateBinding {
    +		if !isImmediateBinding(sc) || !p.nodeDeployment.ImmediateBinding {
     			return false, nil
     		}
     
    -		// If the storage class has AllowedTopologies set, then
    -		// it must match our own. We can find out by trying to
    -		// create accessibility requirements.  If that fails,
    -		// we should not become the owner.
    -		if len(sc.AllowedTopologies) > 0 && p.supportsTopology() {
    +		// The StorageClass topology, plus snapshot topology for Immediate
    +		// snapshot restores, must match this node before it can become owner.
    +		allowedTopologies := sc.AllowedTopologies
    +		if p.supportsTopology() &&
    +			utilfeature.DefaultFeatureGate.Enabled(features.VolumeSnapshotTopology) {
    +			dataSource, err := p.dataSource(ctx, claim)
    +			if err != nil {
    +				if logger.Enabled() {
    +					logger.Infof("%s: deferring snapshot topology check for PVC %s/%s until provisioning: %v", caller, claim.Namespace, claim.Name, err)
    +				}
    +			} else if dataSource != nil &&
    +				dataSource.Kind == snapshotKind &&
    +				dataSource.APIVersion == snapshotAPIGroup &&
    +				p.snapshotClient != nil &&
    +				p.controllerCapabilities[csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT] {
    +				_, snapshotNodeAffinity, err := p.getSnapshotSource(ctx, claim, sc, dataSource)

    Done in latest rev ✅ checkNode now reads the VolumeSnapshot and VolumeSnapshotContent from informer caches instead of getting them from the API server. The informers are only created for node deployment with the VolumeSnapshotTopology gate enabled or for the existing finalizer sweep, which now shares the same VolumeSnapshot informer so it is only watched once.

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Oct 20, 2026 18:52 UTC
    Bot

    PR needs rebase.

    <details>

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
    </details>

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Oct 22, 2026 08:46 UTC
    Bot

    @mdzraf: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

    Test name | Commit | Details | Required | Rerun command
    --- | --- | --- | --- | ---
    pull-kubernetes-csi-external-provisioner-distributed-on-kubernetes-1-36 | 5a76f6f667fc97cdf33aac2bc3f60290faf5109e | link | true | /test pull-kubernetes-csi-external-provisioner-distributed-on-kubernetes-1-36

    Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

    <details>

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.
    </details>
    <!-- test report -->

    Reviewers
    Assignees
    mdzraf mdzraf
    Labels
    risk: low confidence: 88.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: 78.5% (HIGH) · Higher = larger blast radius
    78.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: 88.8% · Lower = rushed or shallow review
    88.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: 8.8% · Safe to merge
    8.8%