Skip to content

Commit dd3af9a

Browse files
committed
fix: skip isPodWorthRequeuing only when SchedulingGates gates the pod
1 parent c3689b9 commit dd3af9a

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

pkg/scheduler/internal/queue/scheduling_queue.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"k8s.io/kubernetes/pkg/features"
4848
"k8s.io/kubernetes/pkg/scheduler/framework"
4949
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
50+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/names"
5051
"k8s.io/kubernetes/pkg/scheduler/internal/heap"
5152
"k8s.io/kubernetes/pkg/scheduler/metrics"
5253
"k8s.io/kubernetes/pkg/scheduler/util"
@@ -1195,9 +1196,10 @@ func (p *PriorityQueue) movePodsToActiveOrBackoffQueue(logger klog.Logger, podIn
11951196
for _, pInfo := range podInfoList {
11961197
// Since there may be many gated pods and they will not move from the
11971198
// unschedulable pool, we skip calling the expensive isPodWorthRequeueing.
1198-
if pInfo.Gated {
1199+
if pInfo.Gated && pInfo.UnschedulablePlugins.Has(names.SchedulingGates) {
11991200
continue
12001201
}
1202+
12011203
schedulingHint := p.isPodWorthRequeuing(logger, pInfo, event, oldObj, newObj)
12021204
if schedulingHint == queueSkip {
12031205
// QueueingHintFn determined that this Pod isn't worth putting to activeQ or backoffQ by this event.

pkg/scheduler/internal/queue/scheduling_queue_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"k8s.io/kubernetes/pkg/features"
4545
"k8s.io/kubernetes/pkg/scheduler/framework"
4646
plfeature "k8s.io/kubernetes/pkg/scheduler/framework/plugins/feature"
47+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/names"
4748
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
4849
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/schedulinggates"
4950
"k8s.io/kubernetes/pkg/scheduler/metrics"
@@ -1499,13 +1500,21 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithQueueingHint(t *testing.
14991500
expectedQ: unschedulablePods,
15001501
},
15011502
{
1502-
name: "QueueHintFunction is not called when Pod is gated",
1503-
podInfo: setQueuedPodInfoGated(&framework.QueuedPodInfo{PodInfo: mustNewPodInfo(p), UnschedulablePlugins: sets.New("foo")}),
1503+
name: "QueueHintFunction is not called when Pod is gated by SchedulingGates plugin",
1504+
podInfo: setQueuedPodInfoGated(&framework.QueuedPodInfo{PodInfo: mustNewPodInfo(p), UnschedulablePlugins: sets.New(names.SchedulingGates, "foo")}),
15041505
hint: func(logger klog.Logger, pod *v1.Pod, oldObj, newObj interface{}) (framework.QueueingHint, error) {
15051506
return framework.Queue, fmt.Errorf("QueueingHintFn should not be called as pod is gated")
15061507
},
15071508
expectedQ: unschedulablePods,
15081509
},
1510+
{
1511+
name: "QueueHintFunction is called when Pod is gated by a plugin other than SchedulingGates",
1512+
podInfo: setQueuedPodInfoGated(&framework.QueuedPodInfo{PodInfo: mustNewPodInfo(p), UnschedulablePlugins: sets.New("foo")}),
1513+
hint: queueHintReturnQueue,
1514+
// FIXME: This should be backoffQ.
1515+
// https://github.com/kubernetes/kubernetes/issues/125538
1516+
expectedQ: activeQ,
1517+
},
15091518
}
15101519

15111520
for _, test := range tests {
@@ -1518,14 +1527,13 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithQueueingHint(t *testing.
15181527
QueueingHintFn: test.hint,
15191528
},
15201529
}
1521-
test.podInfo.UnschedulablePlugins = sets.New("foo")
15221530
cl := testingclock.NewFakeClock(now)
15231531
q := NewTestQueue(ctx, newDefaultQueueSort(), WithQueueingHintMapPerProfile(m), WithClock(cl))
1524-
// add to unsched pod pool
15251532
q.activeQ.Add(q.newQueuedPodInfo(test.podInfo.Pod))
15261533
if p, err := q.Pop(logger); err != nil || p.Pod != test.podInfo.Pod {
15271534
t.Errorf("Expected: %v after Pop, but got: %v", test.podInfo.Pod.Name, p.Pod.Name)
15281535
}
1536+
// add to unsched pod pool
15291537
err := q.AddUnschedulableIfNotPresent(logger, test.podInfo, q.SchedulingCycle())
15301538
if err != nil {
15311539
t.Fatalf("unexpected error from AddUnschedulableIfNotPresent: %v", err)

test/integration/scheduler/plugins/plugins_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,8 +2668,9 @@ func TestSchedulingGatesPluginEventsToRegister(t *testing.T) {
26682668
}
26692669

26702670
tests := []struct {
2671-
name string
2672-
withEvents bool
2671+
name string
2672+
withEvents bool
2673+
// count is the expected number of calls to PreEnqueue().
26732674
count int
26742675
queueHintEnabled []bool
26752676
expectedScheduled []bool
@@ -2686,7 +2687,7 @@ func TestSchedulingGatesPluginEventsToRegister(t *testing.T) {
26862687
{
26872688
name: "preEnqueue plugin with event registered",
26882689
withEvents: true,
2689-
count: 2,
2690+
count: 3,
26902691
queueHintEnabled: []bool{false, true},
26912692
expectedScheduled: []bool{true, true},
26922693
},
@@ -2700,7 +2701,7 @@ func TestSchedulingGatesPluginEventsToRegister(t *testing.T) {
27002701
t.Run(tt.name+fmt.Sprintf(" queueHint(%v)", queueHintEnabled), func(t *testing.T) {
27012702
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SchedulerQueueingHints, queueHintEnabled)
27022703

2703-
// new plugin every time to clear counts
2704+
// use new plugin every time to clear counts
27042705
var plugin framework.PreEnqueuePlugin
27052706
if tt.withEvents {
27062707
plugin = &SchedulingGatesPluginWithEvents{SchedulingGates: schedulinggates.SchedulingGates{}}

0 commit comments

Comments
 (0)