Fix frameworkImpl.extenders being not set

This commit is contained in:
Hidehito Yabuuchi 2021-06-19 18:07:31 +09:00
parent 2ff70c77c9
commit e371b27e6c
2 changed files with 53 additions and 4 deletions

View File

@ -160,6 +160,7 @@ func (c *Configurator) create() (*Scheduler, error) {
frameworkruntime.WithCaptureProfile(frameworkruntime.CaptureProfile(c.frameworkCapturer)),
frameworkruntime.WithClusterEventMap(c.clusterEventMap),
frameworkruntime.WithParallelism(int(c.parallellism)),
frameworkruntime.WithExtenders(extenders),
)
if err != nil {
return nil, fmt.Errorf("initializing profiles: %v", err)

View File

@ -126,10 +126,11 @@ func TestSchedulerCreation(t *testing.T) {
"Foo": defaultbinder.New,
}
cases := []struct {
name string
opts []Option
wantErr string
wantProfiles []string
name string
opts []Option
wantErr string
wantProfiles []string
wantExtenders []string
}{
{
name: "valid out-of-tree registry",
@ -211,6 +212,27 @@ func TestSchedulerCreation(t *testing.T) {
)},
wantErr: "duplicate profile with scheduler name \"foo\"",
},
{
name: "With extenders",
opts: []Option{
WithProfiles(
schedulerapi.KubeSchedulerProfile{
SchedulerName: "default-scheduler",
Plugins: &schedulerapi.Plugins{
QueueSort: schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "PrioritySort"}}},
Bind: schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "DefaultBinder"}}},
},
},
),
WithExtenders(
schedulerapi.Extender{
URLPrefix: "http://extender.kube-system/",
},
),
},
wantProfiles: []string{"default-scheduler"},
wantExtenders: []string{"http://extender.kube-system/"},
},
}
for _, tc := range cases {
@ -230,6 +252,7 @@ func TestSchedulerCreation(t *testing.T) {
tc.opts...,
)
// Errors
if len(tc.wantErr) != 0 {
if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
t.Errorf("got error %q, want %q", err, tc.wantErr)
@ -239,6 +262,8 @@ func TestSchedulerCreation(t *testing.T) {
if err != nil {
t.Fatalf("Failed to create scheduler: %v", err)
}
// Profiles
profiles := make([]string, 0, len(s.Profiles))
for name := range s.Profiles {
profiles = append(profiles, name)
@ -247,6 +272,29 @@ func TestSchedulerCreation(t *testing.T) {
if diff := cmp.Diff(tc.wantProfiles, profiles); diff != "" {
t.Errorf("unexpected profiles (-want, +got):\n%s", diff)
}
// Extenders
if len(tc.wantExtenders) != 0 {
// Scheduler.Extenders
extenders := make([]string, 0, len(s.Extenders))
for _, e := range s.Extenders {
extenders = append(extenders, e.Name())
}
if diff := cmp.Diff(tc.wantExtenders, extenders); diff != "" {
t.Errorf("unexpected extenders (-want, +got):\n%s", diff)
}
// framework.Handle.Extenders()
for _, p := range s.Profiles {
extenders := make([]string, 0, len(p.Extenders()))
for _, e := range p.Extenders() {
extenders = append(extenders, e.Name())
}
if diff := cmp.Diff(tc.wantExtenders, extenders); diff != "" {
t.Errorf("unexpected extenders (-want, +got):\n%s", diff)
}
}
}
})
}
}