@@ -58,13 +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 {
63
- return NewSchedulerCommandWithRegistry (nil )
64
- }
61
+ // PluginOption is an function type used for dealing with scheduler registry.
62
+ type PluginOption func (framework.Registry ) error
65
63
66
- // NewSchedulerCommandWithRegistry creates a *cobra.Command object with registry and default parameters
67
- func NewSchedulerCommandWithRegistry ( registry framework. Registry ) * cobra.Command {
64
+ // NewSchedulerCommand creates a *cobra.Command object with default parameters and pluginOptions
65
+ func NewSchedulerCommand ( pluginOptions ... PluginOption ) * cobra.Command {
68
66
opts , err := options .NewOptions ()
69
67
if err != nil {
70
68
klog .Fatalf ("unable to initialize command options: %v" , err )
@@ -80,7 +78,7 @@ constraints, affinity and anti-affinity specifications, data locality, inter-wor
80
78
interference, deadlines, and so on. Workload-specific requirements will be exposed
81
79
through the API as necessary.` ,
82
80
Run : func (cmd * cobra.Command , args []string ) {
83
- if err := runCommand (cmd , args , opts , registry ); err != nil {
81
+ if err := runCommand (cmd , args , opts , pluginOptions ... ); err != nil {
84
82
fmt .Fprintf (os .Stderr , "%v\n " , err )
85
83
os .Exit (1 )
86
84
}
@@ -111,7 +109,7 @@ through the API as necessary.`,
111
109
}
112
110
113
111
// runCommand runs the scheduler.
114
- func runCommand (cmd * cobra.Command , args []string , opts * options.Options , registry framework. Registry ) error {
112
+ func runCommand (cmd * cobra.Command , args []string , opts * options.Options , pluginOptions ... PluginOption ) error {
115
113
verflag .PrintAndExitIfRequested ()
116
114
utilflag .PrintFlags (cmd .Flags ())
117
115
@@ -139,11 +137,6 @@ func runCommand(cmd *cobra.Command, args []string, opts *options.Options, regist
139
137
}
140
138
141
139
stopCh := make (chan struct {})
142
-
143
- if registry != nil {
144
- c .Registry = registry
145
- }
146
-
147
140
// Get the completed config
148
141
cc := c .Complete ()
149
142
@@ -161,14 +154,21 @@ func runCommand(cmd *cobra.Command, args []string, opts *options.Options, regist
161
154
return fmt .Errorf ("unable to register configz: %s" , err )
162
155
}
163
156
164
- return Run (cc , stopCh )
157
+ return Run (cc , stopCh , pluginOptions ... )
165
158
}
166
159
167
160
// Run executes the scheduler based on the given configuration. It only return on error or when stopCh is closed.
168
- func Run (cc schedulerserverconfig.CompletedConfig , stopCh <- chan struct {}) error {
161
+ func Run (cc schedulerserverconfig.CompletedConfig , stopCh <- chan struct {}, pluginOptions ... PluginOption ) error {
169
162
// To help debugging, immediately log version
170
163
klog .V (1 ).Infof ("Starting Kubernetes Scheduler version %+v" , version .Get ())
171
164
165
+ registry := framework .NewRegistry ()
166
+ for _ , option := range pluginOptions {
167
+ if err := option (registry ); err != nil {
168
+ return err
169
+ }
170
+ }
171
+
172
172
// Create the scheduler.
173
173
sched , err := scheduler .New (cc .Client ,
174
174
cc .InformerFactory .Core ().V1 ().Nodes (),
@@ -184,7 +184,7 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
184
184
cc .Recorder ,
185
185
cc .ComponentConfig .AlgorithmSource ,
186
186
stopCh ,
187
- cc . Registry ,
187
+ registry ,
188
188
cc .ComponentConfig .Plugins ,
189
189
cc .ComponentConfig .PluginConfig ,
190
190
scheduler .WithName (cc .ComponentConfig .SchedulerName ),
@@ -335,3 +335,10 @@ func newHealthzHandler(config *kubeschedulerconfig.KubeSchedulerConfiguration, s
335
335
}
336
336
return pathRecorderMux
337
337
}
338
+
339
+ // WithPlugin creates a PluginOption based on plugin name and factory.
340
+ func WithPlugin (name string , factory framework.PluginFactory ) PluginOption {
341
+ return func (registry framework.Registry ) error {
342
+ return registry .Register (name , factory )
343
+ }
344
+ }
0 commit comments