Skip to content

Commit 3952e22

Browse files
shaneuttrlakhtakia
authored andcommitted
chore: make SchedulerConfig fields configurable (#764)
Signed-off-by: Shane Utt <[email protected]>
1 parent fa4bca1 commit 3952e22

File tree

3 files changed

+46
-40
lines changed

3 files changed

+46
-40
lines changed

pkg/epp/scheduling/config.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ package scheduling
1818

1919
import "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins"
2020

21+
// SchedulerConfig provides a configuration for the scheduler which includes
22+
// items like filters, scorers, etc that influence routing decisions.
23+
//
24+
// This is not threadsafe and the machinery here does not support dynamically
25+
// changing this at runtime, so this should be set once on startup and not
26+
// changed thereafter.
2127
type SchedulerConfig struct {
22-
preSchedulePlugins []plugins.PreSchedule
23-
filters []plugins.Filter
24-
scorers map[plugins.Scorer]int // map from scorer to weight
25-
picker plugins.Picker
26-
postSchedulePlugins []plugins.PostSchedule
28+
PreSchedulePlugins []plugins.PreSchedule
29+
Filters []plugins.Filter
30+
Scorers map[plugins.Scorer]int // map from scorer to weight
31+
Picker plugins.Picker
32+
PostSchedulePlugins []plugins.PostSchedule
2733
}
2834

2935
var defPlugin = &defaultPlugin{}
@@ -33,9 +39,9 @@ var defPlugin = &defaultPlugin{}
3339

3440
// For build time plugins changes, it's recommended to change the defaultConfig variable in this file.
3541
var defaultConfig = &SchedulerConfig{
36-
preSchedulePlugins: []plugins.PreSchedule{},
37-
filters: []plugins.Filter{defPlugin},
38-
scorers: map[plugins.Scorer]int{},
39-
picker: defPlugin,
40-
postSchedulePlugins: []plugins.PostSchedule{},
42+
PreSchedulePlugins: []plugins.PreSchedule{},
43+
Filters: []plugins.Filter{defPlugin},
44+
Scorers: map[plugins.Scorer]int{},
45+
Picker: defPlugin,
46+
PostSchedulePlugins: []plugins.PostSchedule{},
4147
}

pkg/epp/scheduling/scheduler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ func NewScheduler(datastore Datastore) *Scheduler {
7474
func NewSchedulerWithConfig(datastore Datastore, config *SchedulerConfig) *Scheduler {
7575
return &Scheduler{
7676
datastore: datastore,
77-
preSchedulePlugins: config.preSchedulePlugins,
78-
filters: config.filters,
79-
scorers: config.scorers,
80-
picker: config.picker,
81-
postSchedulePlugins: config.postSchedulePlugins,
77+
preSchedulePlugins: config.PreSchedulePlugins,
78+
filters: config.Filters,
79+
scorers: config.Scorers,
80+
picker: config.Picker,
81+
postSchedulePlugins: config.PostSchedulePlugins,
8282
}
8383
}
8484

pkg/epp/scheduling/scheduler_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ func TestSchedulePlugins(t *testing.T) {
273273
{
274274
name: "all plugins executed successfully, all scorers with same weight",
275275
config: SchedulerConfig{
276-
preSchedulePlugins: []plugins.PreSchedule{tp1, tp2},
277-
filters: []plugins.Filter{tp1, tp2},
278-
scorers: map[plugins.Scorer]int{
276+
PreSchedulePlugins: []plugins.PreSchedule{tp1, tp2},
277+
Filters: []plugins.Filter{tp1, tp2},
278+
Scorers: map[plugins.Scorer]int{
279279
tp1: 1,
280280
tp2: 1,
281281
},
282-
picker: pickerPlugin,
283-
postSchedulePlugins: []plugins.PostSchedule{tp1, tp2},
282+
Picker: pickerPlugin,
283+
PostSchedulePlugins: []plugins.PostSchedule{tp1, tp2},
284284
},
285285
input: []*backendmetrics.FakePodMetrics{
286286
{Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod1"}}},
@@ -295,14 +295,14 @@ func TestSchedulePlugins(t *testing.T) {
295295
{
296296
name: "all plugins executed successfully, different scorers weights",
297297
config: SchedulerConfig{
298-
preSchedulePlugins: []plugins.PreSchedule{tp1, tp2},
299-
filters: []plugins.Filter{tp1, tp2},
300-
scorers: map[plugins.Scorer]int{
298+
PreSchedulePlugins: []plugins.PreSchedule{tp1, tp2},
299+
Filters: []plugins.Filter{tp1, tp2},
300+
Scorers: map[plugins.Scorer]int{
301301
tp1: 60,
302302
tp2: 40,
303303
},
304-
picker: pickerPlugin,
305-
postSchedulePlugins: []plugins.PostSchedule{tp1, tp2},
304+
Picker: pickerPlugin,
305+
PostSchedulePlugins: []plugins.PostSchedule{tp1, tp2},
306306
},
307307
input: []*backendmetrics.FakePodMetrics{
308308
{Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod1"}}},
@@ -317,14 +317,14 @@ func TestSchedulePlugins(t *testing.T) {
317317
{
318318
name: "filter all",
319319
config: SchedulerConfig{
320-
preSchedulePlugins: []plugins.PreSchedule{tp1, tp2},
321-
filters: []plugins.Filter{tp1, tp_filterAll},
322-
scorers: map[plugins.Scorer]int{
320+
PreSchedulePlugins: []plugins.PreSchedule{tp1, tp2},
321+
Filters: []plugins.Filter{tp1, tp_filterAll},
322+
Scorers: map[plugins.Scorer]int{
323323
tp1: 1,
324324
tp2: 1,
325325
},
326-
picker: pickerPlugin,
327-
postSchedulePlugins: []plugins.PostSchedule{tp1, tp2},
326+
Picker: pickerPlugin,
327+
PostSchedulePlugins: []plugins.PostSchedule{tp1, tp2},
328328
},
329329
input: []*backendmetrics.FakePodMetrics{
330330
{Pod: &backend.Pod{NamespacedName: k8stypes.NamespacedName{Name: "pod1"}}},
@@ -339,17 +339,17 @@ func TestSchedulePlugins(t *testing.T) {
339339
for _, test := range tests {
340340
t.Run(test.name, func(t *testing.T) {
341341
// Reset all plugins before each new test case.
342-
for _, plugin := range test.config.preSchedulePlugins {
342+
for _, plugin := range test.config.PreSchedulePlugins {
343343
plugin.(*TestPlugin).reset()
344344
}
345-
for _, plugin := range test.config.filters {
345+
for _, plugin := range test.config.Filters {
346346
plugin.(*TestPlugin).reset()
347347
}
348-
for plugin := range test.config.scorers {
348+
for plugin := range test.config.Scorers {
349349
plugin.(*TestPlugin).reset()
350350
}
351-
test.config.picker.(*TestPlugin).reset()
352-
for _, plugin := range test.config.postSchedulePlugins {
351+
test.config.Picker.(*TestPlugin).reset()
352+
for _, plugin := range test.config.PostSchedulePlugins {
353353
plugin.(*TestPlugin).reset()
354354
}
355355

@@ -378,21 +378,21 @@ func TestSchedulePlugins(t *testing.T) {
378378
}
379379

380380
// Validate plugin execution counts dynamically
381-
for _, plugin := range test.config.preSchedulePlugins {
381+
for _, plugin := range test.config.PreSchedulePlugins {
382382
tp, _ := plugin.(*TestPlugin)
383383
if tp.PreScheduleCallCount != 1 {
384384
t.Errorf("Plugin %s PreSchedule() called %d times, expected 1", plugin.Name(), tp.PreScheduleCallCount)
385385
}
386386
}
387387

388-
for _, plugin := range test.config.filters {
388+
for _, plugin := range test.config.Filters {
389389
tp, _ := plugin.(*TestPlugin)
390390
if tp.FilterCallCount != 1 {
391391
t.Errorf("Plugin %s Filter() called %d times, expected 1", plugin.Name(), tp.FilterCallCount)
392392
}
393393
}
394394

395-
for plugin := range test.config.scorers {
395+
for plugin := range test.config.Scorers {
396396
tp, _ := plugin.(*TestPlugin)
397397
if tp.ScoreCallCount != 1 {
398398
t.Errorf("Plugin %s Score() called %d times, expected 1", plugin.Name(), tp.ScoreCallCount)
@@ -402,7 +402,7 @@ func TestSchedulePlugins(t *testing.T) {
402402
}
403403
}
404404

405-
tp, _ := test.config.picker.(*TestPlugin)
405+
tp, _ := test.config.Picker.(*TestPlugin)
406406
if tp.NumOfPickerCandidates != test.numPodsToScore {
407407
t.Errorf("Picker plugin %s Pick() called with %d candidates, expected %d", tp.Name(), tp.NumOfPickerCandidates, tp.NumOfScoredPods)
408408
}
@@ -413,7 +413,7 @@ func TestSchedulePlugins(t *testing.T) {
413413
t.Errorf("winnder pod score %v, expected %v", tp.WinnderPodScore, test.targetPodScore)
414414
}
415415

416-
for _, plugin := range test.config.postSchedulePlugins {
416+
for _, plugin := range test.config.PostSchedulePlugins {
417417
tp, _ := plugin.(*TestPlugin)
418418
if tp.PostScheduleCallCount != 1 {
419419
t.Errorf("Plugin %s PostSchedule() called %d times, expected 1", plugin.Name(), tp.PostScheduleCallCount)

0 commit comments

Comments
 (0)