Skip to content

Commit ff975e8

Browse files
authored
Merge pull request kubernetes#86498 from Huang-Wei/deprecate-failedPredicateMap
Cleanup failedPredicateMap from generic_scheduler.go
2 parents a81bc56 + 3e65b37 commit ff975e8

File tree

4 files changed

+89
-138
lines changed

4 files changed

+89
-138
lines changed

pkg/scheduler/core/generic_scheduler.go

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,10 @@ const (
6666
minFeasibleNodesPercentageToFind = 5
6767
)
6868

69-
// FailedPredicateMap declares a map[string][]algorithm.PredicateFailureReason type.
70-
type FailedPredicateMap map[string][]predicates.PredicateFailureReason
71-
7269
// FitError describes a fit error of a pod.
7370
type FitError struct {
74-
Pod *v1.Pod
75-
NumAllNodes int
76-
// TODO(Huang-Wei): remove 'FailedPredicates'
77-
FailedPredicates FailedPredicateMap
71+
Pod *v1.Pod
72+
NumAllNodes int
7873
FilteredNodesStatuses framework.NodeToStatusMap
7974
}
8075

@@ -89,20 +84,14 @@ const (
8984
// Error returns detailed information of why the pod failed to fit on each node
9085
func (f *FitError) Error() string {
9186
reasons := make(map[string]int)
92-
for _, predicates := range f.FailedPredicates {
93-
for _, pred := range predicates {
94-
reasons[pred.GetReason()]++
95-
}
96-
}
97-
9887
for _, status := range f.FilteredNodesStatuses {
9988
for _, reason := range status.Reasons() {
10089
reasons[reason]++
10190
}
10291
}
10392

10493
sortReasonsHistogram := func() []string {
105-
reasonStrings := []string{}
94+
var reasonStrings []string
10695
for k, v := range reasons {
10796
reasonStrings = append(reasonStrings, fmt.Sprintf("%v %v", v, k))
10897
}
@@ -209,7 +198,7 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
209198
trace.Step("Running prefilter plugins done")
210199

211200
startPredicateEvalTime := time.Now()
212-
filteredNodes, failedPredicateMap, filteredNodesStatuses, err := g.findNodesThatFit(ctx, state, pod)
201+
filteredNodes, filteredNodesStatuses, err := g.findNodesThatFit(ctx, state, pod)
213202
if err != nil {
214203
return result, err
215204
}
@@ -225,7 +214,6 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
225214
return result, &FitError{
226215
Pod: pod,
227216
NumAllNodes: len(g.nodeInfoSnapshot.NodeInfoList),
228-
FailedPredicates: failedPredicateMap,
229217
FilteredNodesStatuses: filteredNodesStatuses,
230218
}
231219
}
@@ -242,7 +230,7 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
242230
metrics.DeprecatedSchedulingAlgorithmPriorityEvaluationDuration.Observe(metrics.SinceInMicroseconds(startPriorityEvalTime))
243231
return ScheduleResult{
244232
SuggestedHost: filteredNodes[0].Name,
245-
EvaluatedNodes: 1 + len(failedPredicateMap) + len(filteredNodesStatuses),
233+
EvaluatedNodes: 1 + len(filteredNodesStatuses),
246234
FeasibleNodes: 1,
247235
}, nil
248236
}
@@ -263,7 +251,7 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
263251

264252
return ScheduleResult{
265253
SuggestedHost: host,
266-
EvaluatedNodes: len(filteredNodes) + len(failedPredicateMap) + len(filteredNodesStatuses),
254+
EvaluatedNodes: len(filteredNodes) + len(filteredNodesStatuses),
267255
FeasibleNodes: len(filteredNodes),
268256
}, err
269257
}
@@ -470,10 +458,8 @@ func (g *genericScheduler) numFeasibleNodesToFind(numAllNodes int32) (numNodes i
470458

471459
// Filters the nodes to find the ones that fit based on the given predicate functions
472460
// Each node is passed through the predicate functions to determine if it is a fit
473-
// TODO(Huang-Wei): remove 'FailedPredicateMap' from the return parameters.
474-
func (g *genericScheduler) findNodesThatFit(ctx context.Context, state *framework.CycleState, pod *v1.Pod) ([]*v1.Node, FailedPredicateMap, framework.NodeToStatusMap, error) {
461+
func (g *genericScheduler) findNodesThatFit(ctx context.Context, state *framework.CycleState, pod *v1.Pod) ([]*v1.Node, framework.NodeToStatusMap, error) {
475462
var filtered []*v1.Node
476-
failedPredicateMap := FailedPredicateMap{}
477463
filteredNodesStatuses := framework.NodeToStatusMap{}
478464

479465
if !g.framework.HasFilterPlugins() {
@@ -496,7 +482,7 @@ func (g *genericScheduler) findNodesThatFit(ctx context.Context, state *framewor
496482
// We check the nodes starting from where we left off in the previous scheduling cycle,
497483
// this is to make sure all nodes have the same chance of being examined across pods.
498484
nodeInfo := g.nodeInfoSnapshot.NodeInfoList[(g.nextStartNodeIndex+i)%allNodes]
499-
fits, _, status, err := g.podFitsOnNode(ctx, state, pod, nodeInfo)
485+
fits, status, err := g.podFitsOnNode(ctx, state, pod, nodeInfo)
500486
if err != nil {
501487
errCh.SendErrorWithCancel(err, cancel)
502488
return
@@ -521,12 +507,12 @@ func (g *genericScheduler) findNodesThatFit(ctx context.Context, state *framewor
521507
// Stops searching for more nodes once the configured number of feasible nodes
522508
// are found.
523509
workqueue.ParallelizeUntil(ctx, 16, allNodes, checkNode)
524-
processedNodes := int(filteredLen) + len(filteredNodesStatuses) + len(failedPredicateMap)
510+
processedNodes := int(filteredLen) + len(filteredNodesStatuses)
525511
g.nextStartNodeIndex = (g.nextStartNodeIndex + processedNodes) % allNodes
526512

527513
filtered = filtered[:filteredLen]
528514
if err := errCh.ReceiveError(); err != nil {
529-
return []*v1.Node{}, FailedPredicateMap{}, framework.NodeToStatusMap{}, err
515+
return []*v1.Node{}, framework.NodeToStatusMap{}, err
530516
}
531517
}
532518

@@ -543,23 +529,23 @@ func (g *genericScheduler) findNodesThatFit(ctx context.Context, state *framewor
543529
continue
544530
}
545531

546-
return []*v1.Node{}, FailedPredicateMap{}, framework.NodeToStatusMap{}, err
532+
return []*v1.Node{}, framework.NodeToStatusMap{}, err
547533
}
548534

549-
// TODO(Huang-Wei): refactor this to fill 'filteredNodesStatuses' instead of 'failedPredicateMap'.
550535
for failedNodeName, failedMsg := range failedMap {
551-
if _, found := failedPredicateMap[failedNodeName]; !found {
552-
failedPredicateMap[failedNodeName] = []predicates.PredicateFailureReason{}
536+
if _, found := filteredNodesStatuses[failedNodeName]; !found {
537+
filteredNodesStatuses[failedNodeName] = framework.NewStatus(framework.Unschedulable, failedMsg)
538+
} else {
539+
filteredNodesStatuses[failedNodeName].AppendReason(failedMsg)
553540
}
554-
failedPredicateMap[failedNodeName] = append(failedPredicateMap[failedNodeName], predicates.NewPredicateFailureError(extender.Name(), failedMsg))
555541
}
556542
filtered = filteredList
557543
if len(filtered) == 0 {
558544
break
559545
}
560546
}
561547
}
562-
return filtered, failedPredicateMap, filteredNodesStatuses, nil
548+
return filtered, filteredNodesStatuses, nil
563549
}
564550

565551
// addNominatedPods adds pods with equal or greater priority which are nominated
@@ -606,8 +592,7 @@ func (g *genericScheduler) podFitsOnNode(
606592
state *framework.CycleState,
607593
pod *v1.Pod,
608594
info *schedulernodeinfo.NodeInfo,
609-
) (bool, []predicates.PredicateFailureReason, *framework.Status, error) {
610-
var failedPredicates []predicates.PredicateFailureReason
595+
) (bool, *framework.Status, error) {
611596
var status *framework.Status
612597

613598
podsAdded := false
@@ -636,19 +621,19 @@ func (g *genericScheduler) podFitsOnNode(
636621
var err error
637622
podsAdded, stateToUse, nodeInfoToUse, err = g.addNominatedPods(ctx, pod, state, info)
638623
if err != nil {
639-
return false, []predicates.PredicateFailureReason{}, nil, err
624+
return false, nil, err
640625
}
641-
} else if !podsAdded || len(failedPredicates) != 0 || !status.IsSuccess() {
626+
} else if !podsAdded || !status.IsSuccess() {
642627
break
643628
}
644629

645630
status = g.framework.RunFilterPlugins(ctx, stateToUse, pod, nodeInfoToUse)
646631
if !status.IsSuccess() && !status.IsUnschedulable() {
647-
return false, failedPredicates, status, status.AsError()
632+
return false, status, status.AsError()
648633
}
649634
}
650635

651-
return len(failedPredicates) == 0 && status.IsSuccess(), failedPredicates, status, nil
636+
return status.IsSuccess(), status, nil
652637
}
653638

654639
// prioritizeNodes prioritizes the nodes by running the score plugins,
@@ -1011,7 +996,7 @@ func (g *genericScheduler) selectVictimsOnNode(
1011996
// inter-pod affinity to one or more victims, but we have decided not to
1012997
// support this case for performance reasons. Having affinity to lower
1013998
// priority pods is not a recommended configuration anyway.
1014-
if fits, _, _, err := g.podFitsOnNode(ctx, state, pod, nodeInfo); !fits {
999+
if fits, _, err := g.podFitsOnNode(ctx, state, pod, nodeInfo); !fits {
10151000
if err != nil {
10161001
klog.Warningf("Encountered error while selecting victims on node %v: %v", nodeInfo.Node().Name, err)
10171002
}
@@ -1029,7 +1014,7 @@ func (g *genericScheduler) selectVictimsOnNode(
10291014
if err := addPod(p); err != nil {
10301015
return false, err
10311016
}
1032-
fits, _, _, _ := g.podFitsOnNode(ctx, state, pod, nodeInfo)
1017+
fits, _, _ := g.podFitsOnNode(ctx, state, pod, nodeInfo)
10331018
if !fits {
10341019
if err := removePod(p); err != nil {
10351020
return false, err
@@ -1060,22 +1045,15 @@ func (g *genericScheduler) selectVictimsOnNode(
10601045
// nodesWherePreemptionMightHelp returns a list of nodes with failed predicates
10611046
// that may be satisfied by removing pods from the node.
10621047
func nodesWherePreemptionMightHelp(nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo, fitErr *FitError) []*v1.Node {
1063-
potentialNodes := []*v1.Node{}
1048+
var potentialNodes []*v1.Node
10641049
for name, node := range nodeNameToInfo {
1050+
// We reply on the status by each plugin - 'Unschedulable' or 'UnschedulableAndUnresolvable'
1051+
// to determine whether preemption may help or not on the node.
10651052
if fitErr.FilteredNodesStatuses[name].Code() == framework.UnschedulableAndUnresolvable {
10661053
continue
10671054
}
1068-
failedPredicates := fitErr.FailedPredicates[name]
1069-
1070-
// If we assume that scheduler looks at all nodes and populates the failedPredicateMap
1071-
// (which is the case today), the !found case should never happen, but we'd prefer
1072-
// to rely less on such assumptions in the code when checking does not impose
1073-
// significant overhead.
1074-
// Also, we currently assume all failures returned by extender as resolvable.
1075-
if !predicates.UnresolvablePredicateExists(failedPredicates) {
1076-
klog.V(3).Infof("Node %v is a potential node for preemption.", name)
1077-
potentialNodes = append(potentialNodes, node.Node())
1078-
}
1055+
klog.V(3).Infof("Node %v is a potential node for preemption.", name)
1056+
potentialNodes = append(potentialNodes, node.Node())
10791057
}
10801058
return potentialNodes
10811059
}

0 commit comments

Comments
 (0)