mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
Merge pull request #118032 from kerthcet/cleanup/interpodaffinity2
Chore: cleanup in interPodAffinity
This commit is contained in:
commit
da1b9df26c
@ -141,10 +141,11 @@ func (pl *InterPodAffinity) PreScore(
|
|||||||
affinity := pod.Spec.Affinity
|
affinity := pod.Spec.Affinity
|
||||||
hasPreferredAffinityConstraints := affinity != nil && affinity.PodAffinity != nil && len(affinity.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution) > 0
|
hasPreferredAffinityConstraints := affinity != nil && affinity.PodAffinity != nil && len(affinity.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution) > 0
|
||||||
hasPreferredAntiAffinityConstraints := affinity != nil && affinity.PodAntiAffinity != nil && len(affinity.PodAntiAffinity.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
|
// Optionally ignore calculating preferences of existing pods' affinity rules
|
||||||
// if the incoming pod has no inter-pod affinities.
|
// 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)
|
return framework.NewStatus(framework.Skip)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +153,7 @@ func (pl *InterPodAffinity) PreScore(
|
|||||||
// need to process nodes hosting pods with affinity.
|
// need to process nodes hosting pods with affinity.
|
||||||
var allNodes []*framework.NodeInfo
|
var allNodes []*framework.NodeInfo
|
||||||
var err error
|
var err error
|
||||||
if hasPreferredAffinityConstraints || hasPreferredAntiAffinityConstraints {
|
if hasConstraints {
|
||||||
allNodes, err = pl.sharedLister.NodeInfos().List()
|
allNodes, err = pl.sharedLister.NodeInfos().List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return framework.AsStatus(fmt.Errorf("failed to get all nodes from shared lister: %w", err))
|
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
|
// Unless the pod being scheduled has preferred affinity terms, we only
|
||||||
// need to process pods with affinity in the node.
|
// need to process pods with affinity in the node.
|
||||||
podsToProcess := nodeInfo.PodsWithAffinity
|
podsToProcess := nodeInfo.PodsWithAffinity
|
||||||
if hasPreferredAffinityConstraints || hasPreferredAntiAffinityConstraints {
|
if hasConstraints {
|
||||||
// We need to process all the pods.
|
// We need to process all the pods.
|
||||||
podsToProcess = nodeInfo.Pods
|
podsToProcess = nodeInfo.Pods
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user