scheduler: remove FrameworkFactory.

This commit is contained in:
tangwz 2020-11-03 23:50:52 +08:00
parent bf5382a53e
commit 3341023664
3 changed files with 17 additions and 32 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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
}