Skip to content

sched: InterPodAffinity plugin has inefficient node label iteration in satisfyExistingPodsAntiAffinity #132070

@utam0k

Description

@utam0k

/sig scheduling

The satisfyExistingPodsAntiAffinity function unnecessarily iterates through all node labels when checking anti-affinity constraints:

func satisfyExistingPodsAntiAffinity(state *preFilterState, nodeInfo *framework.NodeInfo) bool {
if len(state.existingAntiAffinityCounts) > 0 {
// Iterate over topology pairs to get any of the pods being affected by
// the scheduled pod anti-affinity terms
for topologyKey, topologyValue := range nodeInfo.Node().Labels {
tp := topologyPair{key: topologyKey, value: topologyValue}
if state.existingAntiAffinityCounts[tp] > 0 {
return false
}
}
}
return true
}

Instead, iterate through existingAntiAffinityCounts directly:

  nodeLabels := nodeInfo.Node().Labels
  for tp, count := range state.existingAntiAffinityCounts {
      if count > 0 {
          if nodeValue, ok := nodeLabels[tp.key]; ok && nodeValue == tp.value {
              return false
          }
      }
  }

The performance difference depends on:

  • Number of node labels (typically 10-15 on GKE, can be 20-30+ with custom labels)
  • Number of entries in existingAntiAffinityCounts

Metadata

Metadata

Assignees

Labels

sig/schedulingCategorizes an issue or PR as relevant to SIG Scheduling.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions