Aggregate topology per registered key set for immediate binding #1582
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>
/ok-to-test
Can you open an issue and link here?
/assign @jsafrane
Can you provide examples of the PVCs, CSINode, etc. in your testing results?
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.
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.
<!-- 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>
</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:
| 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>
Can you open an issue and link here?
https://github.com/kubernetes-csi/external-provisioner/issues/1589
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
/assign @torredil
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.
/lgtm
/approve
/test pull-kubernetes-csi-external-provisioner-unit
/approve cancel
Please fix gofmt. I.e. remove your gofmt changes, we fixed our scripts to format with the right go 1.26.
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"}},
},
},
/lgtm
lgtm minus what Jan already pointed out
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
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.
@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)
/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.
/approve
[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:
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":[]} -->
/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.
divyenpatel
<!-- 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>, orFixes (paste link of issue)._If PR is about
failing-tests or flakes, please post the related issues/tests in a comment and do not useFixes_-->
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.
<details>
<summary>CSI Nodes</summary>
CSI Nodes with mixed topology keys on the cluster
</details>
Verified volume provisioning request comes with all topology requirements to CSI controller
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.