Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor scheduler.New so that all framework-related parameters are options #83418

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmd/kube-scheduler/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,15 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}, regis
cc.Recorder,
cc.ComponentConfig.AlgorithmSource,
stopCh,
registry,
cc.ComponentConfig.Plugins,
cc.ComponentConfig.PluginConfig,
scheduler.WithName(cc.ComponentConfig.SchedulerName),
scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight),
scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption),
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
scheduler.WithBindTimeoutSeconds(*cc.ComponentConfig.BindTimeoutSeconds))
scheduler.WithBindTimeoutSeconds(*cc.ComponentConfig.BindTimeoutSeconds),
scheduler.WithFrameworkRegistry(registry),
scheduler.WithFrameworkPlugins(cc.ComponentConfig.Plugins),
scheduler.WithFrameworkPluginConfig(cc.ComponentConfig.PluginConfig),
)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/scheduler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/core:go_default_library",
"//pkg/scheduler/factory:go_default_library",
"//pkg/scheduler/framework/plugins:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library",
"//pkg/scheduler/internal/queue:go_default_library",
Expand Down
1 change: 0 additions & 1 deletion pkg/scheduler/api/compatibility/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ go_test(
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/core:go_default_library",
"//pkg/scheduler/factory:go_default_library",
"//pkg/scheduler/framework/plugins:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
Expand Down
4 changes: 0 additions & 4 deletions pkg/scheduler/api/compatibility/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/core"
"k8s.io/kubernetes/pkg/scheduler/factory"
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
)

func TestCompatibility_v1_Scheduler(t *testing.T) {
Expand Down Expand Up @@ -1163,9 +1162,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
nil,
algorithmSrc,
make(chan struct{}),
schedulerframework.NewDefaultRegistry(),
nil,
[]kubeschedulerconfig.PluginConfig{},
)
if err != nil {
t.Fatalf("%s: Error constructing: %v", v, err)
Expand Down
74 changes: 58 additions & 16 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/core"
"k8s.io/kubernetes/pkg/scheduler/factory"
frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
Expand Down Expand Up @@ -109,11 +110,15 @@ func (sched *Scheduler) Cache() internalcache.Cache {
}

type schedulerOptions struct {
schedulerName string
hardPodAffinitySymmetricWeight int32
disablePreemption bool
percentageOfNodesToScore int32
bindTimeoutSeconds int64
schedulerName string
hardPodAffinitySymmetricWeight int32
disablePreemption bool
percentageOfNodesToScore int32
bindTimeoutSeconds int64
frameworkRegistry framework.Registry
frameworkConfigProducerRegistry *frameworkplugins.ConfigProducerRegistry
frameworkPlugins *kubeschedulerconfig.Plugins
frameworkPluginConfig []kubeschedulerconfig.PluginConfig
}

// Option configures a Scheduler
Expand Down Expand Up @@ -154,12 +159,51 @@ func WithBindTimeoutSeconds(bindTimeoutSeconds int64) Option {
}
}

// WithFrameworkRegistry sets the framework registry.
func WithFrameworkRegistry(registry framework.Registry) Option {
return func(o *schedulerOptions) {
o.frameworkRegistry = registry
}
}

// WithFrameworkConfigProducerRegistry sets the framework plugin producer registry.
func WithFrameworkConfigProducerRegistry(registry *frameworkplugins.ConfigProducerRegistry) Option {
return func(o *schedulerOptions) {
o.frameworkConfigProducerRegistry = registry
}
}

// WithFrameworkPlugins sets the plugins that the framework should be configured with.
func WithFrameworkPlugins(plugins *kubeschedulerconfig.Plugins) Option {
return func(o *schedulerOptions) {
o.frameworkPlugins = plugins
}
}

// WithFrameworkPluginConfig sets the PluginConfig slice that the framework should be configured with.
func WithFrameworkPluginConfig(pluginConfig []kubeschedulerconfig.PluginConfig) Option {
return func(o *schedulerOptions) {
o.frameworkPluginConfig = pluginConfig
}
}

var defaultSchedulerOptions = schedulerOptions{
schedulerName: v1.DefaultSchedulerName,
hardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
disablePreemption: false,
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
bindTimeoutSeconds: BindTimeoutSeconds,
schedulerName: v1.DefaultSchedulerName,
hardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
disablePreemption: false,
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
bindTimeoutSeconds: BindTimeoutSeconds,
frameworkRegistry: frameworkplugins.NewDefaultRegistry(),
frameworkConfigProducerRegistry: frameworkplugins.NewDefaultConfigProducerRegistry(),
// The plugins and pluginConfig options are currently nil because we currently don't have
// "default" plugins. All plugins that we run through the framework currently come from two
// sources: 1) specified in component config, in which case those two options should be
// set using their corresponding With* functions, 2) predicate/priority-mapped plugins, which
// pluginConfigProducerRegistry contains a mapping for and produces their configurations.
// TODO(ahg-g) Once predicates and priorities are migrated to natively run as plugins, the
// below two parameters will be populated accordingly.
frameworkPlugins: nil,
frameworkPluginConfig: nil,
}

// New returns a Scheduler
Expand All @@ -178,9 +222,6 @@ func New(client clientset.Interface,
recorder events.EventRecorder,
schedulerAlgorithmSource kubeschedulerconfig.SchedulerAlgorithmSource,
stopCh <-chan struct{},
registry framework.Registry,
plugins *kubeschedulerconfig.Plugins,
pluginConfig []kubeschedulerconfig.PluginConfig,
opts ...Option) (*Scheduler, error) {

options := defaultSchedulerOptions
Expand All @@ -205,9 +246,10 @@ func New(client clientset.Interface,
DisablePreemption: options.disablePreemption,
PercentageOfNodesToScore: options.percentageOfNodesToScore,
BindTimeoutSeconds: options.bindTimeoutSeconds,
Registry: registry,
Plugins: plugins,
PluginConfig: pluginConfig,
Registry: options.frameworkRegistry,
PluginConfigProducerRegistry: options.frameworkConfigProducerRegistry,
Plugins: options.frameworkPlugins,
PluginConfig: options.frameworkPluginConfig,
})
var config *factory.Config
source := schedulerAlgorithmSource
Expand Down
10 changes: 2 additions & 8 deletions pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ import (

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

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

defaultBindTimeout := int64(30)
factory.RegisterFitPredicate("PredicateOne", PredicateOne)
factory.RegisterPriorityFunction("PriorityOne", PriorityOne, 1)
factory.RegisterAlgorithmProvider(testSource, sets.NewString("PredicateOne"), sets.NewString("PriorityOne"))
Expand All @@ -200,10 +197,7 @@ func TestSchedulerCreation(t *testing.T) {
eventBroadcaster.NewRecorder(scheme.Scheme, "scheduler"),
kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &testSource},
stopCh,
emptyPluginRegistry,
nil,
emptyPluginConfig,
WithBindTimeoutSeconds(defaultBindTimeout))
)

if err != nil {
t.Fatalf("Failed to create scheduler: %v", err)
Expand Down
1 change: 0 additions & 1 deletion test/integration/daemonset/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ go_test(
"//pkg/scheduler/algorithmprovider:go_default_library",
"//pkg/scheduler/api:go_default_library",
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/plugins:go_default_library",
"//pkg/util/labels:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
Expand Down
4 changes: 0 additions & 4 deletions test/integration/daemonset/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import (
"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
labelsutil "k8s.io/kubernetes/pkg/util/labels"
"k8s.io/kubernetes/test/integration/framework"
)
Expand Down Expand Up @@ -126,9 +125,6 @@ func setupScheduler(
Provider: &defaultProviderName,
},
stopCh,
schedulerframework.NewDefaultRegistry(),
nil,
[]schedulerconfig.PluginConfig{},
)
if err != nil {
t.Fatalf("Couldn't create scheduler: %v", err)
Expand Down
2 changes: 0 additions & 2 deletions test/integration/scheduler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ go_library(
"//pkg/scheduler/api/latest:go_default_library",
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/factory:go_default_library",
"//pkg/scheduler/framework/plugins:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/util/taints:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/policy/v1beta1:go_default_library",
Expand Down