Skip to content

Commit 82ab6db

Browse files
committed
Pods in pdb.Status.DisruptedPods are treated as 'nonViolating' in any case
1 parent 4886218 commit 82ab6db

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

pkg/scheduler/core/generic_scheduler.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,11 +936,15 @@ func filterPodsWithPDBViolation(pods []*v1.Pod, pdbs []*policy.PodDisruptionBudg
936936
if selector.Empty() || !selector.Matches(labels.Set(pod.Labels)) {
937937
continue
938938
}
939+
940+
// Existing in DisruptedPods means it has been processed in API server,
941+
// we don't treat it as a violating case.
942+
if _, exist := pdb.Status.DisruptedPods[pod.Name]; exist {
943+
continue
944+
}
939945
// Only decrement the matched pdb when it's not in its <DisruptedPods>;
940946
// otherwise we may over-decrement the budget number.
941-
if _, exist := pdb.Status.DisruptedPods[pod.Name]; !exist {
942-
pdbsAllowed[i]--
943-
}
947+
pdbsAllowed[i]--
944948
// We have found a matching PDB.
945949
if pdbsAllowed[i] < 0 {
946950
pdbForPodIsViolated = true

pkg/scheduler/core/generic_scheduler_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,10 +1496,28 @@ func TestSelectNodesForPreemption(t *testing.T) {
14961496
{ObjectMeta: metav1.ObjectMeta{Name: "a", UID: types.UID("a"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}},
14971497
{ObjectMeta: metav1.ObjectMeta{Name: "b", UID: types.UID("b"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}}},
14981498
pdbs: []*policy.PodDisruptionBudget{
1499-
{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()}}}}},
1499+
{Spec: policy.PodDisruptionBudgetSpec{Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"app": "foo"}}}, Status: policy.PodDisruptionBudgetStatus{DisruptionsAllowed: 1, DisruptedPods: map[string]metav1.Time{"b": {Time: time.Now()}}}}},
15001500
expected: map[string]victims{"machine1": {pods: sets.NewString("a", "b"), numPDBViolations: 0}},
15011501
expectedNumFilterCalled: 3,
15021502
},
1503+
{
1504+
name: "preemption with violation of the pdb with pod whose eviction was processed, the victim which belongs to DisruptedPods is treated as 'nonViolating'",
1505+
registerPlugins: []st.RegisterPluginFunc{
1506+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
1507+
st.RegisterPluginAsExtensions(noderesources.FitName, noderesources.NewFit, "Filter", "PreFilter"),
1508+
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
1509+
},
1510+
nodes: []string{"machine1"},
1511+
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod1", UID: types.UID("pod1")}, Spec: v1.PodSpec{Containers: veryLargeContainers, Priority: &highPriority}},
1512+
pods: []*v1.Pod{
1513+
{ObjectMeta: metav1.ObjectMeta{Name: "a", UID: types.UID("a"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}},
1514+
{ObjectMeta: metav1.ObjectMeta{Name: "b", UID: types.UID("b"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}},
1515+
{ObjectMeta: metav1.ObjectMeta{Name: "c", UID: types.UID("c"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}}},
1516+
pdbs: []*policy.PodDisruptionBudget{
1517+
{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()}}}}},
1518+
expected: map[string]victims{"machine1": {pods: sets.NewString("a", "b", "c"), numPDBViolations: 1}},
1519+
expectedNumFilterCalled: 4,
1520+
},
15031521
}
15041522
labelKeys := []string{"hostname", "zone", "region"}
15051523
for _, test := range tests {

0 commit comments

Comments
 (0)