diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go index 2420d20a58f..4a103053fe0 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go @@ -141,10 +141,11 @@ func (pl *InterPodAffinity) PreScore( affinity := pod.Spec.Affinity hasPreferredAffinityConstraints := affinity != nil && affinity.PodAffinity != nil && len(affinity.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution) > 0 hasPreferredAntiAffinityConstraints := affinity != nil && affinity.PodAntiAffinity != nil && len(affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution) > 0 + hasConstraints := hasPreferredAffinityConstraints || hasPreferredAntiAffinityConstraints // Optionally ignore calculating preferences of existing pods' affinity rules // if the incoming pod has no inter-pod affinities. - if pl.args.IgnorePreferredTermsOfExistingPods && !hasPreferredAffinityConstraints && !hasPreferredAntiAffinityConstraints { + if pl.args.IgnorePreferredTermsOfExistingPods && !hasConstraints { return framework.NewStatus(framework.Skip) } @@ -152,7 +153,7 @@ func (pl *InterPodAffinity) PreScore( // need to process nodes hosting pods with affinity. var allNodes []*framework.NodeInfo var err error - if hasPreferredAffinityConstraints || hasPreferredAntiAffinityConstraints { + if hasConstraints { allNodes, err = pl.sharedLister.NodeInfos().List() if err != nil { return framework.AsStatus(fmt.Errorf("failed to get all nodes from shared lister: %w", err)) @@ -195,7 +196,7 @@ func (pl *InterPodAffinity) PreScore( // Unless the pod being scheduled has preferred affinity terms, we only // need to process pods with affinity in the node. podsToProcess := nodeInfo.PodsWithAffinity - if hasPreferredAffinityConstraints || hasPreferredAntiAffinityConstraints { + if hasConstraints { // We need to process all the pods. podsToProcess = nodeInfo.Pods }