← Back to Pull requests

fix: key topology groups on the normalized label key #3307

Open
unknown opened this pull request with 563 lines diff across 7 files
View on GitHub
unknown unknown commented on Sep 08, 2026 13:41 UTC
Author

Description

NewRequirement normalizes aliased label keys, so failure-domain.beta.kubernetes.io/zone becomes topology.kubernetes.io/zone for instance (requirement.go:56, labels.go:250). Every Requirements map is therefore keyed on the normalized key, and so is domainGroups, which is built by iterating one (topology.go:119).

Topology groups, however, keep the raw key the pod declared:

// topology.go:476
NewTopologyGroup(TopologyTypeSpread, tsc.TopologyKey, ..., t.domainGroups[tsc.TopologyKey])

So a pod spreading on the beta key gets an empty domain universe, by construction, every time. AddRequirements then can't find the candidate node's domain either (the node requirements map is normalized, the group key is not), and scheduling fails outright:

unsatisfiable topology constraint for topology spread,
key=failure-domain.beta.kubernetes.io/zone (counts = ,
podDomains = topology.kubernetes.io/zone Exists,
nodeDomains = topology.kubernetes.io/zone Exists

Repro, against a NodePool spanning three zones:

topologySpreadConstraints:
  - topologyKey: failure-domain.beta.kubernetes.io/zone   # normalized alias
    maxSkew: 1
    whenUnsatisfiable: DoNotSchedule
    labelSelector: {matchLabels: {app: demo}}

The pods never schedule. Swap in topology.kubernetes.io/zone, change nothing else, and a NodeClaim is created within seconds. Confirmed on a live cluster running Karpenter v1.14 with the AWS provider, where the nodes carry both spellings of the zone label, so this is not a missing-label artifact.

The change normalizes the topology key at the three NewTopologyGroup call sites (topology spread, pod affinity/anti-affinity, inverse anti-affinity) and their domainGroups lookups, and in Register/Unregister. This covers all five entries of NormalizedLabels (beta zone, region, instance-type, arch, os), not just zone.

Node labels are still read with the group's key, with no alias fallback. kube-scheduler matches topology keys literally, so a node carrying only the beta zone label must not count as a domain for a constraint on the stable key; a fallback would add it as an empty domain and block otherwise valid placements. As a result:

  • Constraints on non-aliased keys behave exactly as before.

  • Constraints on an aliased key read the stable label from nodes. This matches kube-scheduler whenever nodes carry both spellings, which kubelet (arch, os) and the cloud-provider node controller (zone, region, instance-type) ensure. It is the same assumption Karpenter already makes when it normalizes nodeSelector and node affinity keys. On a cluster where nodes carry only one spelling, Karpenter and kube-scheduler can still disagree for such constraints. Topology spread and a pod's own (anti-)affinity on an aliased key could not schedule at all before this change; the anti-affinity of existing pods could, and a legacy-only node is no longer recognized there, which matches kube-scheduler as long as the nodes Karpenter launches don't carry the legacy label either.

  • Constraints that differ only by key spelling now share a topology group.

  • A TSC on the beta zone key now participates in GetTopologyZoneConstraints, so it is reflected in the PendingPodsByEffectiveZone metric.
  • How was this change tested?

    Three new specs in topology_test.go:

  • Zonal: four pods spread on the beta zone key, asserting a 1/1/2 skew over the stable key. Fails on main with the error above, passes with this change.

  • Zonal: a node labeled only with the beta zone key, in a zone outside the NodePool, must not block a stable-key spread over the other zones. Passes on main, and guards against matching node labels through aliases.

  • Pod Affinity/Anti-Affinity: pods with required anti-affinity on the beta zone key schedule exactly as they do on the stable key. Fails on main with an unsatisfiable anti-affinity constraint.
  • Full make test green.

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    Diff: 563 lines (+422 / -141) across 7 files Reviewer: semx Review duration: 52133m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.57) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 563 lines diff across 7 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    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.379
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3307"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% 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: 56.7% (MEDIUM) · Higher = larger blast radius
    56.7%
    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: 44.7% · Lower = rushed or shallow review
    44.7%
    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: 31.4% · Safe to merge
    31.4%