Merge pull request #118032 from kerthcet/cleanup/interpodaffinity2

Chore: cleanup in interPodAffinity
This commit is contained in:
Kubernetes Prow Robot 2023-05-17 14:00:33 -07:00 committed by GitHub
commit da1b9df26c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}