From ccd8eb3b1b84b4573206768333b18f4eab42e460 Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Thu, 20 Aug 2020 15:28:35 +0800 Subject: [PATCH] Only process all nodes when incoming pod has no preferred affinity Currently, in interpodaffinty plugin, it only processes all nodes when the incoming pod with affinity. Actually, it only cares about all nodes when the incoming pod with preferred affinity. Then it will reduces the number of nodes need to be processed. --- .../framework/plugins/interpodaffinity/scoring.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go index c27ae5f41ef5d..06fee90b98b26 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go @@ -141,14 +141,14 @@ func (pl *InterPodAffinity) PreScore( } affinity := pod.Spec.Affinity - hasAffinityConstraints := affinity != nil && affinity.PodAffinity != nil - hasAntiAffinityConstraints := affinity != nil && affinity.PodAntiAffinity != nil + hasPreferredAffinityConstraints := affinity != nil && affinity.PodAffinity != nil && len(affinity.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution) > 0 + hasPreferredAntiAffinityConstraints := affinity != nil && affinity.PodAntiAffinity != nil && len(affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution) > 0 - // Unless the pod being scheduled has affinity terms, we only + // Unless the pod being scheduled has preferred affinity terms, we only // need to process nodes hosting pods with affinity. var allNodes []*framework.NodeInfo var err error - if hasAffinityConstraints || hasAntiAffinityConstraints { + if hasPreferredAffinityConstraints || hasPreferredAntiAffinityConstraints { allNodes, err = pl.sharedLister.NodeInfos().List() if err != nil { framework.NewStatus(framework.Error, fmt.Sprintf("get all nodes from shared lister error, err: %v", err)) @@ -178,10 +178,10 @@ func (pl *InterPodAffinity) PreScore( if nodeInfo.Node() == nil { return } - // Unless the pod being scheduled has affinity terms, we only + // Unless the pod being scheduled has preferred affinity terms, we only // need to process pods with affinity in the node. podsToProcess := nodeInfo.PodsWithAffinity - if hasAffinityConstraints || hasAntiAffinityConstraints { + if hasPreferredAffinityConstraints || hasPreferredAntiAffinityConstraints { // We need to process all the pods. podsToProcess = nodeInfo.Pods }