From d949acc4066490b00d1675cff051a19ade790921 Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Thu, 25 Aug 2022 19:21:28 +0800 Subject: [PATCH] Fix the wrong status returned from `RunPreFilterPlugins` event msg will be impacted due to the wrong status is returned. e.g. Warning FailedScheduling ... running PreFilter plugin "PodTopologySpread": %!!(MISSING)w() Signed-off-by: Dave Chen --- pkg/scheduler/framework/runtime/framework.go | 2 +- .../framework/runtime/framework_test.go | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/framework/runtime/framework.go b/pkg/scheduler/framework/runtime/framework.go index 9408ff4bdb5e..4948e5a3543a 100644 --- a/pkg/scheduler/framework/runtime/framework.go +++ b/pkg/scheduler/framework/runtime/framework.go @@ -609,7 +609,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()) diff --git a/pkg/scheduler/framework/runtime/framework_test.go b/pkg/scheduler/framework/runtime/framework_test.go index 76d899a41c2c..755517a3e5ce 100644 --- a/pkg/scheduler/framework/runtime/framework_test.go +++ b/pkg/scheduler/framework/runtime/framework_test.go @@ -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