@@ -18,20 +18,23 @@ package scheduling
18
18
19
19
import (
20
20
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins"
21
- "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/picker"
22
21
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/plugins/prefix"
23
22
)
24
23
25
24
// NewSchedulerConfig creates a new SchedulerConfig object with the given plugins.
26
25
func 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 {
29
28
preSchedulePlugins : preSchedulePlugins ,
30
29
filters : filters ,
31
30
scorers : scorers ,
32
31
picker : picker ,
33
32
postSchedulePlugins : postSchedulePlugins ,
34
33
}
34
+ for _ , opt := range opts {
35
+ opt (config )
36
+ }
37
+ return config
35
38
}
36
39
37
40
// SchedulerConfig provides a configuration for the scheduler which influence routing decisions.
@@ -43,42 +46,8 @@ type SchedulerConfig struct {
43
46
postSchedulePlugins []plugins.PostSchedule
44
47
}
45
48
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
-
74
49
type ConfigOption func (* SchedulerConfig )
75
50
76
- func AddScorer (scorer plugins.Scorer , weight int ) ConfigOption {
77
- return func (cfg * SchedulerConfig ) {
78
- cfg .scorers [scorer ] = weight
79
- }
80
- }
81
-
82
51
func AddPrefixPlugin (prefixConfig prefix.Config , weight int ) ConfigOption {
83
52
return func (cfg * SchedulerConfig ) {
84
53
prefixPlugin := prefix .New (prefixConfig )
0 commit comments