Skip to content

Filter capacity work items by storage class allowed topologies - #1538

Open
DPS0340 wants to merge 1 commit into
kubernetes-csi:masterfrom
DPS0340:capacity-filter-allowed-topologies
Open

Filter capacity work items by storage class allowed topologies#1538
DPS0340 wants to merge 1 commit into
kubernetes-csi:masterfrom
DPS0340:capacity-filter-allowed-topologies

Conversation

@DPS0340

@DPS0340 DPS0340 commented Jul 4, 2026

Copy link
Copy Markdown

What type of PR is this?
/kind feature

What this PR does / why we need it:

The central capacity controller creates a work item (and with it a CSIStorageCapacity object) for every combination of topology segment and storage class, even when the storage class's allowedTopologies rule out that segment. This PR filters out those impossible combinations when a storage class is added/updated and when new topology segments appear, reducing work queue depth and the number of CSIStorageCapacity objects.

The check is intentionally conservative: a combination is only skipped when a topology selector term contains a requirement for one of the segment's keys with a value that is not allowed. Requirements using label keys which are not part of the segment are assumed to match, because the CSI driver's topology keys are not necessarily the same as the node label keys used in allowedTopologies — this avoids regressions for such setups.

When the allowedTopologies of an existing storage class are changed, work items that have become impossible are removed so that their CSIStorageCapacity objects get deleted.

Which issue(s) this PR fixes:

Fixes #1162

Special notes for your reviewer:

  • onSCDelete intentionally stays unfiltered: removing a work item that was never created is a cheap no-op, and this keeps deletion robust.
  • New unit test TestSegmentCompatibleWithStorageClass covers the matching semantics (OR of terms, AND of requirements, unknown label keys), and TestCapacityController gained cases for initial filtering, filtering of newly added segments, non-segment label keys, and narrowing allowedTopologies on an update.

Does this PR introduce a user-facing change?:

The central storage capacity controller no longer creates CSIStorageCapacity objects for topology segments that are ruled out by a storage class's allowedTopologies.

@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Jul 4, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 4, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: DPS0340 / name: DPS0340 (a078361)

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @DPS0340!

It looks like this is your first PR to kubernetes-csi/external-provisioner 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-csi/external-provisioner has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @DPS0340. 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.

Regular contributors should join the org to skip this step.

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.

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 4, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from andyzhangx and gnufied July 4, 2026 13:32
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: DPS0340
Once this PR has been reviewed and has the lgtm label, please assign msau42 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

The central capacity controller used to create a work item (and with it
a CSIStorageCapacity object) for every combination of topology segment
and storage class. Combinations which are ruled out by the storage
class's allowed topologies are now skipped, which reduces the work
queue depth and the number of CSIStorageCapacity objects in clusters
where storage classes restrict provisioning to a subset of the
topology segments.

The check is conservative: a combination is only filtered out when a
topology selector term requirement uses one of the segment's keys with
a value that is not allowed. Requirements with label keys that are not
part of the segment are assumed to match, because the CSI driver's
topology keys are not necessarily the same as the node label keys used
in the allowed topologies.

When the allowed topologies of an existing storage class change, work
items which have become impossible are removed so that their
CSIStorageCapacity objects get deleted.

Fixes: kubernetes-csi#1162
@DPS0340
DPS0340 force-pushed the capacity-filter-allowed-topologies branch from a8120f5 to a078361 Compare July 4, 2026 13:38
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 4, 2026
@jsafrane

jsafrane commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 7, 2026
@DPS0340

DPS0340 commented Jul 26, 2026

Copy link
Copy Markdown
Author

@jsafrane thanks for the /ok-to-test. All jobs came back green afterwards:

unit                                    success
1-32 / 1-33 / 1-34 / 1-35 on k8s        success (4/4)
distributed on k8s 1-26 / 1-35          success (2/2)
tide                                    Not mergeable. Needs approved, lgtm labels.

So the only thing left is a review. @pohly, would you be able to take a look, or point me at whoever owns pkg/capacity these days? Not trying to rush anyone — just that tide is waiting on labels rather than on CI, and I would rather ask than let it sit.

I also confirmed it is still current: no conflicts against today's master (git merge-tree reports zero conflict markers), and go test ./pkg/capacity/... passes locally on the merge result. Happy to rebase if you would prefer a fresher base.

The one decision worth a reviewer's attention

Everything else in the diff follows from this: an unknown label key counts as a match, not as a mismatch.

A segment is skipped only when a topology selector term has a requirement for one of that segment's keys with a value the segment does not have. If allowedTopologies mentions a key the segment does not carry at all, the term is treated as satisfied.

That is deliberately the conservative direction. CSI driver topology keys are not necessarily the same as the node label keys used in allowedTopologies, so treating an unknown key as a mismatch would silently stop producing CSIStorageCapacity objects for setups that work today. Treating it as a match preserves the current behaviour and only removes combinations that are provably impossible.

TestSegmentCompatibleWithStorageClass pins that semantics directly (OR across terms, AND within a term, unknown keys match), and TestCapacityController covers the paths where it matters: initial filtering, newly appearing segments, non-segment label keys, and narrowing allowedTopologies on an existing storage class so stale objects get deleted.

One asymmetry that is intentional and easy to read as an oversight: onSCDelete stays unfiltered. Removing a work item that was never created is a cheap no-op, and keeping deletion unconditional means a filtering bug can never leave an orphaned CSIStorageCapacity behind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce CentralCapacityController workque depth by filtering allowed topologies in storage class

2 participants