Skip to content

Commit dd213f0

Browse files
authored
Merge pull request kubernetes#103019 from ordovicia/fix-scheduler-framework-extenders
Fix scheduler extenders being not called on preemptions
2 parents 0634437 + e371b27 commit dd213f0

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

pkg/scheduler/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func (c *Configurator) create() (*Scheduler, error) {
160160
frameworkruntime.WithCaptureProfile(frameworkruntime.CaptureProfile(c.frameworkCapturer)),
161161
frameworkruntime.WithClusterEventMap(c.clusterEventMap),
162162
frameworkruntime.WithParallelism(int(c.parallellism)),
163+
frameworkruntime.WithExtenders(extenders),
163164
)
164165
if err != nil {
165166
return nil, fmt.Errorf("initializing profiles: %v", err)

pkg/scheduler/scheduler_test.go

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ func TestSchedulerCreation(t *testing.T) {
126126
"Foo": defaultbinder.New,
127127
}
128128
cases := []struct {
129-
name string
130-
opts []Option
131-
wantErr string
132-
wantProfiles []string
129+
name string
130+
opts []Option
131+
wantErr string
132+
wantProfiles []string
133+
wantExtenders []string
133134
}{
134135
{
135136
name: "valid out-of-tree registry",
@@ -211,6 +212,27 @@ func TestSchedulerCreation(t *testing.T) {
211212
)},
212213
wantErr: "duplicate profile with scheduler name \"foo\"",
213214
},
215+
{
216+
name: "With extenders",
217+
opts: []Option{
218+
WithProfiles(
219+
schedulerapi.KubeSchedulerProfile{
220+
SchedulerName: "default-scheduler",
221+
Plugins: &schedulerapi.Plugins{
222+
QueueSort: schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "PrioritySort"}}},
223+
Bind: schedulerapi.PluginSet{Enabled: []schedulerapi.Plugin{{Name: "DefaultBinder"}}},
224+
},
225+
},
226+
),
227+
WithExtenders(
228+
schedulerapi.Extender{
229+
URLPrefix: "http://extender.kube-system/",
230+
},
231+
),
232+
},
233+
wantProfiles: []string{"default-scheduler"},
234+
wantExtenders: []string{"http://extender.kube-system/"},
235+
},
214236
}
215237

216238
for _, tc := range cases {
@@ -230,6 +252,7 @@ func TestSchedulerCreation(t *testing.T) {
230252
tc.opts...,
231253
)
232254

255+
// Errors
233256
if len(tc.wantErr) != 0 {
234257
if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
235258
t.Errorf("got error %q, want %q", err, tc.wantErr)
@@ -239,6 +262,8 @@ func TestSchedulerCreation(t *testing.T) {
239262
if err != nil {
240263
t.Fatalf("Failed to create scheduler: %v", err)
241264
}
265+
266+
// Profiles
242267
profiles := make([]string, 0, len(s.Profiles))
243268
for name := range s.Profiles {
244269
profiles = append(profiles, name)
@@ -247,6 +272,29 @@ func TestSchedulerCreation(t *testing.T) {
247272
if diff := cmp.Diff(tc.wantProfiles, profiles); diff != "" {
248273
t.Errorf("unexpected profiles (-want, +got):\n%s", diff)
249274
}
275+
276+
// Extenders
277+
if len(tc.wantExtenders) != 0 {
278+
// Scheduler.Extenders
279+
extenders := make([]string, 0, len(s.Extenders))
280+
for _, e := range s.Extenders {
281+
extenders = append(extenders, e.Name())
282+
}
283+
if diff := cmp.Diff(tc.wantExtenders, extenders); diff != "" {
284+
t.Errorf("unexpected extenders (-want, +got):\n%s", diff)
285+
}
286+
287+
// framework.Handle.Extenders()
288+
for _, p := range s.Profiles {
289+
extenders := make([]string, 0, len(p.Extenders()))
290+
for _, e := range p.Extenders() {
291+
extenders = append(extenders, e.Name())
292+
}
293+
if diff := cmp.Diff(tc.wantExtenders, extenders); diff != "" {
294+
t.Errorf("unexpected extenders (-want, +got):\n%s", diff)
295+
}
296+
}
297+
}
250298
})
251299
}
252300
}

0 commit comments

Comments
 (0)