Skip to content

Commit

Permalink
Fix the wrong status returned from RunPreFilterPlugins
Browse files Browse the repository at this point in the history
event msg will be impacted due to the wrong status is returned.
e.g.

Warning  FailedScheduling ... running PreFilter plugin "PodTopologySpread": %!!(MISSING)w(<nil>)

Signed-off-by: Dave Chen <dave.chen@arm.com>
  • Loading branch information
chendave committed Aug 26, 2022
1 parent a1128e3 commit 8a288d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/scheduler/framework/runtime/framework.go
Expand Up @@ -605,7 +605,7 @@ func (f *frameworkImpl) RunPreFilterPlugins(ctx context.Context, state *framewor
if s.IsUnschedulable() {
return nil, s
}
return nil, framework.AsStatus(fmt.Errorf("running PreFilter plugin %q: %w", pl.Name(), status.AsError())).WithFailedPlugin(pl.Name())
return nil, framework.AsStatus(fmt.Errorf("running PreFilter plugin %q: %w", pl.Name(), s.AsError())).WithFailedPlugin(pl.Name())
}
if !r.AllNodes() {
pluginsWithNodes = append(pluginsWithNodes, pl.Name())
Expand Down
28 changes: 28 additions & 0 deletions pkg/scheduler/framework/runtime/framework_test.go
Expand Up @@ -1240,6 +1240,34 @@ func TestPreFilterPlugins(t *testing.T) {
})
}

func TestRunPreFilterPluginsStatus(t *testing.T) {
preFilter := &TestPlugin{
name: preFilterPluginName,
inj: injectedResult{PreFilterStatus: int(framework.Error)},
}
r := make(Registry)
r.Register(preFilterPluginName,
func(_ runtime.Object, fh framework.Handle) (framework.Plugin, error) {
return preFilter, nil
})

plugins := &config.Plugins{PreFilter: config.PluginSet{Enabled: []config.Plugin{{Name: preFilterPluginName}}}}

profile := config.KubeSchedulerProfile{Plugins: plugins}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

f, err := newFrameworkWithQueueSortAndBind(r, profile, ctx.Done())
if err != nil {
t.Fatalf("Failed to create framework for testing: %v", err)
}
_, status := f.RunPreFilterPlugins(ctx, nil, nil)
wantStatus := framework.AsStatus(fmt.Errorf("running PreFilter plugin %q: %w", preFilter.Name(), errInjectedStatus)).WithFailedPlugin(preFilter.Name())
if !reflect.DeepEqual(status, wantStatus) {
t.Errorf("wrong status. got: %v, want:%v", status, wantStatus)
}
}

func TestFilterPlugins(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 8a288d6

Please sign in to comment.