Skip to content

Commit 0f584a9

Browse files
authored
Merge pull request kubernetes#124933 from AxeZhan/fix_panic
[Scheduler] Use allNodes when calculating nextStartNodeIndex
2 parents c0f4879 + b5f25c4 commit 0f584a9

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

pkg/scheduler/schedule_one.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func (sched *Scheduler) findNodesThatFitPod(ctx context.Context, fwk framework.F
500500
// always try to update the sched.nextStartNodeIndex regardless of whether an error has occurred
501501
// this is helpful to make sure that all the nodes have a chance to be searched
502502
processedNodes := len(feasibleNodes) + len(diagnosis.NodeToStatusMap)
503-
sched.nextStartNodeIndex = (sched.nextStartNodeIndex + processedNodes) % len(nodes)
503+
sched.nextStartNodeIndex = (sched.nextStartNodeIndex + processedNodes) % len(allNodes)
504504
if err != nil {
505505
return nil, diagnosis, err
506506
}

pkg/scheduler/schedule_one_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,33 @@ func TestSchedulerSchedulePod(t *testing.T) {
24332433
// since this case has no score plugin, we'll only try to find one node in Filter stage
24342434
wantEvaluatedNodes: ptr.To[int32](1),
24352435
},
2436+
{
2437+
name: "test prefilter plugin returned an invalid node",
2438+
registerPlugins: []tf.RegisterPluginFunc{
2439+
tf.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
2440+
tf.RegisterPreFilterPlugin(
2441+
"FakePreFilter",
2442+
tf.NewFakePreFilterPlugin("FakePreFilter", &framework.PreFilterResult{
2443+
NodeNames: sets.New("invalid-node"),
2444+
}, nil),
2445+
),
2446+
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
2447+
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
2448+
},
2449+
nodes: []string{"1", "2"},
2450+
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
2451+
wantNodes: nil,
2452+
wErr: &framework.FitError{
2453+
Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
2454+
NumAllNodes: 2,
2455+
Diagnosis: framework.Diagnosis{
2456+
NodeToStatusMap: framework.NodeToStatusMap{
2457+
"1": framework.NewStatus(framework.UnschedulableAndUnresolvable, "node is filtered out by the prefilter result"),
2458+
"2": framework.NewStatus(framework.UnschedulableAndUnresolvable, "node is filtered out by the prefilter result"),
2459+
},
2460+
},
2461+
},
2462+
},
24362463
}
24372464
for _, test := range tests {
24382465
t.Run(test.name, func(t *testing.T) {

test/integration/scheduler/scheduler_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,33 @@ func TestSchedulerInformers(t *testing.T) {
480480
}),
481481
preemptedPodIndexes: map[int]struct{}{2: {}},
482482
},
483+
{
484+
name: "The pod cannot be scheduled when nodeAffinity specifies a non-existent node.",
485+
nodes: []*nodeConfig{{name: "node-1", res: defaultNodeRes}},
486+
existingPods: []*v1.Pod{},
487+
pod: testutils.InitPausePod(&testutils.PausePodConfig{
488+
Name: "unschedulable-pod",
489+
Namespace: testCtx.NS.Name,
490+
Affinity: &v1.Affinity{
491+
NodeAffinity: &v1.NodeAffinity{
492+
RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{
493+
NodeSelectorTerms: []v1.NodeSelectorTerm{
494+
{
495+
MatchFields: []v1.NodeSelectorRequirement{
496+
{
497+
Key: "metadata.name",
498+
Operator: v1.NodeSelectorOpIn,
499+
Values: []string{"invalid-node"},
500+
},
501+
},
502+
},
503+
},
504+
},
505+
},
506+
},
507+
Resources: defaultPodRes,
508+
}),
509+
},
483510
}
484511

485512
for _, test := range tests {

0 commit comments

Comments
 (0)