diff --git a/cmd/kube-scheduler/app/config/BUILD b/cmd/kube-scheduler/app/config/BUILD index 877ceef1e05..851b3ab3f75 100644 --- a/cmd/kube-scheduler/app/config/BUILD +++ b/cmd/kube-scheduler/app/config/BUILD @@ -7,6 +7,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/scheduler/apis/config:go_default_library", + "//pkg/scheduler/framework/v1alpha1:go_default_library", "//staging/src/k8s.io/apiserver/pkg/server:go_default_library", "//staging/src/k8s.io/client-go/informers:go_default_library", "//staging/src/k8s.io/client-go/informers/core/v1:go_default_library", diff --git a/cmd/kube-scheduler/app/config/config.go b/cmd/kube-scheduler/app/config/config.go index 2ad5ae9bf34..02243f5aa0d 100644 --- a/cmd/kube-scheduler/app/config/config.go +++ b/cmd/kube-scheduler/app/config/config.go @@ -26,6 +26,7 @@ import ( "k8s.io/client-go/tools/leaderelection" "k8s.io/client-go/tools/record" kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" + framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" ) // Config has all the context to run a Scheduler @@ -51,6 +52,9 @@ type Config struct { // LeaderElection is optional. LeaderElection *leaderelection.LeaderElectionConfig + + // Registry is a collection of all available plugins. + Registry framework.Registry } type completedConfig struct { @@ -73,6 +77,9 @@ func (c *Config) Complete() CompletedConfig { if c.InsecureMetricsServing != nil { c.InsecureMetricsServing.Name = "metrics" } + if c.Registry == nil { + c.Registry = framework.NewRegistry() + } apiserver.AuthorizeClientBearerToken(c.LoopbackClientConfig, &c.Authentication, &c.Authorization) diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go index 65e5b140f6a..545450e49eb 100644 --- a/cmd/kube-scheduler/app/server.go +++ b/cmd/kube-scheduler/app/server.go @@ -58,10 +58,13 @@ import ( "k8s.io/klog" ) -var frameworkRegistry = framework.NewRegistry() - // NewSchedulerCommand creates a *cobra.Command object with default parameters func NewSchedulerCommand() *cobra.Command { + return NewSchedulerCommandWithRegistry(nil) +} + +// NewSchedulerCommandWithRegistry creates a *cobra.Command object with registry and default parameters +func NewSchedulerCommandWithRegistry(registry framework.Registry) *cobra.Command { opts, err := options.NewOptions() if err != nil { klog.Fatalf("unable to initialize command options: %v", err) @@ -77,7 +80,7 @@ constraints, affinity and anti-affinity specifications, data locality, inter-wor interference, deadlines, and so on. Workload-specific requirements will be exposed through the API as necessary.`, Run: func(cmd *cobra.Command, args []string) { - if err := runCommand(cmd, args, opts); err != nil { + if err := runCommand(cmd, args, opts, registry); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) } @@ -108,7 +111,7 @@ through the API as necessary.`, } // runCommand runs the scheduler. -func runCommand(cmd *cobra.Command, args []string, opts *options.Options) error { +func runCommand(cmd *cobra.Command, args []string, opts *options.Options, registry framework.Registry) error { verflag.PrintAndExitIfRequested() utilflag.PrintFlags(cmd.Flags()) @@ -137,6 +140,10 @@ func runCommand(cmd *cobra.Command, args []string, opts *options.Options) error stopCh := make(chan struct{}) + if registry != nil { + c.Registry = registry + } + // Get the completed config cc := c.Complete() @@ -177,7 +184,7 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error cc.Recorder, cc.ComponentConfig.AlgorithmSource, stopCh, - frameworkRegistry, + cc.Registry, cc.ComponentConfig.Plugins, cc.ComponentConfig.PluginConfig, scheduler.WithName(cc.ComponentConfig.SchedulerName), @@ -328,9 +335,3 @@ func newHealthzHandler(config *kubeschedulerconfig.KubeSchedulerConfiguration, s } return pathRecorderMux } - -// RegisterFrameworkPlugin adds a new plugin to the registry. If a plugin with the same name -// exists, it returns an error. -func RegisterFrameworkPlugin(name string, factory framework.PluginFactory) error { - return frameworkRegistry.Register(name, factory) -}