From 7b8e5fb4f5c4ca8a89c450838909fd0be717bcd0 Mon Sep 17 00:00:00 2001 From: Ahmad Diaa Date: Sun, 10 Nov 2019 04:40:43 +0100 Subject: [PATCH] make Configurator.Create return a Scheduler --- pkg/scheduler/factory.go | 10 +++++----- pkg/scheduler/factory_test.go | 20 ++++++++++---------- pkg/scheduler/scheduler.go | 20 +++++++++++--------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index e50cec003cf..e2f07a4c8c5 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -291,12 +291,12 @@ func (c *Configurator) GetHardPodAffinitySymmetricWeight() int32 { } // Create creates a scheduler with the default algorithm provider. -func (c *Configurator) Create() (*Config, error) { +func (c *Configurator) Create() (*Scheduler, error) { return c.CreateFromProvider(DefaultProvider) } // CreateFromProvider creates a scheduler from the name of a registered algorithm provider. -func (c *Configurator) CreateFromProvider(providerName string) (*Config, error) { +func (c *Configurator) CreateFromProvider(providerName string) (*Scheduler, error) { klog.V(2).Infof("Creating scheduler from algorithm provider '%v'", providerName) provider, err := GetAlgorithmProvider(providerName) if err != nil { @@ -306,7 +306,7 @@ func (c *Configurator) CreateFromProvider(providerName string) (*Config, error) } // CreateFromConfig creates a scheduler from the configuration file -func (c *Configurator) CreateFromConfig(policy schedulerapi.Policy) (*Config, error) { +func (c *Configurator) CreateFromConfig(policy schedulerapi.Policy) (*Scheduler, error) { klog.V(2).Infof("Creating scheduler from configuration: %v", policy) // validate the policy configuration @@ -388,7 +388,7 @@ func (c *Configurator) CreateFromConfig(policy schedulerapi.Policy) (*Config, er } // CreateFromKeys creates a scheduler from a set of registered fit predicate keys and priority keys. -func (c *Configurator) CreateFromKeys(predicateKeys, priorityKeys sets.String, extenders []algorithm.SchedulerExtender) (*Config, error) { +func (c *Configurator) CreateFromKeys(predicateKeys, priorityKeys sets.String, extenders []algorithm.SchedulerExtender) (*Scheduler, error) { klog.V(2).Infof("Creating scheduler with fit predicates '%v' and priority functions '%v'", predicateKeys, priorityKeys) if c.GetHardPodAffinitySymmetricWeight() < 1 || c.GetHardPodAffinitySymmetricWeight() > 100 { @@ -478,7 +478,7 @@ func (c *Configurator) CreateFromKeys(predicateKeys, priorityKeys sets.String, e c.enableNonPreempting, ) - return &Config{ + return &Scheduler{ SchedulerCache: c.schedulerCache, Algorithm: algo, GetBinder: getBinderFunc(c.client, extenders), diff --git a/pkg/scheduler/factory_test.go b/pkg/scheduler/factory_test.go index fa17557433f..a52b7a37302 100644 --- a/pkg/scheduler/factory_test.go +++ b/pkg/scheduler/factory_test.go @@ -109,7 +109,7 @@ func TestCreateFromConfig(t *testing.T) { t.Errorf("Invalid configuration: %v", err) } - conf, err := factory.CreateFromConfig(policy) + sched, err := factory.CreateFromConfig(policy) if err != nil { t.Fatalf("CreateFromConfig failed: %v", err) } @@ -120,15 +120,15 @@ func TestCreateFromConfig(t *testing.T) { // Verify that node label predicate/priority are converted to framework plugins. wantArgs := `{"Name":"NodeLabel","Args":{"presentLabels":["zone"],"absentLabels":["foo"],"presentLabelsPreference":["l1"],"absentLabelsPreference":["l2"]}}` - verifyPluginConvertion(t, nodelabel.Name, []string{"FilterPlugin", "ScorePlugin"}, conf, 6, wantArgs) + verifyPluginConvertion(t, nodelabel.Name, []string{"FilterPlugin", "ScorePlugin"}, sched, 6, wantArgs) // Verify that service affinity custom predicate/priority is converted to framework plugin. wantArgs = `{"Name":"ServiceAffinity","Args":{"labels":["zone","foo"],"antiAffinityLabelsPreference":["rack","zone"]}}` - verifyPluginConvertion(t, serviceaffinity.Name, []string{"FilterPlugin", "ScorePlugin"}, conf, 6, wantArgs) + verifyPluginConvertion(t, serviceaffinity.Name, []string{"FilterPlugin", "ScorePlugin"}, sched, 6, wantArgs) } -func verifyPluginConvertion(t *testing.T, name string, extentionPoints []string, conf *Config, wantWeight int32, wantArgs string) { +func verifyPluginConvertion(t *testing.T, name string, extentionPoints []string, sched *Scheduler, wantWeight int32, wantArgs string) { for _, extensionPoint := range extentionPoints { - plugin, ok := findPlugin(name, extensionPoint, conf) + plugin, ok := findPlugin(name, extensionPoint, sched) if !ok { t.Fatalf("%q plugin does not exist in framework.", name) } @@ -138,7 +138,7 @@ func verifyPluginConvertion(t *testing.T, name string, extentionPoints []string, } } // Verify that the policy config is converted to plugin config. - pluginConfig := findPluginConfig(name, conf) + pluginConfig := findPluginConfig(name, sched) encoding, err := json.Marshal(pluginConfig) if err != nil { t.Errorf("Failed to marshal %+v: %v", pluginConfig, err) @@ -149,8 +149,8 @@ func verifyPluginConvertion(t *testing.T, name string, extentionPoints []string, } } -func findPlugin(name, extensionPoint string, schedConf *Config) (schedulerapi.Plugin, bool) { - for _, pl := range schedConf.Framework.ListPlugins()[extensionPoint] { +func findPlugin(name, extensionPoint string, sched *Scheduler) (schedulerapi.Plugin, bool) { + for _, pl := range sched.Framework.ListPlugins()[extensionPoint] { if pl.Name == name { return pl, true } @@ -158,8 +158,8 @@ func findPlugin(name, extensionPoint string, schedConf *Config) (schedulerapi.Pl return schedulerapi.Plugin{}, false } -func findPluginConfig(name string, schedConf *Config) schedulerapi.PluginConfig { - for _, c := range schedConf.PluginConfig { +func findPluginConfig(name string, sched *Scheduler) schedulerapi.PluginConfig { + for _, c := range sched.PluginConfig { if c.Name == name { return c } diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index 6fe15338bc0..89eb8151672 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -119,6 +119,10 @@ type Scheduler struct { SchedulingQueue internalqueue.SchedulingQueue scheduledPodsHasSynced func() bool + + // The final configuration of the framework. + Plugins schedulerapi.Plugins + PluginConfig []schedulerapi.PluginConfig } // Cache returns the cache in scheduler for test to check the data in scheduler. @@ -321,7 +325,7 @@ func New(client clientset.Interface, Plugins: options.frameworkPlugins, PluginConfig: options.frameworkPluginConfig, }) - var config *Config + var sched *Scheduler source := schedulerAlgorithmSource switch { case source.Provider != nil: @@ -330,7 +334,7 @@ func New(client clientset.Interface, if err != nil { return nil, fmt.Errorf("couldn't create scheduler using provider %q: %v", *source.Provider, err) } - config = sc + sched = sc case source.Policy != nil: // Create the config from a user specified policy source. policy := &schedulerapi.Policy{} @@ -348,17 +352,15 @@ func New(client clientset.Interface, if err != nil { return nil, fmt.Errorf("couldn't create scheduler from policy: %v", err) } - config = sc + sched = sc default: return nil, fmt.Errorf("unsupported algorithm source: %v", source) } + metrics.Register() // Additional tweaks to the config produced by the configurator. - config.Recorder = recorder - config.DisablePreemption = options.disablePreemption - config.StopEverything = stopCh - - // Create the scheduler. - sched := NewFromConfig(config) + sched.Recorder = recorder + sched.DisablePreemption = options.disablePreemption + sched.StopEverything = stopCh sched.podConditionUpdater = &podConditionUpdaterImpl{client} sched.podPreemptor = &podPreemptorImpl{client} sched.scheduledPodsHasSynced = podInformer.Informer().HasSynced