Skip to content

Commit 62b091b

Browse files
authored
Merge pull request kubernetes#92476 from Huang-Wei/pbd-bug
Fix a preemption bug when pods are listed in pdb.Status.DisruptedPods
2 parents 6676134 + 82ab6db commit 62b091b

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

pkg/scheduler/core/generic_scheduler.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -936,15 +936,18 @@ 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+
}
945+
// Only decrement the matched pdb when it's not in its <DisruptedPods>;
946+
// otherwise we may over-decrement the budget number.
947+
pdbsAllowed[i]--
939948
// We have found a matching PDB.
940-
if pdbsAllowed[i] <= 0 {
949+
if pdbsAllowed[i] < 0 {
941950
pdbForPodIsViolated = true
942-
} else {
943-
// Only decrement the matched pdb when it's not in its <DisruptedPods>;
944-
// otherwise we may over-decrement the budget number.
945-
if _, exist := pdb.Status.DisruptedPods[pod.Name]; !exist {
946-
pdbsAllowed[i]--
947-
}
948951
}
949952
}
950953
}

pkg/scheduler/core/generic_scheduler_test.go

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

0 commit comments

Comments
 (0)