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.
This commit is contained in:
He Jie Xu 2020-08-10 14:48:26 +08:00
parent 9b78bd5979
commit 75ccb90407

View File

@ -330,6 +330,7 @@ func satisfyExistingPodsAntiAffinity(state *preFilterState, nodeInfo *framework.
// Checks if the node satisifies the incoming pod's anti-affinity rules. // Checks if the node satisifies the incoming pod's anti-affinity rules.
func satisfyPodAntiAffinity(state *preFilterState, nodeInfo *framework.NodeInfo) bool { func satisfyPodAntiAffinity(state *preFilterState, nodeInfo *framework.NodeInfo) bool {
if len(state.topologyToMatchedAntiAffinityTerms) > 0 {
for _, term := range state.podInfo.RequiredAntiAffinityTerms { for _, term := range state.podInfo.RequiredAntiAffinityTerms {
if topologyValue, ok := nodeInfo.Node().Labels[term.TopologyKey]; ok { if topologyValue, ok := nodeInfo.Node().Labels[term.TopologyKey]; ok {
tp := topologyPair{key: term.TopologyKey, value: topologyValue} tp := topologyPair{key: term.TopologyKey, value: topologyValue}
@ -338,6 +339,7 @@ func satisfyPodAntiAffinity(state *preFilterState, nodeInfo *framework.NodeInfo)
} }
} }
} }
}
return true return true
} }