fix: allow empty-string topology spread domains #3317
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/karpenter/pull/3317#" title="Author self-approved">maxcao13</a>
Once this PR has been reviewed and has the lgtm label, please assign engedaam 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":["engedaam"]} -->
/cc @DerekFrank
this is the simple proposed fix after talking about issue in the wg on sept 10, 2026.
PTAL and please tag anyone anyone else that needs to review/be aware, thanks!
Read nextDomainTopologySpread on main and reproduced both new specs failing there.
minDomain starts as "" and is assigned in the same branch that inserts into validDomains, with minCount starting at MaxInt32, so validDomains.Len() == 0 is exactly "no domain selected" and no longer conflates a legitimately selected "". domainMinCount and TopologyGroup.Register do not special-case "".In [""] requirement is valid downstream: the NodeClaim CRD values pattern ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$ accepts the empty string and validation.IsValidLabelValue("") returns no errors (nodeclaim_validation.go:136). envtest applied the real CRDs, so the NodePool template label with an empty value is accepted too.nodeDomains = topology.example.com/role In [] and pass here; full package green with -race.One nit: the deleted comment explained why the old check existed. A one-line replacement saying that "" is a valid domain value would keep someone from reintroducing the minDomain == "" check later.
LGTM too
added a comment explaining the change, PTAL!
/cc @jmdeal
semx
maxcao13
Fixes #3146
Description
When a topology spread constraint uses a label whose value is the empty string (e.g.
node-role.kubernetes.io/worker: ""), Karpenter registers that domain butnextDomainTopologySpreadtreatsminDomain == ""as failure and returnsDoesNotExist. Pods withwhenUnsatisfiable: DoNotSchedulestay pending even though the domain is valid and has headroom undermaxSkew.The fix checks
validDomains.Len() == 0as the failure condition instead. An empty string is a legitimate domain value since a domain is effectively defined as a<key, value>pair (i.e. a label), and according to official Kubernetes docs, a label value is entirely valid to be an empty string.After this fix, we still continue to accept that the _absence_ of any valid domain (including domains with empty string value) should still produce
DoesNotExist.How was this change tested?
Added two unit tests in topology_test.go:
Provisions 2 pods with a TSC on a custom label where the only domain is
"". Before the fix, both pods stayed pending. After, both schedule to that domain (skew: [2]).Provisions 4 pods with a TSC across two
NodePools: one with domain"", one with domain"worker". Verifies pods spread evenly across both (skew: [2, 2]).By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.