Introduce IsExpendablePod helper function

Change-Id: I899abc73b6de8906a29df0453559545c1cd0a0e5
This commit is contained in:
Łukasz Osipiuk 2020-01-15 19:33:38 +01:00
parent 84bebf3e93
commit e592cc6142
2 changed files with 23 additions and 1 deletions

View File

@ -55,9 +55,14 @@ func FilterOutExpendableAndSplit(unschedulableCandidates []*apiv1.Pod, nodes []*
func FilterOutExpendablePods(pods []*apiv1.Pod, expendablePodsPriorityCutoff int) []*apiv1.Pod {
var result []*apiv1.Pod
for _, pod := range pods {
if pod.Spec.Priority == nil || int(*pod.Spec.Priority) >= expendablePodsPriorityCutoff {
if !IsExpendablePod(pod, expendablePodsPriorityCutoff) {
result = append(result, pod)
}
}
return result
}
// IsExpendablePod tests if pod is expendable for give priority cutoff
func IsExpendablePod(pod *apiv1.Pod, expendablePodsPriorityCutoff int) bool {
return pod.Spec.Priority != nil && int(*pod.Spec.Priority) < expendablePodsPriorityCutoff
}

View File

@ -86,5 +86,22 @@ func TestFilterOutExpendablePods(t *testing.T) {
assert.Equal(t, p1, res[0])
assert.Equal(t, p2, res[1])
assert.Equal(t, podWaitingForPreemption2, res[2])
}
func TestIsExpendablePod(t *testing.T) {
pod1 := BuildTestPod("p1", 1500, 200000)
pod2 := BuildTestPod("w1", 1500, 200000)
var priority1 int32 = -10
pod2.Spec.Priority = &priority1
pod2.Status.NominatedNodeName = "node1"
assert.False(t, IsExpendablePod(pod1, 0))
assert.False(t, IsExpendablePod(pod1, -9))
assert.False(t, IsExpendablePod(pod1, -10))
assert.False(t, IsExpendablePod(pod1, -11))
assert.True(t, IsExpendablePod(pod2, 0))
assert.True(t, IsExpendablePod(pod2, -9))
assert.False(t, IsExpendablePod(pod2, -10))
assert.False(t, IsExpendablePod(pod2, -11))
}