Merge pull request #75703 from tedyu/master

Simplify the loop for latest start time in pickOneNodeForPreemption
This commit is contained in:
Kubernetes Prow Robot 2019-04-01 13:18:58 -07:00 committed by GitHub
commit 1ac4cc7980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -916,8 +916,8 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*schedulerapi.Victims)
klog.Errorf("earliestStartTime is nil for node %s. Should not reach here.", minNodes2[0]) klog.Errorf("earliestStartTime is nil for node %s. Should not reach here.", minNodes2[0])
return minNodes2[0] return minNodes2[0]
} }
lenNodes1 = 0 nodeToReturn := minNodes2[0]
for i := 0; i < lenNodes2; i++ { for i := 1; i < lenNodes2; i++ {
node := minNodes2[i] node := minNodes2[i]
// Get earliest start time of all pods on the current node. // Get earliest start time of all pods on the current node.
earliestStartTimeOnNode := util.GetEarliestPodStartTime(nodesToVictims[node]) earliestStartTimeOnNode := util.GetEarliestPodStartTime(nodesToVictims[node])
@ -927,22 +927,11 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*schedulerapi.Victims)
} }
if earliestStartTimeOnNode.After(latestStartTime.Time) { if earliestStartTimeOnNode.After(latestStartTime.Time) {
latestStartTime = earliestStartTimeOnNode latestStartTime = earliestStartTimeOnNode
lenNodes1 = 0 nodeToReturn = node
}
if earliestStartTimeOnNode.Equal(latestStartTime) {
minNodes1[lenNodes1] = node
lenNodes1++
} }
} }
// At this point, even if there are more than one node with the same score, return nodeToReturn
// return the first one.
if lenNodes1 > 0 {
return minNodes1[0]
}
klog.Errorf("Error in logic of node scoring for preemption. We should never reach here!")
return nil
} }
// selectNodesForPreemption finds all the nodes with possible victims for // selectNodesForPreemption finds all the nodes with possible victims for