Skip to content

Commit 370e2f4

Browse files
authored
Merge pull request kubernetes#85862 from ahg-g/ahg-antiAffinity
Partially avoid LabelSelectorAsSelector overhead in anti-pod affinity calculation
2 parents ca7ad98 + 2d3c8fe commit 370e2f4

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

pkg/scheduler/algorithm/predicates/metadata.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ func getTPMapMatchingIncomingAffinityAntiAffinity(pod *v1.Pod, allNodes []*sched
780780
return newTopologyPairsMaps(), newTopologyPairsMaps(), nil
781781
}
782782

783-
errCh := schedutil.NewErrorChannel()
784783
var lock sync.Mutex
785784
topologyPairsAffinityPodsMaps = newTopologyPairsMaps()
786785
topologyPairsAntiAffinityPodsMaps = newTopologyPairsMaps()
@@ -802,8 +801,10 @@ func getTPMapMatchingIncomingAffinityAntiAffinity(pod *v1.Pod, allNodes []*sched
802801
}
803802

804803
antiAffinityTerms := GetPodAntiAffinityTerms(affinity.PodAntiAffinity)
805-
806-
ctx, cancel := context.WithCancel(context.Background())
804+
antiAffinityProperties, err := getAffinityTermProperties(pod, antiAffinityTerms)
805+
if err != nil {
806+
return nil, nil, err
807+
}
807808

808809
processNode := func(i int) {
809810
nodeInfo := allNodes[i]
@@ -825,14 +826,9 @@ func getTPMapMatchingIncomingAffinityAntiAffinity(pod *v1.Pod, allNodes []*sched
825826
}
826827
}
827828
// Check anti-affinity properties.
828-
for _, term := range antiAffinityTerms {
829-
namespaces := priorityutil.GetNamespacesFromPodAffinityTerm(pod, &term)
830-
selector, err := metav1.LabelSelectorAsSelector(term.LabelSelector)
831-
if err != nil {
832-
errCh.SendErrorWithCancel(err, cancel)
833-
return
834-
}
835-
if priorityutil.PodMatchesTermsNamespaceAndSelector(existingPod, namespaces, selector) {
829+
for i, term := range antiAffinityTerms {
830+
p := antiAffinityProperties[i]
831+
if priorityutil.PodMatchesTermsNamespaceAndSelector(existingPod, p.namespaces, p.selector) {
836832
if topologyValue, ok := node.Labels[term.TopologyKey]; ok {
837833
pair := topologyPair{key: term.TopologyKey, value: topologyValue}
838834
nodeTopologyPairsAntiAffinityPodsMaps.addTopologyPair(pair, existingPod)
@@ -845,11 +841,7 @@ func getTPMapMatchingIncomingAffinityAntiAffinity(pod *v1.Pod, allNodes []*sched
845841
appendResult(node.Name, nodeTopologyPairsAffinityPodsMaps, nodeTopologyPairsAntiAffinityPodsMaps)
846842
}
847843
}
848-
workqueue.ParallelizeUntil(ctx, 16, len(allNodes), processNode)
849-
850-
if err := errCh.ReceiveError(); err != nil {
851-
return nil, nil, err
852-
}
844+
workqueue.ParallelizeUntil(context.Background(), 16, len(allNodes), processNode)
853845

854846
return topologyPairsAffinityPodsMaps, topologyPairsAntiAffinityPodsMaps, nil
855847
}

0 commit comments

Comments
 (0)