Skip to content

Commit 75ccb90

Browse files
committed
Fast return when no any matched anti-affinity terms
When check the incoming pod's anti-affinity rules, there is change to return early when there is no any matched anti-affinity terms in the whole cluster.
1 parent 9b78bd5 commit 75ccb90

File tree

1 file changed

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

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,13 @@ func satisfyExistingPodsAntiAffinity(state *preFilterState, nodeInfo *framework.
330330

331331
// Checks if the node satisifies the incoming pod's anti-affinity rules.
332332
func satisfyPodAntiAffinity(state *preFilterState, nodeInfo *framework.NodeInfo) bool {
333-
for _, term := range state.podInfo.RequiredAntiAffinityTerms {
334-
if topologyValue, ok := nodeInfo.Node().Labels[term.TopologyKey]; ok {
335-
tp := topologyPair{key: term.TopologyKey, value: topologyValue}
336-
if state.topologyToMatchedAntiAffinityTerms[tp] > 0 {
337-
return false
333+
if len(state.topologyToMatchedAntiAffinityTerms) > 0 {
334+
for _, term := range state.podInfo.RequiredAntiAffinityTerms {
335+
if topologyValue, ok := nodeInfo.Node().Labels[term.TopologyKey]; ok {
336+
tp := topologyPair{key: term.TopologyKey, value: topologyValue}
337+
if state.topologyToMatchedAntiAffinityTerms[tp] > 0 {
338+
return false
339+
}
338340
}
339341
}
340342
}

0 commit comments

Comments
 (0)