From 3341023664d9f00c63debc61217d74c501db3051 Mon Sep 17 00:00:00 2001 From: tangwz Date: Tue, 3 Nov 2020 23:50:52 +0800 Subject: [PATCH] scheduler: remove FrameworkFactory. --- pkg/scheduler/factory.go | 32 ++++++++++----------------- pkg/scheduler/profile/profile.go | 11 ++++----- pkg/scheduler/profile/profile_test.go | 6 +---- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index 89d6fc548c7..90e52bf5a94 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -84,24 +84,6 @@ type Configurator struct { frameworkCapturer FrameworkCapturer } -func (c *Configurator) buildFramework(p schedulerapi.KubeSchedulerProfile, opts ...frameworkruntime.Option) (framework.Framework, error) { - if c.frameworkCapturer != nil { - c.frameworkCapturer(p) - } - opts = append([]frameworkruntime.Option{ - frameworkruntime.WithClientSet(c.client), - frameworkruntime.WithInformerFactory(c.informerFactory), - frameworkruntime.WithSnapshotSharedLister(c.nodeInfoSnapshot), - frameworkruntime.WithRunAllFilters(c.alwaysCheckAllPredicates), - }, opts...) - return frameworkruntime.NewFramework( - c.registry, - p.Plugins, - p.PluginConfig, - opts..., - ) -} - // create a scheduler from a set of registered plugins. func (c *Configurator) create() (*Scheduler, error) { var extenders []framework.Extender @@ -149,8 +131,18 @@ func (c *Configurator) create() (*Scheduler, error) { // The nominator will be passed all the way to framework instantiation. nominator := internalqueue.NewPodNominator() - profiles, err := profile.NewMap(c.profiles, c.buildFramework, c.recorderFactory, - frameworkruntime.WithPodNominator(nominator)) + profiles, err := profile.NewMap(c.profiles, c.registry, c.recorderFactory, + frameworkruntime.WithClientSet(c.client), + frameworkruntime.WithInformerFactory(c.informerFactory), + frameworkruntime.WithSnapshotSharedLister(c.nodeInfoSnapshot), + frameworkruntime.WithRunAllFilters(c.alwaysCheckAllPredicates), + frameworkruntime.WithPodNominator(nominator), + ) + for _, p := range c.profiles { + if c.frameworkCapturer != nil { + c.frameworkCapturer(p) + } + } if err != nil { return nil, fmt.Errorf("initializing profiles: %v", err) } diff --git a/pkg/scheduler/profile/profile.go b/pkg/scheduler/profile/profile.go index 621a7319418..5b174763084 100644 --- a/pkg/scheduler/profile/profile.go +++ b/pkg/scheduler/profile/profile.go @@ -33,15 +33,12 @@ import ( // RecorderFactory builds an EventRecorder for a given scheduler name. type RecorderFactory func(string) events.EventRecorder -// FrameworkFactory builds a Framework for a given profile configuration. -type FrameworkFactory func(config.KubeSchedulerProfile, ...frameworkruntime.Option) (framework.Framework, error) - // newProfile builds a Profile for the given configuration. -func newProfile(cfg config.KubeSchedulerProfile, frameworkFact FrameworkFactory, recorderFact RecorderFactory, +func newProfile(cfg config.KubeSchedulerProfile, r frameworkruntime.Registry, recorderFact RecorderFactory, opts ...frameworkruntime.Option) (framework.Framework, error) { recorder := recorderFact(cfg.SchedulerName) opts = append(opts, frameworkruntime.WithEventRecorder(recorder), frameworkruntime.WithProfileName(cfg.SchedulerName)) - fwk, err := frameworkFact(cfg, opts...) + fwk, err := frameworkruntime.NewFramework(r, cfg.Plugins, cfg.PluginConfig, opts...) if err != nil { return nil, err } @@ -52,7 +49,7 @@ func newProfile(cfg config.KubeSchedulerProfile, frameworkFact FrameworkFactory, type Map map[string]framework.Framework // NewMap builds the frameworks given by the configuration, indexed by name. -func NewMap(cfgs []config.KubeSchedulerProfile, frameworkFact FrameworkFactory, recorderFact RecorderFactory, +func NewMap(cfgs []config.KubeSchedulerProfile, r frameworkruntime.Registry, recorderFact RecorderFactory, opts ...frameworkruntime.Option) (Map, error) { m := make(Map) v := cfgValidator{m: m} @@ -61,7 +58,7 @@ func NewMap(cfgs []config.KubeSchedulerProfile, frameworkFact FrameworkFactory, if err := v.validate(cfg); err != nil { return nil, err } - p, err := newProfile(cfg, frameworkFact, recorderFact, opts...) + p, err := newProfile(cfg, r, recorderFact, opts...) if err != nil { return nil, fmt.Errorf("creating profile for scheduler name %s: %v", cfg.SchedulerName, err) } diff --git a/pkg/scheduler/profile/profile_test.go b/pkg/scheduler/profile/profile_test.go index bccfe01654d..fa17c3dfaeb 100644 --- a/pkg/scheduler/profile/profile_test.go +++ b/pkg/scheduler/profile/profile_test.go @@ -246,7 +246,7 @@ func TestNewMap(t *testing.T) { } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - m, err := NewMap(tc.cfgs, fakeFrameworkFactory, nilRecorderFactory) + m, err := NewMap(tc.cfgs, fakeRegistry, nilRecorderFactory) if err := checkErr(err, tc.wantErr); err != nil { t.Fatal(err) } @@ -278,10 +278,6 @@ func newFakePlugin(_ runtime.Object, _ framework.Handle) (framework.Plugin, erro return &fakePlugin{}, nil } -func fakeFrameworkFactory(cfg config.KubeSchedulerProfile, opts ...frameworkruntime.Option) (framework.Framework, error) { - return frameworkruntime.NewFramework(fakeRegistry, cfg.Plugins, cfg.PluginConfig, opts...) -} - func nilRecorderFactory(_ string) events.EventRecorder { return nil }