Skip to content

Commit

Permalink
Merge pull request #122371 from caohe/automated-cherry-pick-of-#12206…
Browse files Browse the repository at this point in the history
…8-upstream-release-1.26

Automated cherry pick of #122068: fix(scheduler): fix incorrect loop logic in MultiPoint to avoid a plugin being loaded multiple times
  • Loading branch information
k8s-ci-robot authored Jan 10, 2024
2 parents da842e4 + 879bece commit bcbff1c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/scheduler/framework/runtime/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework"
"k8s.io/kubernetes/pkg/scheduler/framework/parallelize"
"k8s.io/kubernetes/pkg/scheduler/metrics"
"k8s.io/kubernetes/pkg/util/slice"
)

const (
Expand Down Expand Up @@ -512,7 +513,7 @@ func (f *frameworkImpl) expandMultiPointPlugins(profile *config.KubeSchedulerPro
// - part 3: other plugins (excluded by part 1 & 2) in regular extension point.
newPlugins := reflect.New(reflect.TypeOf(e.slicePtr).Elem()).Elem()
// part 1
for _, name := range enabledSet.list {
for _, name := range slice.CopyStrings(enabledSet.list) {
if overridePlugins.has(name) {
newPlugins = reflect.Append(newPlugins, reflect.ValueOf(pluginsMap[name]))
enabledSet.delete(name)
Expand Down
49 changes: 49 additions & 0 deletions pkg/scheduler/framework/runtime/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
scoreWithNormalizePlugin1 = "score-with-normalize-plugin-1"
scoreWithNormalizePlugin2 = "score-with-normalize-plugin-2"
scorePlugin1 = "score-plugin-1"
scorePlugin2 = "score-plugin-2"
pluginNotImplementingScore = "plugin-not-implementing-score"
preFilterPluginName = "prefilter-plugin"
preFilterWithExtensionsPluginName = "prefilter-with-extensions-plugin"
Expand Down Expand Up @@ -91,6 +92,14 @@ func newScorePlugin1(injArgs runtime.Object, f framework.Handle) (framework.Plug
return &TestScorePlugin{scorePlugin1, inj}, nil
}

func newScorePlugin2(injArgs runtime.Object, f framework.Handle) (framework.Plugin, error) {
var inj injectedResult
if err := DecodeInto(injArgs, &inj); err != nil {
return nil, err
}
return &TestScorePlugin{scorePlugin2, inj}, nil
}

func newPluginNotImplementingScore(_ runtime.Object, _ framework.Handle) (framework.Plugin, error) {
return &PluginNotImplementingScore{}, nil
}
Expand Down Expand Up @@ -349,11 +358,13 @@ func (t TestBindPlugin) Bind(ctx context.Context, state *framework.CycleState, p
return nil
}

// nolint:errcheck // Ignore the error returned by Register as before
var registry = func() Registry {
r := make(Registry)
r.Register(scoreWithNormalizePlugin1, newScoreWithNormalizePlugin1)
r.Register(scoreWithNormalizePlugin2, newScoreWithNormalizePlugin2)
r.Register(scorePlugin1, newScorePlugin1)
r.Register(scorePlugin2, newScorePlugin2)
r.Register(pluginNotImplementingScore, newPluginNotImplementingScore)
r.Register(duplicatePluginName, newDuplicatePlugin)
r.Register(testPlugin, newTestPlugin)
Expand Down Expand Up @@ -813,6 +824,44 @@ func TestNewFrameworkMultiPointExpansion(t *testing.T) {
},
wantErr: "already registered",
},
{
name: "Override MultiPoint plugins weights and avoid a plugin being loaded multiple times",
plugins: &config.Plugins{
MultiPoint: config.PluginSet{
Enabled: []config.Plugin{
{Name: testPlugin},
{Name: scorePlugin1},
},
},
Score: config.PluginSet{
Enabled: []config.Plugin{
{Name: scorePlugin1, Weight: 5},
{Name: scorePlugin2, Weight: 5},
{Name: testPlugin, Weight: 3},
},
},
},
wantPlugins: &config.Plugins{
QueueSort: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin}}},
PreFilter: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin}}},
Filter: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin}}},
PostFilter: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin}}},
PreScore: config.PluginSet{Enabled: []config.Plugin{
{Name: testPlugin},
{Name: scorePlugin1},
}},
Score: config.PluginSet{Enabled: []config.Plugin{
{Name: scorePlugin1, Weight: 5},
{Name: testPlugin, Weight: 3},
{Name: scorePlugin2, Weight: 5},
}},
Reserve: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin}}},
Permit: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin}}},
PreBind: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin}}},
Bind: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin}}},
PostBind: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin}}},
},
},
}

for _, tc := range tests {
Expand Down

0 comments on commit bcbff1c

Please sign in to comment.