Skip to content

Commit 0a17315

Browse files
authored
Merge pull request kubernetes#83418 from ahg-g/ahg-first-priority
Refactor scheduler.New so that all framework-related parameters are options
2 parents 5fbda60 + 30e7016 commit 0a17315

File tree

17 files changed

+216
-279
lines changed

17 files changed

+216
-279
lines changed

cmd/kube-scheduler/app/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,15 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}, regis
182182
cc.Recorder,
183183
cc.ComponentConfig.AlgorithmSource,
184184
stopCh,
185-
registry,
186-
cc.ComponentConfig.Plugins,
187-
cc.ComponentConfig.PluginConfig,
188185
scheduler.WithName(cc.ComponentConfig.SchedulerName),
189186
scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight),
190187
scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption),
191188
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
192-
scheduler.WithBindTimeoutSeconds(*cc.ComponentConfig.BindTimeoutSeconds))
189+
scheduler.WithBindTimeoutSeconds(*cc.ComponentConfig.BindTimeoutSeconds),
190+
scheduler.WithFrameworkRegistry(registry),
191+
scheduler.WithFrameworkPlugins(cc.ComponentConfig.Plugins),
192+
scheduler.WithFrameworkPluginConfig(cc.ComponentConfig.PluginConfig),
193+
)
193194
if err != nil {
194195
return err
195196
}

pkg/scheduler/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ go_library(
1616
"//pkg/scheduler/apis/config:go_default_library",
1717
"//pkg/scheduler/core:go_default_library",
1818
"//pkg/scheduler/factory:go_default_library",
19+
"//pkg/scheduler/framework/plugins:go_default_library",
1920
"//pkg/scheduler/framework/v1alpha1:go_default_library",
2021
"//pkg/scheduler/internal/cache:go_default_library",
2122
"//pkg/scheduler/internal/queue:go_default_library",

pkg/scheduler/api/compatibility/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ go_test(
1111
"//pkg/scheduler/apis/config:go_default_library",
1212
"//pkg/scheduler/core:go_default_library",
1313
"//pkg/scheduler/factory:go_default_library",
14-
"//pkg/scheduler/framework/plugins:go_default_library",
1514
"//staging/src/k8s.io/api/core/v1:go_default_library",
1615
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
1716
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",

pkg/scheduler/api/compatibility/compatibility_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
3333
"k8s.io/kubernetes/pkg/scheduler/core"
3434
"k8s.io/kubernetes/pkg/scheduler/factory"
35-
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
3635
)
3736

3837
func TestCompatibility_v1_Scheduler(t *testing.T) {
@@ -1163,9 +1162,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11631162
nil,
11641163
algorithmSrc,
11651164
make(chan struct{}),
1166-
schedulerframework.NewDefaultRegistry(),
1167-
nil,
1168-
[]kubeschedulerconfig.PluginConfig{},
11691165
)
11701166
if err != nil {
11711167
t.Fatalf("%s: Error constructing: %v", v, err)

pkg/scheduler/scheduler.go

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
4242
"k8s.io/kubernetes/pkg/scheduler/core"
4343
"k8s.io/kubernetes/pkg/scheduler/factory"
44+
frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
4445
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
4546
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
4647
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
@@ -116,11 +117,15 @@ func (sched *Scheduler) Cache() internalcache.Cache {
116117
}
117118

118119
type schedulerOptions struct {
119-
schedulerName string
120-
hardPodAffinitySymmetricWeight int32
121-
disablePreemption bool
122-
percentageOfNodesToScore int32
123-
bindTimeoutSeconds int64
120+
schedulerName string
121+
hardPodAffinitySymmetricWeight int32
122+
disablePreemption bool
123+
percentageOfNodesToScore int32
124+
bindTimeoutSeconds int64
125+
frameworkRegistry framework.Registry
126+
frameworkConfigProducerRegistry *frameworkplugins.ConfigProducerRegistry
127+
frameworkPlugins *kubeschedulerconfig.Plugins
128+
frameworkPluginConfig []kubeschedulerconfig.PluginConfig
124129
}
125130

126131
// Option configures a Scheduler
@@ -161,12 +166,51 @@ func WithBindTimeoutSeconds(bindTimeoutSeconds int64) Option {
161166
}
162167
}
163168

169+
// WithFrameworkRegistry sets the framework registry.
170+
func WithFrameworkRegistry(registry framework.Registry) Option {
171+
return func(o *schedulerOptions) {
172+
o.frameworkRegistry = registry
173+
}
174+
}
175+
176+
// WithFrameworkConfigProducerRegistry sets the framework plugin producer registry.
177+
func WithFrameworkConfigProducerRegistry(registry *frameworkplugins.ConfigProducerRegistry) Option {
178+
return func(o *schedulerOptions) {
179+
o.frameworkConfigProducerRegistry = registry
180+
}
181+
}
182+
183+
// WithFrameworkPlugins sets the plugins that the framework should be configured with.
184+
func WithFrameworkPlugins(plugins *kubeschedulerconfig.Plugins) Option {
185+
return func(o *schedulerOptions) {
186+
o.frameworkPlugins = plugins
187+
}
188+
}
189+
190+
// WithFrameworkPluginConfig sets the PluginConfig slice that the framework should be configured with.
191+
func WithFrameworkPluginConfig(pluginConfig []kubeschedulerconfig.PluginConfig) Option {
192+
return func(o *schedulerOptions) {
193+
o.frameworkPluginConfig = pluginConfig
194+
}
195+
}
196+
164197
var defaultSchedulerOptions = schedulerOptions{
165-
schedulerName: v1.DefaultSchedulerName,
166-
hardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
167-
disablePreemption: false,
168-
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
169-
bindTimeoutSeconds: BindTimeoutSeconds,
198+
schedulerName: v1.DefaultSchedulerName,
199+
hardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
200+
disablePreemption: false,
201+
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
202+
bindTimeoutSeconds: BindTimeoutSeconds,
203+
frameworkRegistry: frameworkplugins.NewDefaultRegistry(),
204+
frameworkConfigProducerRegistry: frameworkplugins.NewDefaultConfigProducerRegistry(),
205+
// The plugins and pluginConfig options are currently nil because we currently don't have
206+
// "default" plugins. All plugins that we run through the framework currently come from two
207+
// sources: 1) specified in component config, in which case those two options should be
208+
// set using their corresponding With* functions, 2) predicate/priority-mapped plugins, which
209+
// pluginConfigProducerRegistry contains a mapping for and produces their configurations.
210+
// TODO(ahg-g) Once predicates and priorities are migrated to natively run as plugins, the
211+
// below two parameters will be populated accordingly.
212+
frameworkPlugins: nil,
213+
frameworkPluginConfig: nil,
170214
}
171215

172216
// New returns a Scheduler
@@ -185,9 +229,6 @@ func New(client clientset.Interface,
185229
recorder events.EventRecorder,
186230
schedulerAlgorithmSource kubeschedulerconfig.SchedulerAlgorithmSource,
187231
stopCh <-chan struct{},
188-
registry framework.Registry,
189-
plugins *kubeschedulerconfig.Plugins,
190-
pluginConfig []kubeschedulerconfig.PluginConfig,
191232
opts ...Option) (*Scheduler, error) {
192233

193234
options := defaultSchedulerOptions
@@ -212,9 +253,10 @@ func New(client clientset.Interface,
212253
DisablePreemption: options.disablePreemption,
213254
PercentageOfNodesToScore: options.percentageOfNodesToScore,
214255
BindTimeoutSeconds: options.bindTimeoutSeconds,
215-
Registry: registry,
216-
Plugins: plugins,
217-
PluginConfig: pluginConfig,
256+
Registry: options.frameworkRegistry,
257+
PluginConfigProducerRegistry: options.frameworkConfigProducerRegistry,
258+
Plugins: options.frameworkPlugins,
259+
PluginConfig: options.frameworkPluginConfig,
218260
})
219261
var config *factory.Config
220262
source := schedulerAlgorithmSource

pkg/scheduler/scheduler_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ import (
5959

6060
var (
6161
emptyPluginRegistry = framework.Registry{}
62-
// emptyPluginConfig is an empty plugin config used in tests.
63-
emptyPluginConfig []kubeschedulerconfig.PluginConfig
6462
// emptyFramework is an empty framework used in tests.
6563
// Note: If the test runs in goroutine, please don't use this variable to avoid a race condition.
66-
emptyFramework, _ = framework.NewFramework(emptyPluginRegistry, nil, emptyPluginConfig)
64+
emptyFramework, _ = framework.NewFramework(emptyPluginRegistry, nil, nil)
6765
)
6866

6967
type fakeBinder struct {
@@ -178,7 +176,6 @@ func TestSchedulerCreation(t *testing.T) {
178176
testSource := "testProvider"
179177
eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1beta1().Events("")})
180178

181-
defaultBindTimeout := int64(30)
182179
factory.RegisterFitPredicate("PredicateOne", PredicateOne)
183180
factory.RegisterPriorityFunction("PriorityOne", PriorityOne, 1)
184181
factory.RegisterAlgorithmProvider(testSource, sets.NewString("PredicateOne"), sets.NewString("PriorityOne"))
@@ -200,10 +197,7 @@ func TestSchedulerCreation(t *testing.T) {
200197
eventBroadcaster.NewRecorder(scheme.Scheme, "scheduler"),
201198
kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &testSource},
202199
stopCh,
203-
emptyPluginRegistry,
204-
nil,
205-
emptyPluginConfig,
206-
WithBindTimeoutSeconds(defaultBindTimeout))
200+
)
207201

208202
if err != nil {
209203
t.Fatalf("Failed to create scheduler: %v", err)

test/integration/daemonset/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ go_test(
2323
"//pkg/scheduler/algorithmprovider:go_default_library",
2424
"//pkg/scheduler/api:go_default_library",
2525
"//pkg/scheduler/apis/config:go_default_library",
26-
"//pkg/scheduler/framework/plugins:go_default_library",
2726
"//pkg/util/labels:go_default_library",
2827
"//staging/src/k8s.io/api/apps/v1:go_default_library",
2928
"//staging/src/k8s.io/api/core/v1:go_default_library",

test/integration/daemonset/daemonset_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import (
5151
"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
5252
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
5353
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
54-
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
5554
labelsutil "k8s.io/kubernetes/pkg/util/labels"
5655
"k8s.io/kubernetes/test/integration/framework"
5756
)
@@ -126,9 +125,6 @@ func setupScheduler(
126125
Provider: &defaultProviderName,
127126
},
128127
stopCh,
129-
schedulerframework.NewDefaultRegistry(),
130-
nil,
131-
[]schedulerconfig.PluginConfig{},
132128
)
133129
if err != nil {
134130
t.Fatalf("Couldn't create scheduler: %v", err)

test/integration/scheduler/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ go_library(
9797
"//pkg/scheduler/api/latest:go_default_library",
9898
"//pkg/scheduler/apis/config:go_default_library",
9999
"//pkg/scheduler/factory:go_default_library",
100-
"//pkg/scheduler/framework/plugins:go_default_library",
101-
"//pkg/scheduler/framework/v1alpha1:go_default_library",
102100
"//pkg/util/taints:go_default_library",
103101
"//staging/src/k8s.io/api/core/v1:go_default_library",
104102
"//staging/src/k8s.io/api/policy/v1beta1:go_default_library",

0 commit comments

Comments
 (0)