Skip to content

Commit

Permalink
Merge pull request kubernetes#94125 from soulxu/only_includes_all_nod…
Browse files Browse the repository at this point in the history
…es_for_preferred

Only process all nodes when incoming pod has no preferred affinity
  • Loading branch information
k8s-ci-robot authored Sep 7, 2020
2 parents 2481e88 + ccd8eb3 commit b837699
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/scheduler/framework/plugins/interpodaffinity/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b837699

Please sign in to comment.