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.
This commit is contained in:
He Jie Xu 2020-08-25 11:23:57 +08:00
parent 14a11060a0
commit 0e8bd4c550

View File

@ -332,13 +332,15 @@ func SelectCandidate(candidates []Candidate) Candidate {
// Same as candidatesToVictimsMap, this logic is not applicable for out-of-tree // Same as candidatesToVictimsMap, this logic is not applicable for out-of-tree
// preemption plugins that exercise different candidates on the same nominated node. // preemption plugins that exercise different candidates on the same nominated node.
for _, candidate := range candidates { if victims := victimsMap[candidateNode]; victims != nil {
if candidateNode == candidate.Name() { return &candidate{
return candidate victims: victims,
name: candidateNode,
} }
} }
// We shouldn't reach here. // 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. // To not break the whole flow, return the first candidate.
return candidates[0] return candidates[0]
} }