@@ -18,20 +18,23 @@ package scheduling
1818
1919import (
2020 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins"
21- "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/picker"
2221 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/prefix"
2322)
2423
2524// NewSchedulerConfig creates a new SchedulerConfig object with the given plugins.
2625func NewSchedulerConfig (preSchedulePlugins []plugins.PreSchedule , filters []plugins.Filter , scorers map [plugins.Scorer ]int ,
27- picker plugins.Picker , postSchedulePlugins []plugins.PostSchedule ) * SchedulerConfig {
28- return & SchedulerConfig {
26+ picker plugins.Picker , postSchedulePlugins []plugins.PostSchedule , opts ... ConfigOption ) * SchedulerConfig {
27+ config := & SchedulerConfig {
2928 preSchedulePlugins : preSchedulePlugins ,
3029 filters : filters ,
3130 scorers : scorers ,
3231 picker : picker ,
3332 postSchedulePlugins : postSchedulePlugins ,
3433 }
34+ for _ , opt := range opts {
35+ opt (config )
36+ }
37+ return config
3538}
3639
3740// SchedulerConfig provides a configuration for the scheduler which influence routing decisions.
@@ -43,42 +46,8 @@ type SchedulerConfig struct {
4346 postSchedulePlugins []plugins.PostSchedule
4447}
4548
46- var defPlugin = & defaultPlugin {}
47-
48- // When the scheduler is initialized with NewScheduler function, this config will be used as default.
49- // it's possible to call NewSchedulerWithConfig to pass a different argument.
50-
51- // For build time plugins changes, it's recommended to change the defaultConfig variable in this file.
52- var defaultConfig = & SchedulerConfig {
53- preSchedulePlugins : []plugins.PreSchedule {},
54- filters : []plugins.Filter {defPlugin },
55- scorers : map [plugins.Scorer ]int {},
56- picker : defPlugin ,
57- postSchedulePlugins : []plugins.PostSchedule {},
58- }
59-
60- func CreateConfig (opts ... ConfigOption ) * SchedulerConfig {
61- config := & SchedulerConfig {
62- preSchedulePlugins : []plugins.PreSchedule {},
63- postSchedulePlugins : []plugins.PostSchedule {},
64- scorers : map [plugins.Scorer ]int {},
65- filters : []plugins.Filter {& sheddableRequestFilterV2 {}},
66- picker : & picker.MaxScorePicker {},
67- }
68- for _ , opt := range opts {
69- opt (config )
70- }
71- return config
72- }
73-
7449type ConfigOption func (* SchedulerConfig )
7550
76- func AddScorer (scorer plugins.Scorer , weight int ) ConfigOption {
77- return func (cfg * SchedulerConfig ) {
78- cfg .scorers [scorer ] = weight
79- }
80- }
81-
8251func AddPrefixPlugin (prefixConfig prefix.Config , weight int ) ConfigOption {
8352 return func (cfg * SchedulerConfig ) {
8453 prefixPlugin := prefix .New (prefixConfig )
0 commit comments