Skip to content

Commit 02e4060

Browse files
committed
Computing DisruptedPods of PDB in scheduling preemption
1 parent b93e9d9 commit 02e4060

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

pkg/scheduler/core/generic_scheduler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,9 +916,12 @@ func filterPodsWithPDBViolation(pods []*v1.Pod, pdbs []*policy.PodDisruptionBudg
916916
// We have found a matching PDB.
917917
if pdbsAllowed[i] <= 0 {
918918
pdbForPodIsViolated = true
919-
break
920919
} else {
921-
pdbsAllowed[i]--
920+
// Only decrement the matched pdb when it's not in its <DisruptedPods>;
921+
// otherwise we may over-decrement the budget number.
922+
if _, exist := pdb.Status.DisruptedPods[pod.Name]; !exist {
923+
pdbsAllowed[i]--
924+
}
922925
}
923926
}
924927
}

pkg/scheduler/core/generic_scheduler_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,40 @@ func TestSelectNodesForPreemption(t *testing.T) {
15611561
expected: map[string]victims{"machine1": {pods: sets.NewString("a", "b"), numPDBViolations: 1}},
15621562
expectedNumFilterCalled: 3,
15631563
},
1564+
{
1565+
name: "preemption with violation of the pdb with pod whose eviction was processed, the victim doesn't belong to DisruptedPods",
1566+
registerPlugins: []st.RegisterPluginFunc{
1567+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
1568+
st.RegisterPluginAsExtensions(noderesources.FitName, noderesources.NewFit, "Filter", "PreFilter"),
1569+
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
1570+
},
1571+
nodes: []string{"machine1"},
1572+
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod1", UID: types.UID("pod1")}, Spec: v1.PodSpec{Containers: veryLargeContainers, Priority: &highPriority}},
1573+
pods: []*v1.Pod{
1574+
{ObjectMeta: metav1.ObjectMeta{Name: "a", UID: types.UID("a"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}},
1575+
{ObjectMeta: metav1.ObjectMeta{Name: "b", UID: types.UID("b"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}}},
1576+
pdbs: []*policy.PodDisruptionBudget{
1577+
{Spec: policy.PodDisruptionBudgetSpec{Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"app": "foo"}}}, Status: policy.PodDisruptionBudgetStatus{DisruptionsAllowed: 1, DisruptedPods: map[string]metav1.Time{"c": {Time: time.Now()}}}}},
1578+
expected: map[string]victims{"machine1": {pods: sets.NewString("a", "b"), numPDBViolations: 1}},
1579+
expectedNumFilterCalled: 3,
1580+
},
1581+
{
1582+
name: "preemption with violation of the pdb with pod whose eviction was processed, the victim belongs to DisruptedPods",
1583+
registerPlugins: []st.RegisterPluginFunc{
1584+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
1585+
st.RegisterPluginAsExtensions(noderesources.FitName, noderesources.NewFit, "Filter", "PreFilter"),
1586+
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
1587+
},
1588+
nodes: []string{"machine1"},
1589+
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod1", UID: types.UID("pod1")}, Spec: v1.PodSpec{Containers: veryLargeContainers, Priority: &highPriority}},
1590+
pods: []*v1.Pod{
1591+
{ObjectMeta: metav1.ObjectMeta{Name: "a", UID: types.UID("a"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}},
1592+
{ObjectMeta: metav1.ObjectMeta{Name: "b", UID: types.UID("b"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}}},
1593+
pdbs: []*policy.PodDisruptionBudget{
1594+
{Spec: policy.PodDisruptionBudgetSpec{Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"app": "foo"}}}, Status: policy.PodDisruptionBudgetStatus{DisruptionsAllowed: 1, DisruptedPods: map[string]metav1.Time{"a": {Time: time.Now()}}}}},
1595+
expected: map[string]victims{"machine1": {pods: sets.NewString("a", "b"), numPDBViolations: 0}},
1596+
expectedNumFilterCalled: 3,
1597+
},
15641598
}
15651599
labelKeys := []string{"hostname", "zone", "region"}
15661600
for _, test := range tests {

0 commit comments

Comments
 (0)