← Back to Pull requests

Aggregate topology per registered key set for immediate binding #1582

Merged
divyenpatel merged 3 files (623 lines) on Oct 08, 2026 15:40 UTC
View on GitHub
divyenpatel divyenpatel commented on Sep 18, 2026 20:35 UTC
Author

<!-- Thanks for sending a pull request! Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Follow the instructions for writing a release note: https://git.k8s.io/community/contributors/guide/release-notes.md
3. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

What type of PR is this?
/kind bug

What this PR does / why we need it:
Nodes are not required to register the same topology keys for a driver: part of a cluster may register a finer granularity than the rest, for example "region" on some nodes and "region" plus "zone" on others. When that happened, the topology aggregated for immediate binding depended on which node was picked at random, and lost information either way.

aggregateTopologies() shuffled the CSINode list and adopted the topology keys of the first node that had any registered. That single key set was then turned into an AND-of-Exists node selector applied to the whole cluster, so only nodes carrying every one of those keys contributed a topology term. For the example above, the outcome depended entirely on the shuffle:

- picking a node registering region+zone made the selector require the zone label, excluding every region-only node from Requisite and constraining the volume to a zone it may not need;
- picking a region-only node erased zone from every term, dropping the finer placement that the nodes registering it can provide.

The choice was cached per PVC UID, so it was stable for one PVC but varied between PVCs and across provisioner restarts, leaving the resulting topology impossible to reason about operationally.

Each distinct key set registered across CSINodes is now aggregated on its own and the results are combined, so Requisite describes every granularity the cluster offers and no node is dropped for registering fewer keys than another. Entries in Requisite may therefore use different topology keys; per the CSI spec Requisite is a list the SP selects from, and the SP reports what it actually used through CreateVolumeResponse.accessible_topology. Preferred generation is unchanged and keeps rotating Requisite to spread StatefulSet volumes, so it carries the same mix of key sets in rotated order.

Clusters where every node registers the same topology keys are unaffected: a single key set yields exactly the previous behavior. Delayed binding is also unaffected, since it continues to aggregate using only the selected node's own key set.

Removing the shuffle makes the result fully determined by cluster state, which allows enabling the "different keys across cluster" test case that had been commented out because its result was not deterministic enough to assert.

Which issue(s) this PR fixes:
<!--
Automatically closes linked issue when PR is merged.
Usage: Fixes #<issue number>, or Fixes (paste link of issue).
_If PR is about failing-tests or flakes, please post the related issues/tests in a comment and do not use Fixes_

-->
Fixes # https://github.com/kubernetes-csi/external-provisioner/issues/1589

Special notes for your reviewer:
Deployed cluster with mixed topology keys. Some nodes with both host and zone key, some nodes with only zone keys.

# kubectl get nodes -L topology.kubernetes.io/zone -L  topology.csi.vmware.com/host
NAME                                                              STATUS   ROLES           AGE   VERSION            ZONE   HOST
kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-nodepool-75krnx   Ready    <none>          21m   v1.37.0+vmware.2   az2    
kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-nodepool-7h4jgp   Ready    <none>          21m   v1.37.0+vmware.2   az2    
kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-np-2f5l-jpqfj9j   Ready    <none>          24m   v1.37.0+vmware.2   az1    lvn-dvm-10-70-192-184.dvm.lvn.broadcom.net
kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-np-2f5l-jpxj9sh   Ready    <none>          24m   v1.37.0+vmware.2   az1    lvn-dvm-10-70-192-184.dvm.lvn.broadcom.net
kubernetes-cluster-bjwg-mzpp8-pxzt5                               Ready    control-plane   29m   v1.37.0+vmware.2   az1    

<details>
<summary>CSI Nodes</summary>

CSI Nodes with mixed topology keys on the cluster

# kubectl get csinodes -o json
{
    "apiVersion": "v1",
    "items": [
        {
            "apiVersion": "storage.k8s.io/v1",
            "kind": "CSINode",
            "metadata": {
                "annotations": {
                    "storage.alpha.kubernetes.io/migrated-plugins": "kubernetes.io/aws-ebs,kubernetes.io/azure-disk,kubernetes.io/azure-file,kubernetes.io/cinder,kubernetes.io/gce-pd,kubernetes.io/portworx-volume,kubernetes.io/vsphere-volume"
                },
                "creationTimestamp": "2026-09-22T22:37:26Z",
                "name": "kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-nodepool-75krnx",
                "ownerReferences": [
                    {
                        "apiVersion": "v1",
                        "kind": "Node",
                        "name": "kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-nodepool-75krnx",
                        "uid": "2a169851-2193-4195-b347-832bd887099a"
                    }
                ],
                "resourceVersion": "7459",
                "uid": "e3491b5b-6463-4f2f-9429-3d3867fb2c86"
            },
            "spec": {
                "drivers": [
                    {
                        "allocatable": {
                            "count": 59
                        },
                        "name": "csi.vsphere.vmware.com",
                        "nodeID": "kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-nodepool-75krnx",
                        "topologyKeys": [
                            "topology.kubernetes.io/zone"
                        ]
                    }
                ]
            },
            "status": {}
        },
        {
            "apiVersion": "storage.k8s.io/v1",
            "kind": "CSINode",
            "metadata": {
                "annotations": {
                    "storage.alpha.kubernetes.io/migrated-plugins": "kubernetes.io/aws-ebs,kubernetes.io/azure-disk,kubernetes.io/azure-file,kubernetes.io/cinder,kubernetes.io/gce-pd,kubernetes.io/portworx-volume,kubernetes.io/vsphere-volume"
                },
                "creationTimestamp": "2026-09-22T22:37:26Z",
                "name": "kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-nodepool-7h4jgp",
                "ownerReferences": [
                    {
                        "apiVersion": "v1",
                        "kind": "Node",
                        "name": "kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-nodepool-7h4jgp",
                        "uid": "c8cb32cb-c68d-42ef-90eb-20aa5da1aaba"
                    }
                ],
                "resourceVersion": "7467",
                "uid": "213bcc48-9bc5-4282-b29d-902bc06e739a"
            },
            "spec": {
                "drivers": [
                    {
                        "allocatable": {
                            "count": 59
                        },
                        "name": "csi.vsphere.vmware.com",
                        "nodeID": "kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-nodepool-7h4jgp",
                        "topologyKeys": [
                            "topology.kubernetes.io/zone"
                        ]
                    }
                ]
            },
            "status": {}
        },
        {
            "apiVersion": "storage.k8s.io/v1",
            "kind": "CSINode",
            "metadata": {
                "annotations": {
                    "storage.alpha.kubernetes.io/migrated-plugins": "kubernetes.io/aws-ebs,kubernetes.io/azure-disk,kubernetes.io/azure-file,kubernetes.io/cinder,kubernetes.io/gce-pd,kubernetes.io/portworx-volume,kubernetes.io/vsphere-volume"
                },
                "creationTimestamp": "2026-09-22T22:37:25Z",
                "name": "kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-np-2f5l-jpqfj9j",
                "ownerReferences": [
                    {
                        "apiVersion": "v1",
                        "kind": "Node",
                        "name": "kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-np-2f5l-jpqfj9j",
                        "uid": "cad33cd1-df33-4541-a5fe-324d0b5311c2"
                    }
                ],
                "resourceVersion": "7440",
                "uid": "3647b08b-5c0a-480a-bf5c-af1560c8ad74"
            },
            "spec": {
                "drivers": [
                    {
                        "allocatable": {
                            "count": 59
                        },
                        "name": "csi.vsphere.vmware.com",
                        "nodeID": "kubernetes-cluster-bjwg-kubernetes-cluster-bjwg-np-2f5l-jpqfj9j",
                        "topologyKeys": [
                            "topology.csi.vmware.com/host",
                            "topology.kubernetes.io/zone"
                        ]
                    }
                ]
            },
            "status": {}
        },
        {
            "apiVersion": "storage.k8s.io/v1",
            "kind": "CSINode",
            "metadata": {
                "annotations": {
                    "storage.alpha.kubernetes.io/migrated-plugins": "kubernetes.io/aws-ebs,kubernetes.io/azure-disk,kubernetes.io/azure-file,kubernetes.io/cinder,kubernetes.io/gce-pd,kubernetes.io/portworx-volume,kubernetes.io/vsphere-volume"
                },
                "creationTimestamp": "2026-09-22T22:37:25Z",
                "name": "kubernetes-cluster-bjwg-mzpp8-pxzt5",
                "ownerReferences": [
                    {
                        "apiVersion": "v1",
                        "kind": "Node",
                        "name": "kubernetes-cluster-bjwg-mzpp8-pxzt5",
                        "uid": "46ea3d9d-e30c-49ca-82f7-3732ca1894ce"
                    }
                ],
                "resourceVersion": "7449",
                "uid": "7521fbd3-1bfa-4ab7-9e67-8722c1c3f3be"
            },
            "spec": {
                "drivers": [
                    {
                        "allocatable": {
                            "count": 59
                        },
                        "name": "csi.vsphere.vmware.com",
                        "nodeID": "kubernetes-cluster-bjwg-mzpp8-pxzt5",
                        "topologyKeys": [
                            "topology.kubernetes.io/zone"
                        ]
                    }
                ]
            },
            "status": {}
        }
    ],
    "kind": "List",
    "metadata": {
        "resourceVersion": ""
    }
}

</details>

Verified volume provisioning request comes with all topology requirements to CSI controller

{"level":"info","time":"2026-09-22T22:44:00.731609526Z","caller":"wcpguest/controller.go:391","msg":"CreateVolume: called with args name:\"pvc-294e0600-c086-49bb-9051-c0b77d5310d7\"  capacity_range:{required_bytes:5368709120}  volume_capabilities:{mount:{fs_type:\"ext4\"}  access_mode:{mode:SINGLE_NODE_WRITER}}  parameters:{key:\"csi.storage.k8s.io/pv/name\"  value:\"pvc-294e0600-c086-49bb-9051-c0b77d5310d7\"}  parameters:{key:\"csi.storage.k8s.io/pvc/name\"  value:\"hostlocalpvc\"}  parameters:{key:\"csi.storage.k8s.io/pvc/namespace\"  value:\"default\"}  parameters:{key:\"svStorageClass\"  value:\"hostlocal-storage\"}  accessibility_requirements:{requisite:{segments:{key:\"topology.kubernetes.io/zone\"  value:\"az1\"}}  requisite:{segments:{key:\"topology.kubernetes.io/zone\"  value:\"az2\"}}  requisite:{segments:{key:\"topology.csi.vmware.com/host\"  value:\"lvn-dvm-10-70-192-184.dvm.lvn.broadcom.net\"}  segments:{key:\"topology.kubernetes.io/zone\"  value:\"az1\"}}  preferred:{segments:{key:\"topology.kubernetes.io/zone\"  value:\"az1\"}}  preferred:{segments:{key:\"topology.kubernetes.io/zone\"  value:\"az2\"}}  preferred:{segments:{key:\"topology.csi.vmware.com/host\"  value:\"lvn-dvm-10-70-192-184.dvm.lvn.broadcom.net\"}  segments:{key:\"topology.kubernetes.io/zone\"  value:\"az1\"}}}","TraceId":"5e61480a-4164-427d-9345-4d28ff95faae"}


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
Aggregate topology per registered key set for immediate binding.
With immediate binding, topology requirements now cover every set of topology keys registered by the driver, rather than one set picked at random. Additionally (with both immediate and delayed binding) nodes are no longer included in topology requirements unless the driver registered those topology keys on that node.
``

Diff: 623 lines (+523 / -100) across 3 files Reviewer: divyenpatel Review duration: 28504m
All Vouch review confidence checks passed
Residual risk 0.10 = Change Risk (0.58) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.58 · 623 lines diff across 3 files
0.58
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%
83%
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.385
Self Review self_review
0.140
Real PR Conversation Timeline
28 items
kubernetes-prow[bot] kubernetes-prow[bot] commented on Sep 18, 2026 20:35 UTC
Bot

Hi @divyenpatel. Thanks for your PR.

I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

>[!TIP]
>We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

<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>

xing-yang xing-yang commented on Sep 21, 2026 14:39 UTC
Contributor

/ok-to-test

xing-yang xing-yang commented on Sep 21, 2026 14:40 UTC
Contributor

Can you open an issue and link here?

xing-yang xing-yang commented on Sep 21, 2026 14:41 UTC
Contributor

/assign @jsafrane

xing-yang xing-yang commented on Sep 21, 2026 14:44 UTC
Contributor

Can you provide examples of the PVCs, CSINode, etc. in your testing results?

Copilot Copilot commented on code on Sep 21, 2026 14:47 UTC
Code Review
pkg/controller/topology.go:1
@@ -335,96 +397,90 @@ func aggregateTopologies(
 	nodeLister corelisters.NodeLister,
 	pvcKeyForStore types.UID,
 	pvcNodeStore TopologyProvider) ([]topologyTerm, error) {
-	// 1. Determine topologyKeys to use for aggregation
-	var topologyKeys []string
-	var err error
 	if len(selectedNodeName) == 0 {
-		// Immediate binding
-		// Read from cache first to make sure retry with the same arguments
-		topologyKeys, err = getTopologyKeysFromCache(pvcNodeStore, pvcKeyForStore)
-		if err != nil || len(topologyKeys) == 0 {
-			// Not in the in memory cache. Find from csiNodes.
-			csiNodes, err := csiNodeLister.List(labels.Everything())
-			if err != nil {
-				// Require CSINode beta feature on K8s apiserver to be enabled.
-				// We don't want to fallback and provision in the wrong topology if there's some temporary
-				// error with the API server.
-				return nil, fmt.Errorf("error listing CSINodes: %v", err)
-			}
-			rand.Shuffle(len(csiNodes), func(i, j int) {
-				csiNodes[i], csiNodes[j] = csiNodes[j], csiNodes[i]
-			})
-			// Pick the first node with topology keys
-			for _, csiNode := range csiNodes {
-				keys := getTopologyKeys(csiNode, driverName)
-				if len(keys) > 0 {
-					topologyKeys = keys
-					// Store in cache for next time.
-					pvcNodeStore.UpdateTopologyKeys(pvcKeyForStore, topologyKeys)
-					break
-				}
-			}
+		// Immediate binding. The result is fully determined by the state of the
+		// cluster, so the cached requisite terms are the only memo needed here.
+		terms, err := getRequisiteTermsFromCache(pvcNodeStore, pvcKeyForStore)
+		if err == nil && len(terms) > 0 {
+			return terms, nil
 		}
 
-		if len(topologyKeys) == 0 {
+		csiNodes, err := csiNodeLister.List(labels.Everything())
+		if err != nil {
+			// Require CSINode beta feature on K8s apiserver to be enabled.
+			// We don't want to fallback and provision in the wrong topology if there's some temporary
+			// error with the API server.
+			return nil, fmt.Errorf("error listing CSINodes: %v", err)
+		}
+
+		keySets := distinctTopologyKeySets(csiNodes, driverName)
+		if len(keySets) == 0 {
 			// The driver supports topology but no nodes have registered any topology keys.
 			// This is possible if nodes have not been upgraded to use the beta CSINode feature.
 			klog.Warningf("No topology keys found on any node")
 			return nil, nil
 		}
-	} else {
-		// Delayed binding; use topology key from selected node
-		topologyKeys = selectedNodeTopologyKeys
-		if len(topologyKeys) == 0 {
-			// The scheduler selected a node with no topology information.
-			// This can happen if:
-			//
-			// * the node driver is not deployed on all nodes.
-			// * the node driver is being restarted and has not re-registered yet. This should be
-			//   temporary and a retry should eventually succeed.
-			//
-			// Returning an error in provisioning will cause the scheduler to retry and potentially
-			// (but not guaranteed) pick a different node.
-			return nil, fmt.Errorf("no topology key found on CSINode %s", selectedNodeName)
+
+		// Nodes are not required to report the same topology keys for a driver.
+		// Aggregating a single key set across the whole cluster would either
+		// drop the nodes that do not report the finer keys, or erase the finer
+		// keys from the nodes that do report them. Aggregate each reported key
+		// set on its own instead and combine the results, so that the requisite
+		// topology describes every granularity the cluster offers.
+		terms = nil
+		for _, topologyKeys := range keySets {
+			keyTerms, err := aggregateTopologiesForKeys(topologyKeys, nodeLister)
+			if err != nil {
+				return nil, err
+			}
+			terms = append(terms, keyTerms...)

This pass filters only Node labels, not the driver's per-node CSINode registration. If a node reports [region] while another reports [zone] and both nodes carry both cluster labels, the [region] pass will emit the second node's region and the [zone] pass will emit the first node's zone, even though the driver never reported those topologies for those nodes. Restrict each key-set pass to nodes whose registration contains that set (while preserving the intended superset/fallback behavior), otherwise Requisite can advertise placements the driver cannot access.

Copilot Copilot commented on code on Sep 21, 2026 14:47 UTC
Code Review
README.md:1
@@ -157,6 +157,8 @@ No | Irrelevant | No  | No  | `Requisite` and `Preferred` both nil
 *) `Topology` feature gate is enabled by default since v5.0.
 <!-- TODO: remove the feature gate in the next release - remove the whole column in the table above. -->
 
+Aggregated cluster topology is computed from the topology keys that the driver has registered in the `CSINode` objects. Nodes are not required to register the same topology keys: a driver may report a finer granularity on part of the cluster than on the rest, for example `region` on some nodes and `region` plus `zone` on others. Every distinct registered key set is aggregated separately and the results are combined, so `Requisite` describes each granularity the cluster offers and no node is excluded because it reports fewer keys than another. As a result, the entries in `Requisite` are not guaranteed to all use the same topology keys. `Requisite` is a list the driver selects from, so a driver that registers several granularities should pick the entry that suits the volume it is creating, and report the topology the volume was actually created in through `CreateVolumeResponse.accessible_topology`. `Preferred` for immediate binding is a rotation of `Requisite` used to spread StatefulSet volumes, so it contains the same mix of key sets in rotated order: its first entry is not guaranteed to use any particular key set, and a driver should scan it for an entry it can satisfy rather than assuming the first one fits. Clusters where every node registers the same topology keys are unaffected and get a single key set as before.

The table above still says that immediate-binding Preferred starts with a randomly selected node topology, but this change removes the shuffle and the implementation rotates the sorted terms deterministically from the PVC name/index. Please update the table as part of this documentation change; otherwise it contradicts the new deterministic behavior described here.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 21, 2026 14:47 UTC
Reviewer

<!-- ccr-overview-v2 -->

Copilot review overview

🟡 Changes recommended

The topology aggregation must be restricted to matching per-node CSI registrations before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> · 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture>

<details open>
<summary><strong>Open (2)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Filter topology passes by each node&#39;s CSINode registration](#discussion_r4063271240) · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture> [Update table to describe deterministic Preferred topology selection](#discussion_r4063271338) · New

  • </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Updates immediate-binding topology aggregation to handle heterogeneous CSI topology key sets deterministically.

    Changes:

  • Aggregates each distinct registered key set independently.

  • Removes nondeterministic CSINode shuffling.

  • Adds mixed-key tests and documentation.
  • | File | Summary | Review comments |
    |---|---|---|
    | README.md | Documents mixed topology key behavior. | Nit (2 votes): Update the table describing randomly selected Preferred topology to reflect deterministic rotation. |
    | pkg/​controller/​topology.go | Implements deterministic per-key-set aggregation. | Moderate (2 votes): Restrict each key-set pass to nodes whose CSINode registration contains that set. |
    | pkg/​controller/​topology_test.go | Adds mixed-key aggregation test coverage. | No comments. |
    </details>

    ---

    💡 <a href="/kubernetes-csi/external-provisioner/new/master?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>

    divyenpatel divyenpatel commented on Sep 21, 2026 20:49 UTC
    Author
    divyenpatel divyenpatel commented on code on Sep 21, 2026 21:02 UTC
    Code Review
    pkg/controller/topology.go:1
    @@ -335,96 +397,90 @@ func aggregateTopologies(
     	nodeLister corelisters.NodeLister,
     	pvcKeyForStore types.UID,
     	pvcNodeStore TopologyProvider) ([]topologyTerm, error) {
    -	// 1. Determine topologyKeys to use for aggregation
    -	var topologyKeys []string
    -	var err error
     	if len(selectedNodeName) == 0 {
    -		// Immediate binding
    -		// Read from cache first to make sure retry with the same arguments
    -		topologyKeys, err = getTopologyKeysFromCache(pvcNodeStore, pvcKeyForStore)
    -		if err != nil || len(topologyKeys) == 0 {
    -			// Not in the in memory cache. Find from csiNodes.
    -			csiNodes, err := csiNodeLister.List(labels.Everything())
    -			if err != nil {
    -				// Require CSINode beta feature on K8s apiserver to be enabled.
    -				// We don't want to fallback and provision in the wrong topology if there's some temporary
    -				// error with the API server.
    -				return nil, fmt.Errorf("error listing CSINodes: %v", err)
    -			}
    -			rand.Shuffle(len(csiNodes), func(i, j int) {
    -				csiNodes[i], csiNodes[j] = csiNodes[j], csiNodes[i]
    -			})
    -			// Pick the first node with topology keys
    -			for _, csiNode := range csiNodes {
    -				keys := getTopologyKeys(csiNode, driverName)
    -				if len(keys) > 0 {
    -					topologyKeys = keys
    -					// Store in cache for next time.
    -					pvcNodeStore.UpdateTopologyKeys(pvcKeyForStore, topologyKeys)
    -					break
    -				}
    -			}
    +		// Immediate binding. The result is fully determined by the state of the
    +		// cluster, so the cached requisite terms are the only memo needed here.
    +		terms, err := getRequisiteTermsFromCache(pvcNodeStore, pvcKeyForStore)
    +		if err == nil && len(terms) > 0 {
    +			return terms, nil
     		}
     
    -		if len(topologyKeys) == 0 {
    +		csiNodes, err := csiNodeLister.List(labels.Everything())
    +		if err != nil {
    +			// Require CSINode beta feature on K8s apiserver to be enabled.
    +			// We don't want to fallback and provision in the wrong topology if there's some temporary
    +			// error with the API server.
    +			return nil, fmt.Errorf("error listing CSINodes: %v", err)
    +		}
    +
    +		keySets := distinctTopologyKeySets(csiNodes, driverName)
    +		if len(keySets) == 0 {
     			// The driver supports topology but no nodes have registered any topology keys.
     			// This is possible if nodes have not been upgraded to use the beta CSINode feature.
     			klog.Warningf("No topology keys found on any node")
     			return nil, nil
     		}
    -	} else {
    -		// Delayed binding; use topology key from selected node
    -		topologyKeys = selectedNodeTopologyKeys
    -		if len(topologyKeys) == 0 {
    -			// The scheduler selected a node with no topology information.
    -			// This can happen if:
    -			//
    -			// * the node driver is not deployed on all nodes.
    -			// * the node driver is being restarted and has not re-registered yet. This should be
    -			//   temporary and a retry should eventually succeed.
    -			//
    -			// Returning an error in provisioning will cause the scheduler to retry and potentially
    -			// (but not guaranteed) pick a different node.
    -			return nil, fmt.Errorf("no topology key found on CSINode %s", selectedNodeName)
    +
    +		// Nodes are not required to report the same topology keys for a driver.
    +		// Aggregating a single key set across the whole cluster would either
    +		// drop the nodes that do not report the finer keys, or erase the finer
    +		// keys from the nodes that do report them. Aggregate each reported key
    +		// set on its own instead and combine the results, so that the requisite
    +		// topology describes every granularity the cluster offers.
    +		terms = nil
    +		for _, topologyKeys := range keySets {
    +			keyTerms, err := aggregateTopologiesForKeys(topologyKeys, nodeLister)
    +			if err != nil {
    +				return nil, err
    +			}
    +			terms = append(terms, keyTerms...)
    divyenpatel divyenpatel commented on code on Sep 21, 2026 21:02 UTC
    Code Review
    README.md:1
    @@ -157,6 +157,8 @@ No | Irrelevant | No  | No  | `Requisite` and `Preferred` both nil
     *) `Topology` feature gate is enabled by default since v5.0.
     <!-- TODO: remove the feature gate in the next release - remove the whole column in the table above. -->
     
    +Aggregated cluster topology is computed from the topology keys that the driver has registered in the `CSINode` objects. Nodes are not required to register the same topology keys: a driver may report a finer granularity on part of the cluster than on the rest, for example `region` on some nodes and `region` plus `zone` on others. Every distinct registered key set is aggregated separately and the results are combined, so `Requisite` describes each granularity the cluster offers and no node is excluded because it reports fewer keys than another. As a result, the entries in `Requisite` are not guaranteed to all use the same topology keys. `Requisite` is a list the driver selects from, so a driver that registers several granularities should pick the entry that suits the volume it is creating, and report the topology the volume was actually created in through `CreateVolumeResponse.accessible_topology`. `Preferred` for immediate binding is a rotation of `Requisite` used to spread StatefulSet volumes, so it contains the same mix of key sets in rotated order: its first entry is not guaranteed to use any particular key set, and a driver should scan it for an entry it can satisfy rather than assuming the first one fits. Clusters where every node registers the same topology keys are unaffected and get a single key set as before.
    divyenpatel divyenpatel commented on Sep 23, 2026 00:10 UTC
    Author

    Can you provide examples of the PVCs, CSINode, etc. in your testing results?

    @xing-yang I have provided CSINodes and testing logs. Verified creating volumes on cluster with mixed topology requirements

    xing-yang xing-yang commented on Sep 26, 2026 03:22 UTC
    Contributor

    /assign @torredil

    torredil torredil commented on Sep 30, 2026 19:01 UTC
    Contributor

    We are actively reviewing this +@ConnorJC3 is working on a fix to kubernetes-sigs/aws-ebs-csi-driver's topology handling since this changes behavior for clusters that mix regional and outpost nodes.

    sunnylovestiramisu sunnylovestiramisu commented on Oct 02, 2026 17:09 UTC
    Contributor

    /lgtm

    jsafrane jsafrane commented on Oct 05, 2026 12:32 UTC
    Contributor

    /approve

    jsafrane jsafrane commented on Oct 05, 2026 12:33 UTC
    Contributor

    /test pull-kubernetes-csi-external-provisioner-unit

    jsafrane jsafrane commented on Oct 05, 2026 12:53 UTC
    Contributor

    /approve cancel

    Please fix gofmt. I.e. remove your gofmt changes, we fixed our scripts to format with the right go 1.26.

    jsafrane jsafrane commented on code on Oct 05, 2026 12:55 UTC
    Code Review
    pkg/controller/topology_test.go:1
    @@ -936,24 +936,100 @@ func TestTopologyAggregation(t *testing.T) {
     				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
     			},
     		},
    -		//"different keys across cluster": {
    -		//	nodeLabels: []map[string]string{
    -		//		{ "com.example.csi/zone": "zone1" },
    -		//		{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" },
    -		//		{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" },
    -		//	},
    -		//	topologyKeys: []map[string][]string{
    -		//		{ testDriverName: []string{ "com.example.csi/zone" } },
    -		//		{ testDriverName: []string{ "com.example.csi/zone", "com.example.csi/rack" } },
    -		//		{ testDriverName: []string{ "com.example.csi/zone", "com.example.csi/rack" } },
    -		//	},
    -		//	expectedRequisite: &csi.TopologyRequirement{
    -		//		Requisite: []*csi.Topology{
    -		//			{ Segments: map[string]string{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" } },
    -		//		},
    -		//	},
    -		//	// TODO (verult) mock Rand
    -		//},
    +		// Nodes report different topology keys for the same driver. Each
    +		// reported key set is aggregated on its own, so the finer granularity
    +		// is not erased and the node reporting only the coarser key set is not
    +		// dropped.
    +		"different keys across cluster": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/zone": "zone1"},
    +				{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"},
    +				{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +				{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
    +				{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"}},
    +			},
    +		},
    +		// The node reporting only the coarser key set is in a topology of its
    +		// own, so its contribution to the requisite terms is unambiguous.
    +		"different keys across cluster: node reporting fewer keys is not dropped": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone1"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"}},
    +			},
    +		},
    +		// Key sets that have no key in common are still each aggregated, rather
    +		// than one of them being picked over the other.
    +		"disjoint keys across cluster": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east"},
    +				{"com.example.csi/zone": "zone1"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
    +			},
    +		},
    +		// Topology labels can exist on nodes the driver did not register them
    +		// on. Each key set must only report the nodes whose own registration
    +		// covers it, otherwise the requisite terms advertise placements the
    +		// driver cannot serve: here the first node's zone and the second
    +		// node's region were never registered.
    +		"disjoint keys across cluster, both labels on every node": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone2"}},
    +			},
    +		},
    +		// A node registering a finer key set still contributes to the coarser
    +		// key set's aggregation, because its registration covers those keys.
    +		// The reverse does not hold: the node registering only the coarser set
    +		// is left out of the finer aggregation even though it carries both
    +		// labels, so its zone never appears.
    +		"finer registration contributes to the coarser key set": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone2"}},
    +			},
    +		},
     		"selected node: different keys across cluster": {

    What about a node that has topology labels on Node, but does not report any topology keys in CSINode? The driver explicitly said that it does not have any topology keys for this node in NodeGetInfo response. Yet, someone has labeled it.

    This fails, because the code picks us-west + zone2, despite no topologyKeys for that node.

                   "unregistered node with labels for multiple key sets": {
                           nodeLabels: []map[string]string{
                                   {"com.example.csi/region": "us-east"},
                                   {"com.example.csi/zone": "zone1"},
                                   {"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"},
                           },
                           topologyKeys: []map[string][]string{
                                   {testDriverName: []string{"com.example.csi/region"}},
                                   {testDriverName: []string{"com.example.csi/zone"}},
                                   {testDriverName: nil},
                           },
                           expectedRequisite: []*csi.Topology{
                                   {Segments: map[string]string{"com.example.csi/region": "us-east"}},
                                   {Segments: map[string]string{"com.example.csi/zone": "zone1"}},
                          },
                   },
    

    ConnorJC3 ConnorJC3 commented on Oct 06, 2026 23:43 UTC
    Contributor

    /lgtm

    lgtm minus what Jan already pointed out

    jsafrane jsafrane commented on code on Oct 07, 2026 15:56 UTC
    Code Review
    pkg/controller/topology_test.go:1
    @@ -936,24 +936,100 @@ func TestTopologyAggregation(t *testing.T) {
     				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
     			},
     		},
    -		//"different keys across cluster": {
    -		//	nodeLabels: []map[string]string{
    -		//		{ "com.example.csi/zone": "zone1" },
    -		//		{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" },
    -		//		{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" },
    -		//	},
    -		//	topologyKeys: []map[string][]string{
    -		//		{ testDriverName: []string{ "com.example.csi/zone" } },
    -		//		{ testDriverName: []string{ "com.example.csi/zone", "com.example.csi/rack" } },
    -		//		{ testDriverName: []string{ "com.example.csi/zone", "com.example.csi/rack" } },
    -		//	},
    -		//	expectedRequisite: &csi.TopologyRequirement{
    -		//		Requisite: []*csi.Topology{
    -		//			{ Segments: map[string]string{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" } },
    -		//		},
    -		//	},
    -		//	// TODO (verult) mock Rand
    -		//},
    +		// Nodes report different topology keys for the same driver. Each
    +		// reported key set is aggregated on its own, so the finer granularity
    +		// is not erased and the node reporting only the coarser key set is not
    +		// dropped.
    +		"different keys across cluster": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/zone": "zone1"},
    +				{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"},
    +				{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +				{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
    +				{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"}},
    +			},
    +		},
    +		// The node reporting only the coarser key set is in a topology of its
    +		// own, so its contribution to the requisite terms is unambiguous.
    +		"different keys across cluster: node reporting fewer keys is not dropped": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone1"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"}},
    +			},
    +		},
    +		// Key sets that have no key in common are still each aggregated, rather
    +		// than one of them being picked over the other.
    +		"disjoint keys across cluster": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east"},
    +				{"com.example.csi/zone": "zone1"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
    +			},
    +		},
    +		// Topology labels can exist on nodes the driver did not register them
    +		// on. Each key set must only report the nodes whose own registration
    +		// covers it, otherwise the requisite terms advertise placements the
    +		// driver cannot serve: here the first node's zone and the second
    +		// node's region were never registered.
    +		"disjoint keys across cluster, both labels on every node": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone2"}},
    +			},
    +		},
    +		// A node registering a finer key set still contributes to the coarser
    +		// key set's aggregation, because its registration covers those keys.
    +		// The reverse does not hold: the node registering only the coarser set
    +		// is left out of the finer aggregation even though it carries both
    +		// labels, so its zone never appears.
    +		"finer registration contributes to the coarser key set": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone2"}},
    +			},
    +		},
     		"selected node: different keys across cluster": {

    BTW, this is for discussion - my gut feeling is the provisioner should honor the topology keys from CSINode and not include us-west/zone2. But I could be convinced by a good use case. I know various cloud providers label their nodes in ... creative ways, e.g. via node-labeler in GCE; cc @sunnylovestiramisu

    ConnorJC3 ConnorJC3 commented on code on Oct 07, 2026 16:27 UTC
    Code Review
    pkg/controller/topology_test.go:1
    @@ -936,24 +936,100 @@ func TestTopologyAggregation(t *testing.T) {
     				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
     			},
     		},
    -		//"different keys across cluster": {
    -		//	nodeLabels: []map[string]string{
    -		//		{ "com.example.csi/zone": "zone1" },
    -		//		{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" },
    -		//		{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" },
    -		//	},
    -		//	topologyKeys: []map[string][]string{
    -		//		{ testDriverName: []string{ "com.example.csi/zone" } },
    -		//		{ testDriverName: []string{ "com.example.csi/zone", "com.example.csi/rack" } },
    -		//		{ testDriverName: []string{ "com.example.csi/zone", "com.example.csi/rack" } },
    -		//	},
    -		//	expectedRequisite: &csi.TopologyRequirement{
    -		//		Requisite: []*csi.Topology{
    -		//			{ Segments: map[string]string{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" } },
    -		//		},
    -		//	},
    -		//	// TODO (verult) mock Rand
    -		//},
    +		// Nodes report different topology keys for the same driver. Each
    +		// reported key set is aggregated on its own, so the finer granularity
    +		// is not erased and the node reporting only the coarser key set is not
    +		// dropped.
    +		"different keys across cluster": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/zone": "zone1"},
    +				{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"},
    +				{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +				{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
    +				{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"}},
    +			},
    +		},
    +		// The node reporting only the coarser key set is in a topology of its
    +		// own, so its contribution to the requisite terms is unambiguous.
    +		"different keys across cluster: node reporting fewer keys is not dropped": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone1"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"}},
    +			},
    +		},
    +		// Key sets that have no key in common are still each aggregated, rather
    +		// than one of them being picked over the other.
    +		"disjoint keys across cluster": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east"},
    +				{"com.example.csi/zone": "zone1"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
    +			},
    +		},
    +		// Topology labels can exist on nodes the driver did not register them
    +		// on. Each key set must only report the nodes whose own registration
    +		// covers it, otherwise the requisite terms advertise placements the
    +		// driver cannot serve: here the first node's zone and the second
    +		// node's region were never registered.
    +		"disjoint keys across cluster, both labels on every node": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone2"}},
    +			},
    +		},
    +		// A node registering a finer key set still contributes to the coarser
    +		// key set's aggregation, because its registration covers those keys.
    +		// The reverse does not hold: the node registering only the coarser set
    +		// is left out of the finer aggregation even though it carries both
    +		// labels, so its zone never appears.
    +		"finer registration contributes to the coarser key set": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone2"}},
    +			},
    +		},
     		"selected node: different keys across cluster": {

    I would argue the correct behavior is only to pass keys the driver returned in NodeGetInfo - here's a quote from the CSI spec CreateVolumeRequest struct:

    COs SHALL only specify topological accessibility information supported by the SP.
    

    divyenpatel divyenpatel commented on code on Oct 08, 2026 11:49 UTC
    Code Review
    pkg/controller/topology_test.go:1
    @@ -936,24 +936,100 @@ func TestTopologyAggregation(t *testing.T) {
     				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
     			},
     		},
    -		//"different keys across cluster": {
    -		//	nodeLabels: []map[string]string{
    -		//		{ "com.example.csi/zone": "zone1" },
    -		//		{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" },
    -		//		{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" },
    -		//	},
    -		//	topologyKeys: []map[string][]string{
    -		//		{ testDriverName: []string{ "com.example.csi/zone" } },
    -		//		{ testDriverName: []string{ "com.example.csi/zone", "com.example.csi/rack" } },
    -		//		{ testDriverName: []string{ "com.example.csi/zone", "com.example.csi/rack" } },
    -		//	},
    -		//	expectedRequisite: &csi.TopologyRequirement{
    -		//		Requisite: []*csi.Topology{
    -		//			{ Segments: map[string]string{ "com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA" } },
    -		//		},
    -		//	},
    -		//	// TODO (verult) mock Rand
    -		//},
    +		// Nodes report different topology keys for the same driver. Each
    +		// reported key set is aggregated on its own, so the finer granularity
    +		// is not erased and the node reporting only the coarser key set is not
    +		// dropped.
    +		"different keys across cluster": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/zone": "zone1"},
    +				{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"},
    +				{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +				{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
    +				{testDriverName: []string{"com.example.csi/zone", "com.example.csi/rack"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1", "com.example.csi/rack": "rackA"}},
    +			},
    +		},
    +		// The node reporting only the coarser key set is in a topology of its
    +		// own, so its contribution to the requisite terms is unambiguous.
    +		"different keys across cluster: node reporting fewer keys is not dropped": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone1"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"}},
    +			},
    +		},
    +		// Key sets that have no key in common are still each aggregated, rather
    +		// than one of them being picked over the other.
    +		"disjoint keys across cluster": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east"},
    +				{"com.example.csi/zone": "zone1"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone1"}},
    +			},
    +		},
    +		// Topology labels can exist on nodes the driver did not register them
    +		// on. Each key set must only report the nodes whose own registration
    +		// covers it, otherwise the requisite terms advertise placements the
    +		// driver cannot serve: here the first node's zone and the second
    +		// node's region were never registered.
    +		"disjoint keys across cluster, both labels on every node": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-west", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/zone": "zone2"}},
    +			},
    +		},
    +		// A node registering a finer key set still contributes to the coarser
    +		// key set's aggregation, because its registration covers those keys.
    +		// The reverse does not hold: the node registering only the coarser set
    +		// is left out of the finer aggregation even though it carries both
    +		// labels, so its zone never appears.
    +		"finer registration contributes to the coarser key set": {
    +			nodeLabels: []map[string]string{
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone1"},
    +				{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone2"},
    +			},
    +			topologyKeys: []map[string][]string{
    +				{testDriverName: []string{"com.example.csi/region"}},
    +				{testDriverName: []string{"com.example.csi/region", "com.example.csi/zone"}},
    +			},
    +			expectedRequisite: []*csi.Topology{
    +				{Segments: map[string]string{"com.example.csi/region": "us-east"}},
    +				{Segments: map[string]string{"com.example.csi/region": "us-east", "com.example.csi/zone": "zone2"}},
    +			},
    +		},
     		"selected node: different keys across cluster": {

    @jsafrane @ConnorJC3

    A node whose driver reported no topology keys is now excluded even if it carries matching labels, per the CSI requirement that COs only specify topology the SP supports. See commit https://github.com/kubernetes-csi/external-provisioner/pull/1582/changes/ab732b4ddeff730fb1e95261a7fa7ae2c0461064 and https://github.com/kubernetes-csi/external-provisioner/pull/1582/changes/f4d0353a3a205f6fdb9c9bb20eaf9e8fa077f4e8 (for delayed binding)

    torredil torredil commented on Oct 08, 2026 14:01 UTC
    Contributor

    /lgtm

    If you can also please update the release note to account for the changes in latest rev:

    With immediate binding, topology requirements now cover every set of topology keys registered by the driver, rather than one set picked at random. Additionally (with both immediate and delayed binding) nodes are no longer included in topology requirements unless the driver registered those topology keys on that node.
    

    jsafrane jsafrane commented on Oct 08, 2026 15:38 UTC
    Contributor

    /approve

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Oct 08, 2026 15:38 UTC
    Bot

    [APPROVALNOTIFIER] This PR is APPROVED

    This pull-request has been approved by: <a href="https://github.com/kubernetes-csi/external-provisioner/pull/1582#" title="Author self-approved">divyenpatel</a>, <a href="https://github.com/kubernetes-csi/external-provisioner/pull/1582#issuecomment-6063493934" title="Approved">jsafrane</a>

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

    The pull request process is described here

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

  • ~~OWNERS~~ [jsafrane]
  • 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":[]} -->

    divyenpatel divyenpatel commented on Oct 08, 2026 17:03 UTC
    Author

    /lgtm

    > If you can also please update the release note to account for the changes in latest rev:

    >
    > With immediate binding, topology requirements now cover every set of topology keys registered by the driver, rather than one set picked at random. Additionally (with both immediate and delayed binding) nodes are no longer included in topology requirements unless the driver registered those topology keys on that node.
    > 

    done.

    Reviewers
    Assignees
    divyenpatel divyenpatel
    Labels
    risk: low confidence: 83.1% 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: 58.4% (MEDIUM) · Higher = larger blast radius
    58.4%
    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: 83.1% · Lower = rushed or shallow review
    83.1%
    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: 9.9% · Safe to merge
    9.9%