@@ -803,7 +803,8 @@ func EqualPriorityMap(_ *v1.Pod, _ interface{}, nodeInfo *schedulernodeinfo.Node
803
803
// 2. A node with minimum highest priority victim is picked.
804
804
// 3. Ties are broken by sum of priorities of all victims.
805
805
// 4. If there are still ties, node with the minimum number of victims is picked.
806
- // 5. If there are still ties, the first such node is picked (sort of randomly).
806
+ // 5. If there are still ties, node with the latest start time of all highest priority victims is picked.
807
+ // 6. If there are still ties, the first such node is picked (sort of randomly).
807
808
// The 'minNodes1' and 'minNodes2' are being reused here to save the memory
808
809
// allocation and garbage collection time.
809
810
func pickOneNodeForPreemption (nodesToVictims map [* v1.Node ]* schedulerapi.Victims ) * v1.Node {
@@ -902,11 +903,44 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*schedulerapi.Victims)
902
903
lenNodes2 ++
903
904
}
904
905
}
906
+ if lenNodes2 == 1 {
907
+ return minNodes2 [0 ]
908
+ }
909
+
910
+ // There are a few nodes with same number of pods.
911
+ // Find the node that satisfies latest(earliestStartTime(all highest-priority pods on node))
912
+ latestStartTime := util .GetEarliestPodStartTime (nodesToVictims [minNodes2 [0 ]])
913
+ if latestStartTime == nil {
914
+ // If the earliest start time of all pods on the 1st node is nil, just return it,
915
+ // which is not expected to happen.
916
+ klog .Errorf ("earliestStartTime is nil for node %s. Should not reach here." , minNodes2 [0 ])
917
+ return minNodes2 [0 ]
918
+ }
919
+ lenNodes1 = 0
920
+ for i := 0 ; i < lenNodes2 ; i ++ {
921
+ node := minNodes2 [i ]
922
+ // Get earliest start time of all pods on the current node.
923
+ earliestStartTimeOnNode := util .GetEarliestPodStartTime (nodesToVictims [node ])
924
+ if earliestStartTimeOnNode == nil {
925
+ klog .Errorf ("earliestStartTime is nil for node %s. Should not reach here." , node )
926
+ continue
927
+ }
928
+ if earliestStartTimeOnNode .After (latestStartTime .Time ) {
929
+ latestStartTime = earliestStartTimeOnNode
930
+ lenNodes1 = 0
931
+ }
932
+ if earliestStartTimeOnNode .Equal (latestStartTime ) {
933
+ minNodes1 [lenNodes1 ] = node
934
+ lenNodes1 ++
935
+ }
936
+ }
937
+
905
938
// At this point, even if there are more than one node with the same score,
906
939
// return the first one.
907
- if lenNodes2 > 0 {
908
- return minNodes2 [0 ]
940
+ if lenNodes1 > 0 {
941
+ return minNodes1 [0 ]
909
942
}
943
+
910
944
klog .Errorf ("Error in logic of node scoring for preemption. We should never reach here!" )
911
945
return nil
912
946
}
0 commit comments