mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #75510 from hex108/starttime
Pick pods for preemption based on StartTime of pods when priorities a…
This commit is contained in:
commit
da7af5897c
@ -197,7 +197,7 @@ func (f *FakeExtender) selectVictimsOnNodeByExtender(
|
|||||||
// and get cached node info by given node name.
|
// and get cached node info by given node name.
|
||||||
nodeInfoCopy := f.cachedNodeNameToInfo[node.GetName()].Clone()
|
nodeInfoCopy := f.cachedNodeNameToInfo[node.GetName()].Clone()
|
||||||
|
|
||||||
potentialVictims := util.SortableList{CompFunc: util.HigherPriorityPod}
|
potentialVictims := util.SortableList{CompFunc: util.MoreImportantPod}
|
||||||
|
|
||||||
removePod := func(rp *v1.Pod) {
|
removePod := func(rp *v1.Pod) {
|
||||||
nodeInfoCopy.RemovePod(rp)
|
nodeInfoCopy.RemovePod(rp)
|
||||||
|
@ -1046,7 +1046,7 @@ func selectVictimsOnNode(
|
|||||||
if nodeInfo == nil {
|
if nodeInfo == nil {
|
||||||
return nil, 0, false
|
return nil, 0, false
|
||||||
}
|
}
|
||||||
potentialVictims := util.SortableList{CompFunc: util.HigherPriorityPod}
|
potentialVictims := util.SortableList{CompFunc: util.MoreImportantPod}
|
||||||
nodeInfoCopy := nodeInfo.Clone()
|
nodeInfoCopy := nodeInfo.Clone()
|
||||||
|
|
||||||
removePod := func(rp *v1.Pod) {
|
removePod := func(rp *v1.Pod) {
|
||||||
|
@ -946,6 +946,19 @@ func TestSelectNodesForPreemption(t *testing.T) {
|
|||||||
{ObjectMeta: metav1.ObjectMeta{Name: "e", UID: types.UID("e")}, Spec: v1.PodSpec{Containers: largeContainers, Priority: &highPriority, NodeName: "machine2"}}},
|
{ObjectMeta: metav1.ObjectMeta{Name: "e", UID: types.UID("e")}, Spec: v1.PodSpec{Containers: largeContainers, Priority: &highPriority, NodeName: "machine2"}}},
|
||||||
expected: map[string]map[string]bool{"machine1": {"b": true, "c": true}},
|
expected: map[string]map[string]bool{"machine1": {"b": true, "c": true}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "mixed priority pods are preempted, pick later StartTime one when priorities are equal",
|
||||||
|
predicates: map[string]algorithmpredicates.FitPredicate{"matches": algorithmpredicates.PodFitsResources},
|
||||||
|
nodes: []string{"machine1", "machine2"},
|
||||||
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "machine1", UID: types.UID("machine1")}, Spec: v1.PodSpec{Containers: largeContainers, Priority: &highPriority}},
|
||||||
|
pods: []*v1.Pod{
|
||||||
|
{ObjectMeta: metav1.ObjectMeta{Name: "a", UID: types.UID("a")}, Spec: v1.PodSpec{Containers: smallContainers, Priority: &lowPriority, NodeName: "machine1"}, Status: v1.PodStatus{StartTime: &startTime20190107}},
|
||||||
|
{ObjectMeta: metav1.ObjectMeta{Name: "b", UID: types.UID("b")}, Spec: v1.PodSpec{Containers: smallContainers, Priority: &lowPriority, NodeName: "machine1"}, Status: v1.PodStatus{StartTime: &startTime20190106}},
|
||||||
|
{ObjectMeta: metav1.ObjectMeta{Name: "c", UID: types.UID("c")}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}, Status: v1.PodStatus{StartTime: &startTime20190105}},
|
||||||
|
{ObjectMeta: metav1.ObjectMeta{Name: "d", UID: types.UID("d")}, Spec: v1.PodSpec{Containers: smallContainers, Priority: &highPriority, NodeName: "machine1"}, Status: v1.PodStatus{StartTime: &startTime20190104}},
|
||||||
|
{ObjectMeta: metav1.ObjectMeta{Name: "e", UID: types.UID("e")}, Spec: v1.PodSpec{Containers: largeContainers, Priority: &highPriority, NodeName: "machine2"}, Status: v1.PodStatus{StartTime: &startTime20190103}}},
|
||||||
|
expected: map[string]map[string]bool{"machine1": {"a": true, "c": true}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "pod with anti-affinity is preempted",
|
name: "pod with anti-affinity is preempted",
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"matches": algorithmpredicates.PodFitsResources},
|
predicates: map[string]algorithmpredicates.FitPredicate{"matches": algorithmpredicates.PodFitsResources},
|
||||||
|
@ -134,9 +134,15 @@ func (l *SortableList) Sort() {
|
|||||||
sort.Sort(l)
|
sort.Sort(l)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HigherPriorityPod return true when priority of the first pod is higher than
|
// MoreImportantPod 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
|
// the second one. If two pods' priorities are equal, compare their StartTime.
|
||||||
// SortableList, but expects those arguments to be *v1.Pod.
|
// It takes arguments of the type "interface{}" to be used with SortableList,
|
||||||
func HigherPriorityPod(pod1, pod2 interface{}) bool {
|
// but expects those arguments to be *v1.Pod.
|
||||||
return GetPodPriority(pod1.(*v1.Pod)) > GetPodPriority(pod2.(*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)))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user