From 0e8bd4c55096567bb0d69eccc26e1f05b20625cf Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Tue, 25 Aug 2020 11:23:57 +0800 Subject: [PATCH] Initialize candidate directly instead of iterating the array of candidates Using existing victimsMap to get the victims, then it is easy to build candidate directly. --- .../plugins/defaultpreemption/default_preemption.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption.go b/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption.go index 6fd6b0dc415..ac54d49bcea 100644 --- a/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption.go +++ b/pkg/scheduler/framework/plugins/defaultpreemption/default_preemption.go @@ -332,13 +332,15 @@ func SelectCandidate(candidates []Candidate) Candidate { // Same as candidatesToVictimsMap, this logic is not applicable for out-of-tree // preemption plugins that exercise different candidates on the same nominated node. - for _, candidate := range candidates { - if candidateNode == candidate.Name() { - return candidate + if victims := victimsMap[candidateNode]; victims != nil { + return &candidate{ + victims: victims, + name: candidateNode, } } + // We shouldn't reach here. - klog.Errorf("None candidate can be picked from %v.", candidates) + klog.Errorf("should not reach here, no candidate selected from %v.", candidates) // To not break the whole flow, return the first candidate. return candidates[0] }