Pick pods for preemption based on StartTime of pods when priorities are equal

This commit is contained in:
Jun Gong
2019-03-20 21:11:26 +08:00
parent e7eb742c19
commit 042b83ba73
4 changed files with 26 additions and 7 deletions

View File

@@ -134,9 +134,15 @@ func (l *SortableList) Sort() {
sort.Sort(l)
}
// HigherPriorityPod return true when priority of the first pod is higher than
// the second one. It takes arguments of the type "interface{}" to be used with
// SortableList, but expects those arguments to be *v1.Pod.
func HigherPriorityPod(pod1, pod2 interface{}) bool {
return GetPodPriority(pod1.(*v1.Pod)) > GetPodPriority(pod2.(*v1.Pod))
// MoreImportantPod return true when priority of the first pod is higher than
// the second one. If two pods' priorities are equal, compare their StartTime.
// It takes arguments of the type "interface{}" to be used with SortableList,
// but expects those arguments to be *v1.Pod.
func MoreImportantPod(pod1, pod2 interface{}) bool {
p1 := GetPodPriority(pod1.(*v1.Pod))
p2 := GetPodPriority(pod2.(*v1.Pod))
if p1 != p2 {
return p1 > p2
}
return GetPodStartTime(pod1.(*v1.Pod)).Before(GetPodStartTime(pod2.(*v1.Pod)))
}