From b02aad42fa4cb630b457fc580b242661f483198c Mon Sep 17 00:00:00 2001 From: kerthcet Date: Tue, 31 Oct 2023 16:02:16 +0800 Subject: [PATCH] Fix panic when process RunScorePlugins for cap out of range Signed-off-by: kerthcet --- pkg/scheduler/framework/runtime/framework.go | 2 +- .../framework/runtime/framework_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/framework/runtime/framework.go b/pkg/scheduler/framework/runtime/framework.go index 4d4588ef5b8..df26e5f21a2 100644 --- a/pkg/scheduler/framework/runtime/framework.go +++ b/pkg/scheduler/framework/runtime/framework.go @@ -1015,7 +1015,7 @@ func (f *frameworkImpl) RunScorePlugins(ctx context.Context, state *framework.Cy metrics.FrameworkExtensionPointDuration.WithLabelValues(metrics.Score, status.Code().String(), f.profileName).Observe(metrics.SinceInSeconds(startTime)) }() allNodePluginScores := make([]framework.NodePluginScores, len(nodes)) - numPlugins := len(f.scorePlugins) - state.SkipScorePlugins.Len() + numPlugins := len(f.scorePlugins) plugins := make([]framework.ScorePlugin, 0, numPlugins) pluginToNodeScores := make(map[string]framework.NodeScoreList, numPlugins) for _, pl := range f.scorePlugins { diff --git a/pkg/scheduler/framework/runtime/framework_test.go b/pkg/scheduler/framework/runtime/framework_test.go index f5ae23dfd5e..7c5bf26c64f 100644 --- a/pkg/scheduler/framework/runtime/framework_test.go +++ b/pkg/scheduler/framework/runtime/framework_test.go @@ -1385,6 +1385,22 @@ func TestRunScorePlugins(t *testing.T) { }, }, }, + { + name: "skipped prescore plugin number greater than the number of score plugins", + plugins: buildScoreConfigDefaultWeights(scorePlugin1), + pluginConfigs: nil, + skippedPlugins: sets.New(scorePlugin1, "score-plugin-unknown"), + want: []framework.NodePluginScores{ + { + Name: "node1", + Scores: []framework.PluginScore{}, + }, + { + Name: "node2", + Scores: []framework.PluginScore{}, + }, + }, + }, } for _, tt := range tests {