Skip to content

Commit e9793c8

Browse files
committed
Pass registry parameter to scheduler instead of global singleton
1 parent ea8e1e0 commit e9793c8

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

cmd/kube-scheduler/app/config/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ go_library(
77
visibility = ["//visibility:public"],
88
deps = [
99
"//pkg/scheduler/apis/config:go_default_library",
10+
"//pkg/scheduler/framework/v1alpha1:go_default_library",
1011
"//staging/src/k8s.io/apiserver/pkg/server:go_default_library",
1112
"//staging/src/k8s.io/client-go/informers:go_default_library",
1213
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",

cmd/kube-scheduler/app/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"k8s.io/client-go/tools/leaderelection"
2727
"k8s.io/client-go/tools/record"
2828
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
29+
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
2930
)
3031

3132
// Config has all the context to run a Scheduler
@@ -51,6 +52,9 @@ type Config struct {
5152

5253
// LeaderElection is optional.
5354
LeaderElection *leaderelection.LeaderElectionConfig
55+
56+
// Registry is a collection of all available plugins.
57+
Registry framework.Registry
5458
}
5559

5660
type completedConfig struct {
@@ -73,6 +77,9 @@ func (c *Config) Complete() CompletedConfig {
7377
if c.InsecureMetricsServing != nil {
7478
c.InsecureMetricsServing.Name = "metrics"
7579
}
80+
if c.Registry == nil {
81+
c.Registry = framework.NewRegistry()
82+
}
7683

7784
apiserver.AuthorizeClientBearerToken(c.LoopbackClientConfig, &c.Authentication, &c.Authorization)
7885

cmd/kube-scheduler/app/server.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ import (
5858
"k8s.io/klog"
5959
)
6060

61-
var frameworkRegistry = framework.NewRegistry()
62-
6361
// NewSchedulerCommand creates a *cobra.Command object with default parameters
6462
func NewSchedulerCommand() *cobra.Command {
63+
return NewSchedulerCommandWithRegistry(nil)
64+
}
65+
66+
// NewSchedulerCommandWithRegistry creates a *cobra.Command object with registry and default parameters
67+
func NewSchedulerCommandWithRegistry(registry framework.Registry) *cobra.Command {
6568
opts, err := options.NewOptions()
6669
if err != nil {
6770
klog.Fatalf("unable to initialize command options: %v", err)
@@ -77,7 +80,7 @@ constraints, affinity and anti-affinity specifications, data locality, inter-wor
7780
interference, deadlines, and so on. Workload-specific requirements will be exposed
7881
through the API as necessary.`,
7982
Run: func(cmd *cobra.Command, args []string) {
80-
if err := runCommand(cmd, args, opts); err != nil {
83+
if err := runCommand(cmd, args, opts, registry); err != nil {
8184
fmt.Fprintf(os.Stderr, "%v\n", err)
8285
os.Exit(1)
8386
}
@@ -108,7 +111,7 @@ through the API as necessary.`,
108111
}
109112

110113
// runCommand runs the scheduler.
111-
func runCommand(cmd *cobra.Command, args []string, opts *options.Options) error {
114+
func runCommand(cmd *cobra.Command, args []string, opts *options.Options, registry framework.Registry) error {
112115
verflag.PrintAndExitIfRequested()
113116
utilflag.PrintFlags(cmd.Flags())
114117

@@ -137,6 +140,10 @@ func runCommand(cmd *cobra.Command, args []string, opts *options.Options) error
137140

138141
stopCh := make(chan struct{})
139142

143+
if registry != nil {
144+
c.Registry = registry
145+
}
146+
140147
// Get the completed config
141148
cc := c.Complete()
142149

@@ -177,7 +184,7 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
177184
cc.Recorder,
178185
cc.ComponentConfig.AlgorithmSource,
179186
stopCh,
180-
frameworkRegistry,
187+
cc.Registry,
181188
cc.ComponentConfig.Plugins,
182189
cc.ComponentConfig.PluginConfig,
183190
scheduler.WithName(cc.ComponentConfig.SchedulerName),
@@ -328,9 +335,3 @@ func newHealthzHandler(config *kubeschedulerconfig.KubeSchedulerConfiguration, s
328335
}
329336
return pathRecorderMux
330337
}
331-
332-
// RegisterFrameworkPlugin adds a new plugin to the registry. If a plugin with the same name
333-
// exists, it returns an error.
334-
func RegisterFrameworkPlugin(name string, factory framework.PluginFactory) error {
335-
return frameworkRegistry.Register(name, factory)
336-
}

0 commit comments

Comments
 (0)