@@ -58,8 +58,11 @@ import (
58
58
"k8s.io/klog"
59
59
)
60
60
61
- // NewSchedulerCommand creates a *cobra.Command object with default parameters
62
- func NewSchedulerCommand () * cobra.Command {
61
+ // Option configures a framework.Registry.
62
+ type Option func (framework.Registry ) error
63
+
64
+ // NewSchedulerCommand creates a *cobra.Command object with default parameters and registryOptions
65
+ func NewSchedulerCommand (registryOptions ... Option ) * cobra.Command {
63
66
opts , err := options .NewOptions ()
64
67
if err != nil {
65
68
klog .Fatalf ("unable to initialize command options: %v" , err )
@@ -75,7 +78,7 @@ constraints, affinity and anti-affinity specifications, data locality, inter-wor
75
78
interference, deadlines, and so on. Workload-specific requirements will be exposed
76
79
through the API as necessary.` ,
77
80
Run : func (cmd * cobra.Command , args []string ) {
78
- if err := runCommand (cmd , args , opts ); err != nil {
81
+ if err := runCommand (cmd , args , opts , registryOptions ... ); err != nil {
79
82
fmt .Fprintf (os .Stderr , "%v\n " , err )
80
83
os .Exit (1 )
81
84
}
@@ -106,7 +109,7 @@ through the API as necessary.`,
106
109
}
107
110
108
111
// runCommand runs the scheduler.
109
- func runCommand (cmd * cobra.Command , args []string , opts * options.Options ) error {
112
+ func runCommand (cmd * cobra.Command , args []string , opts * options.Options , registryOptions ... Option ) error {
110
113
verflag .PrintAndExitIfRequested ()
111
114
utilflag .PrintFlags (cmd .Flags ())
112
115
@@ -134,7 +137,6 @@ func runCommand(cmd *cobra.Command, args []string, opts *options.Options) error
134
137
}
135
138
136
139
stopCh := make (chan struct {})
137
-
138
140
// Get the completed config
139
141
cc := c .Complete ()
140
142
@@ -152,14 +154,21 @@ func runCommand(cmd *cobra.Command, args []string, opts *options.Options) error
152
154
return fmt .Errorf ("unable to register configz: %s" , err )
153
155
}
154
156
155
- return Run (cc , stopCh )
157
+ return Run (cc , stopCh , registryOptions ... )
156
158
}
157
159
158
160
// Run executes the scheduler based on the given configuration. It only return on error or when stopCh is closed.
159
- func Run (cc schedulerserverconfig.CompletedConfig , stopCh <- chan struct {}) error {
161
+ func Run (cc schedulerserverconfig.CompletedConfig , stopCh <- chan struct {}, registryOptions ... Option ) error {
160
162
// To help debugging, immediately log version
161
163
klog .V (1 ).Infof ("Starting Kubernetes Scheduler version %+v" , version .Get ())
162
164
165
+ registry := framework .NewRegistry ()
166
+ for _ , option := range registryOptions {
167
+ if err := option (registry ); err != nil {
168
+ return err
169
+ }
170
+ }
171
+
163
172
// Create the scheduler.
164
173
sched , err := scheduler .New (cc .Client ,
165
174
cc .InformerFactory .Core ().V1 ().Nodes (),
@@ -176,7 +185,7 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
176
185
cc .Recorder ,
177
186
cc .ComponentConfig .AlgorithmSource ,
178
187
stopCh ,
179
- framework . NewRegistry () ,
188
+ registry ,
180
189
cc .ComponentConfig .Plugins ,
181
190
cc .ComponentConfig .PluginConfig ,
182
191
scheduler .WithName (cc .ComponentConfig .SchedulerName ),
@@ -328,3 +337,10 @@ func newHealthzHandler(config *kubeschedulerconfig.KubeSchedulerConfiguration, s
328
337
}
329
338
return pathRecorderMux
330
339
}
340
+
341
+ // WithPlugin creates an Option based on plugin name and factory.
342
+ func WithPlugin (name string , factory framework.PluginFactory ) Option {
343
+ return func (registry framework.Registry ) error {
344
+ return registry .Register (name , factory )
345
+ }
346
+ }
0 commit comments