Skip to content

Commit eb7733e

Browse files
committed
sched: Optimize anti-affinity node label check
Signed-off-by: utam0k <[email protected]>
1 parent 849a82b commit eb7733e

File tree

1 file changed

+7
-6
lines changed
  • pkg/scheduler/framework/plugins/interpodaffinity

1 file changed

+7
-6
lines changed

pkg/scheduler/framework/plugins/interpodaffinity/filtering.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,13 @@ func getPreFilterState(cycleState fwk.CycleState) (*preFilterState, error) {
351351
// terms indicated by the existing pods.
352352
func satisfyExistingPodsAntiAffinity(state *preFilterState, nodeInfo *framework.NodeInfo) bool {
353353
if len(state.existingAntiAffinityCounts) > 0 {
354-
// Iterate over topology pairs to get any of the pods being affected by
355-
// the scheduled pod anti-affinity terms
356-
for topologyKey, topologyValue := range nodeInfo.Node().Labels {
357-
tp := topologyPair{key: topologyKey, value: topologyValue}
358-
if state.existingAntiAffinityCounts[tp] > 0 {
359-
return false
354+
// Check if this node matches any anti-affinity topology pairs.
355+
nodeLabels := nodeInfo.Node().Labels
356+
for tp, count := range state.existingAntiAffinityCounts {
357+
if count > 0 {
358+
if nodeValue, ok := nodeLabels[tp.key]; ok && nodeValue == tp.value {
359+
return false
360+
}
360361
}
361362
}
362363
}

0 commit comments

Comments
 (0)