Add snapshot topology support for Immediate binding (KEP-5943) #1552
[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:
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"]} -->
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.
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.
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.
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:
VolumeSnapshotTopology feature gate and wires it into provisioning to constrain CreateVolume accessibility requirements for snapshot-sourced PVCs with Immediate binding.intersectSnapshotTopology logic (plus unit tests) to compute the intersection of snapshot NodeAffinity and StorageClass.AllowedTopologies.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>.
This silently drops all the results generated by GenerateAccessibilityRequirements().
This will trigger a reschedule even in cases where the snapshot-topology intersection could have resolved things locally without needing that lookup.
Fixed in new rev
Addressed in new rev by adding TestProvisionFromSnapshotWithTopology tests
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.
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.
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.
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.
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.
🟡 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
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"
</details>
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.
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.
This looks like a valid comment to me.
Again, pretty good catch
It's maybe valid, but much less concerning than the two AI comments above.
Added in new rev ✅
Added in new rev ✅
/retest
checkNode is called frequently. Can you use VolumeSnapshot and VolumeSnapshotContent listers instead of calling getSnapshotSource() which gets them from the API server?
I suppose we can't merge this before the snapshotter PR.
Yes, that is why I have the hold on this one
Sure, going to swap for listers and have that in the next rev, leaving this thread open until that rev is out.
/retest
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.
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>
@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 -->
xing-yang
mdzraf
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
NodeAffinityandStorageClass.AllowedTopologies. This functionality is gated behind theVolumeSnapshotTopologyfeature 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