Skip to content

Commit 3e65b37

Browse files
committed
Cleanup failedPredicateMap from generic_scheduler.go
1 parent 4ff6928 commit 3e65b37

File tree

4 files changed

+89
-139
lines changed

4 files changed

+89
-139
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
}
@@ -210,7 +199,7 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
210199
trace.Step("Running prefilter plugins done")
211200

212201
startPredicateEvalTime := time.Now()
213-
filteredNodes, failedPredicateMap, filteredNodesStatuses, err := g.findNodesThatFit(ctx, state, pod)
202+
filteredNodes, filteredNodesStatuses, err := g.findNodesThatFit(ctx, state, pod)
214203
if err != nil {
215204
return result, err
216205
}
@@ -226,7 +215,6 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
226215
return result, &FitError{
227216
Pod: pod,
228217
NumAllNodes: len(g.nodeInfoSnapshot.NodeInfoList),
229-
FailedPredicates: failedPredicateMap,
230218
FilteredNodesStatuses: filteredNodesStatuses,
231219
}
232220
}
@@ -243,7 +231,7 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
243231
metrics.DeprecatedSchedulingAlgorithmPriorityEvaluationDuration.Observe(metrics.SinceInMicroseconds(startPriorityEvalTime))
244232
return ScheduleResult{
245233
SuggestedHost: filteredNodes[0].Name,
246-
EvaluatedNodes: 1 + len(failedPredicateMap) + len(filteredNodesStatuses),
234+
EvaluatedNodes: 1 + len(filteredNodesStatuses),
247235
FeasibleNodes: 1,
248236
}, nil
249237
}
@@ -264,7 +252,7 @@ func (g *genericScheduler) Schedule(ctx context.Context, state *framework.CycleS
264252

265253
return ScheduleResult{
266254
SuggestedHost: host,
267-
EvaluatedNodes: len(filteredNodes) + len(failedPredicateMap) + len(filteredNodesStatuses),
255+
EvaluatedNodes: len(filteredNodes) + len(filteredNodesStatuses),
268256
FeasibleNodes: len(filteredNodes),
269257
}, err
270258
}
@@ -471,10 +459,8 @@ func (g *genericScheduler) numFeasibleNodesToFind(numAllNodes int32) (numNodes i
471459

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

480466
if !g.framework.HasFilterPlugins() {
@@ -497,7 +483,7 @@ func (g *genericScheduler) findNodesThatFit(ctx context.Context, state *framewor
497483
// We check the nodes starting from where we left off in the previous scheduling cycle,
498484
// this is to make sure all nodes have the same chance of being examined across pods.
499485
nodeInfo := g.nodeInfoSnapshot.NodeInfoList[(g.nextStartNodeIndex+i)%allNodes]
500-
fits, _, status, err := g.podFitsOnNode(ctx, state, pod, nodeInfo)
486+
fits, status, err := g.podFitsOnNode(ctx, state, pod, nodeInfo)
501487
if err != nil {
502488
errCh.SendErrorWithCancel(err, cancel)
503489
return
@@ -522,12 +508,12 @@ func (g *genericScheduler) findNodesThatFit(ctx context.Context, state *framewor
522508
// Stops searching for more nodes once the configured number of feasible nodes
523509
// are found.
524510
workqueue.ParallelizeUntil(ctx, 16, allNodes, checkNode)
525-
processedNodes := int(filteredLen) + len(filteredNodesStatuses) + len(failedPredicateMap)
511+
processedNodes := int(filteredLen) + len(filteredNodesStatuses)
526512
g.nextStartNodeIndex = (g.nextStartNodeIndex + processedNodes) % allNodes
527513

528514
filtered = filtered[:filteredLen]
529515
if err := errCh.ReceiveError(); err != nil {
530-
return []*v1.Node{}, FailedPredicateMap{}, framework.NodeToStatusMap{}, err
516+
return []*v1.Node{}, framework.NodeToStatusMap{}, err
531517
}
532518
}
533519

@@ -544,23 +530,23 @@ func (g *genericScheduler) findNodesThatFit(ctx context.Context, state *framewor
544530
continue
545531
}
546532

547-
return []*v1.Node{}, FailedPredicateMap{}, framework.NodeToStatusMap{}, err
533+
return []*v1.Node{}, framework.NodeToStatusMap{}, err
548534
}
549535

550-
// TODO(Huang-Wei): refactor this to fill 'filteredNodesStatuses' instead of 'failedPredicateMap'.
551536
for failedNodeName, failedMsg := range failedMap {
552-
if _, found := failedPredicateMap[failedNodeName]; !found {
553-
failedPredicateMap[failedNodeName] = []predicates.PredicateFailureReason{}
537+
if _, found := filteredNodesStatuses[failedNodeName]; !found {
538+
filteredNodesStatuses[failedNodeName] = framework.NewStatus(framework.Unschedulable, failedMsg)
539+
} else {
540+
filteredNodesStatuses[failedNodeName].AppendReason(failedMsg)
554541
}
555-
failedPredicateMap[failedNodeName] = append(failedPredicateMap[failedNodeName], predicates.NewPredicateFailureError(extender.Name(), failedMsg))
556542
}
557543
filtered = filteredList
558544
if len(filtered) == 0 {
559545
break
560546
}
561547
}
562548
}
563-
return filtered, failedPredicateMap, filteredNodesStatuses, nil
549+
return filtered, filteredNodesStatuses, nil
564550
}
565551

566552
// addNominatedPods adds pods with equal or greater priority which are nominated
@@ -607,8 +593,7 @@ func (g *genericScheduler) podFitsOnNode(
607593
state *framework.CycleState,
608594
pod *v1.Pod,
609595
info *schedulernodeinfo.NodeInfo,
610-
) (bool, []predicates.PredicateFailureReason, *framework.Status, error) {
611-
var failedPredicates []predicates.PredicateFailureReason
596+
) (bool, *framework.Status, error) {
612597
var status *framework.Status
613598

614599
podsAdded := false
@@ -637,19 +622,19 @@ func (g *genericScheduler) podFitsOnNode(
637622
var err error
638623
podsAdded, stateToUse, nodeInfoToUse, err = g.addNominatedPods(ctx, pod, state, info)
639624
if err != nil {
640-
return false, []predicates.PredicateFailureReason{}, nil, err
625+
return false, nil, err
641626
}
642-
} else if !podsAdded || len(failedPredicates) != 0 || !status.IsSuccess() {
627+
} else if !podsAdded || !status.IsSuccess() {
643628
break
644629
}
645630

646631
status = g.framework.RunFilterPlugins(ctx, stateToUse, pod, nodeInfoToUse)
647632
if !status.IsSuccess() && !status.IsUnschedulable() {
648-
return false, failedPredicates, status, status.AsError()
633+
return false, status, status.AsError()
649634
}
650635
}
651636

652-
return len(failedPredicates) == 0 && status.IsSuccess(), failedPredicates, status, nil
637+
return status.IsSuccess(), status, nil
653638
}
654639

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

0 commit comments

Comments
 (0)