Skip to content

Commit 7e073db

Browse files
authored
Merge pull request kubernetes#91986 from denkensk/fix-pdb-preempt
Computing DisruptedPods of PDB in scheduling preemption
2 parents 8dbca91 + 02e4060 commit 7e073db

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
@@ -941,9 +941,12 @@ func filterPodsWithPDBViolation(pods []*v1.Pod, pdbs []*policy.PodDisruptionBudg
941941
// We have found a matching PDB.
942942
if pdbsAllowed[i] <= 0 {
943943
pdbForPodIsViolated = true
944-
break
945944
} else {
946-
pdbsAllowed[i]--
945+
// Only decrement the matched pdb when it's not in its <DisruptedPods>;
946+
// otherwise we may over-decrement the budget number.
947+
if _, exist := pdb.Status.DisruptedPods[pod.Name]; !exist {
948+
pdbsAllowed[i]--
949+
}
947950
}
948951
}
949952
}

pkg/scheduler/core/generic_scheduler_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,40 @@ func TestSelectNodesForPreemption(t *testing.T) {
14701470
expected: map[string]victims{"machine1": {pods: sets.NewString("a", "b"), numPDBViolations: 1}},
14711471
expectedNumFilterCalled: 3,
14721472
},
1473+
{
1474+
name: "preemption with violation of the pdb with pod whose eviction was processed, the victim doesn't belong to DisruptedPods",
1475+
registerPlugins: []st.RegisterPluginFunc{
1476+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
1477+
st.RegisterPluginAsExtensions(noderesources.FitName, noderesources.NewFit, "Filter", "PreFilter"),
1478+
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
1479+
},
1480+
nodes: []string{"machine1"},
1481+
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod1", UID: types.UID("pod1")}, Spec: v1.PodSpec{Containers: veryLargeContainers, Priority: &highPriority}},
1482+
pods: []*v1.Pod{
1483+
{ObjectMeta: metav1.ObjectMeta{Name: "a", UID: types.UID("a"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}},
1484+
{ObjectMeta: metav1.ObjectMeta{Name: "b", UID: types.UID("b"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}}},
1485+
pdbs: []*policy.PodDisruptionBudget{
1486+
{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()}}}}},
1487+
expected: map[string]victims{"machine1": {pods: sets.NewString("a", "b"), numPDBViolations: 1}},
1488+
expectedNumFilterCalled: 3,
1489+
},
1490+
{
1491+
name: "preemption with violation of the pdb with pod whose eviction was processed, the victim belongs to DisruptedPods",
1492+
registerPlugins: []st.RegisterPluginFunc{
1493+
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
1494+
st.RegisterPluginAsExtensions(noderesources.FitName, noderesources.NewFit, "Filter", "PreFilter"),
1495+
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
1496+
},
1497+
nodes: []string{"machine1"},
1498+
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "pod1", UID: types.UID("pod1")}, Spec: v1.PodSpec{Containers: veryLargeContainers, Priority: &highPriority}},
1499+
pods: []*v1.Pod{
1500+
{ObjectMeta: metav1.ObjectMeta{Name: "a", UID: types.UID("a"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}},
1501+
{ObjectMeta: metav1.ObjectMeta{Name: "b", UID: types.UID("b"), Labels: map[string]string{"app": "foo"}}, Spec: v1.PodSpec{Containers: mediumContainers, Priority: &midPriority, NodeName: "machine1"}}},
1502+
pdbs: []*policy.PodDisruptionBudget{
1503+
{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()}}}}},
1504+
expected: map[string]victims{"machine1": {pods: sets.NewString("a", "b"), numPDBViolations: 0}},
1505+
expectedNumFilterCalled: 3,
1506+
},
14731507
}
14741508
labelKeys := []string{"hostname", "zone", "region"}
14751509
for _, test := range tests {

0 commit comments

Comments
 (0)