Skip to content

Commit 34cdcc0

Browse files
nirrozenbaumrlakhtakia
authored andcommitted
put SchedulerConfig fields private again. added NewSchedulerConfig func (#771)
Signed-off-by: Nir Rozenbaum <[email protected]>
1 parent f6d83fe commit 34cdcc0

File tree

4 files changed

+59
-50
lines changed

4 files changed

+59
-50
lines changed

pkg/epp/handlers/request_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"testing"
2323
"time"
2424

25-
extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
2625
"github.com/google/go-cmp/cmp"
2726
corev1 "k8s.io/api/core/v1"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -145,9 +144,12 @@ func TestHandleRequestBody(t *testing.T) {
145144
for _, test := range tests {
146145
t.Run(test.name, func(t *testing.T) {
147146
server := NewStreamingServer(scheduling.NewScheduler(ds), DefaultDestinationEndpointHintMetadataNamespace, DefaultDestinationEndpointHintKey, ds)
148-
reqCtx := &RequestContext{}
149-
req := &extProcPb.ProcessingRequest{}
150-
reqCtx, err := server.HandleRequestBody(ctx, reqCtx, req, test.reqBodyMap)
147+
reqCtx := &RequestContext{
148+
Request: &Request{
149+
Body: test.reqBodyMap,
150+
},
151+
}
152+
reqCtx, err := server.HandleRequestBody(ctx, reqCtx)
151153

152154
if test.wantErrCode != "" {
153155
if err == nil {

pkg/epp/scheduling/config.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,25 @@ 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.
21+
// SchedulerConfig creates a new SchedulerConfig object with the given plugins.
22+
func NewSchedulerConfig(preSchedulePlugins []plugins.PreSchedule, filters []plugins.Filter, scorers map[plugins.Scorer]int,
23+
picker plugins.Picker, postSchedulePlugins []plugins.PostSchedule) *SchedulerConfig {
24+
return &SchedulerConfig{
25+
preSchedulePlugins: preSchedulePlugins,
26+
filters: filters,
27+
scorers: scorers,
28+
picker: picker,
29+
postSchedulePlugins: postSchedulePlugins,
30+
}
31+
}
32+
33+
// SchedulerConfig provides a configuration for the scheduler which influence routing decisions.
2734
type SchedulerConfig struct {
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
35+
preSchedulePlugins []plugins.PreSchedule
36+
filters []plugins.Filter
37+
scorers map[plugins.Scorer]int // map from scorer to weight
38+
picker plugins.Picker
39+
postSchedulePlugins []plugins.PostSchedule
3340
}
3441

3542
var defPlugin = &defaultPlugin{}
@@ -39,9 +46,9 @@ var defPlugin = &defaultPlugin{}
3946

4047
// For build time plugins changes, it's recommended to change the defaultConfig variable in this file.
4148
var defaultConfig = &SchedulerConfig{
42-
PreSchedulePlugins: []plugins.PreSchedule{},
43-
Filters: []plugins.Filter{defPlugin},
44-
Scorers: map[plugins.Scorer]int{},
45-
Picker: defPlugin,
46-
PostSchedulePlugins: []plugins.PostSchedule{},
49+
preSchedulePlugins: []plugins.PreSchedule{},
50+
filters: []plugins.Filter{defPlugin},
51+
scorers: map[plugins.Scorer]int{},
52+
picker: defPlugin,
53+
postSchedulePlugins: []plugins.PostSchedule{},
4754
}

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)