From 66347b516cc687ee739b1efc226aa37914a3b55e Mon Sep 17 00:00:00 2001 From: Jun Gong Date: Thu, 18 Jul 2019 21:19:21 +0800 Subject: [PATCH 1/2] Precheck score plugins' weight when initializing --- pkg/scheduler/framework/v1alpha1/framework.go | 16 +++++++--------- test/integration/scheduler/framework_test.go | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/scheduler/framework/v1alpha1/framework.go b/pkg/scheduler/framework/v1alpha1/framework.go index 7dce3761a13..a4d3d787c5e 100644 --- a/pkg/scheduler/framework/v1alpha1/framework.go +++ b/pkg/scheduler/framework/v1alpha1/framework.go @@ -93,9 +93,8 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi // A weight of zero is not permitted, plugins can be disabled explicitly // when configured. - f.pluginNameToWeightMap[name] = int(pg[name].Weight) - if f.pluginNameToWeightMap[name] == 0 { - f.pluginNameToWeightMap[name] = 1 + if pg[name].Weight != 0 { + f.pluginNameToWeightMap[name] = int(pg[name].Weight) } } @@ -121,6 +120,9 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi return nil, fmt.Errorf("plugin %v does not extend score plugin", sc.Name) } f.scorePlugins = append(f.scorePlugins, p) + if _, exists := f.pluginNameToWeightMap[p.Name()]; !exists { + return nil, fmt.Errorf("score plugin %v is not configured with weight", sc.Name) + } } else { return nil, fmt.Errorf("score plugin %v does not exist", sc.Name) } @@ -276,12 +278,8 @@ func (f *framework) RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1. errCh := schedutil.NewErrorChannel() workqueue.ParallelizeUntil(ctx, 16, len(nodes), func(index int) { for _, pl := range f.scorePlugins { - weight, weightExists := f.pluginNameToWeightMap[pl.Name()] - if !weightExists { - err := fmt.Errorf("weight does not exist for plugin %v", pl.Name()) - errCh.SendErrorWithCancel(err, cancel) - return - } + // Score plugins' weight has been checked when they are initialized. + weight, _ := f.pluginNameToWeightMap[pl.Name()] score, status := pl.Score(pc, pod, nodes[index].Name) if !status.IsSuccess() { errCh.SendErrorWithCancel(fmt.Errorf(status.Message()), cancel) diff --git a/test/integration/scheduler/framework_test.go b/test/integration/scheduler/framework_test.go index 910efafccb3..1050b6b5166 100644 --- a/test/integration/scheduler/framework_test.go +++ b/test/integration/scheduler/framework_test.go @@ -456,6 +456,7 @@ func TestScorePlugin(t *testing.T) { Enabled: []schedulerconfig.Plugin{ { Name: scorePluginName, + Weight: 1, }, }, }, From 2dc5cf8c43a9452fda404106b2cd2925c7646111 Mon Sep 17 00:00:00 2001 From: Jun Gong Date: Thu, 18 Jul 2019 21:57:24 +0800 Subject: [PATCH 2/2] Set score plugin's weight to 1 if it is not set --- pkg/scheduler/framework/v1alpha1/framework.go | 13 +++++++------ test/integration/scheduler/framework_test.go | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/scheduler/framework/v1alpha1/framework.go b/pkg/scheduler/framework/v1alpha1/framework.go index a4d3d787c5e..6e9fe4ad2a3 100644 --- a/pkg/scheduler/framework/v1alpha1/framework.go +++ b/pkg/scheduler/framework/v1alpha1/framework.go @@ -93,8 +93,9 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi // A weight of zero is not permitted, plugins can be disabled explicitly // when configured. - if pg[name].Weight != 0 { - f.pluginNameToWeightMap[name] = int(pg[name].Weight) + f.pluginNameToWeightMap[name] = int(pg[name].Weight) + if f.pluginNameToWeightMap[name] == 0 { + f.pluginNameToWeightMap[name] = 1 } } @@ -119,10 +120,10 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi if !ok { return nil, fmt.Errorf("plugin %v does not extend score plugin", sc.Name) } - f.scorePlugins = append(f.scorePlugins, p) - if _, exists := f.pluginNameToWeightMap[p.Name()]; !exists { - return nil, fmt.Errorf("score plugin %v is not configured with weight", sc.Name) + if f.pluginNameToWeightMap[p.Name()] == 0 { + return nil, fmt.Errorf("score plugin %v is not configured with weight", p.Name()) } + f.scorePlugins = append(f.scorePlugins, p) } else { return nil, fmt.Errorf("score plugin %v does not exist", sc.Name) } @@ -279,7 +280,7 @@ func (f *framework) RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1. workqueue.ParallelizeUntil(ctx, 16, len(nodes), func(index int) { for _, pl := range f.scorePlugins { // Score plugins' weight has been checked when they are initialized. - weight, _ := f.pluginNameToWeightMap[pl.Name()] + weight := f.pluginNameToWeightMap[pl.Name()] score, status := pl.Score(pc, pod, nodes[index].Name) if !status.IsSuccess() { errCh.SendErrorWithCancel(fmt.Errorf(status.Message()), cancel) diff --git a/test/integration/scheduler/framework_test.go b/test/integration/scheduler/framework_test.go index 1050b6b5166..910efafccb3 100644 --- a/test/integration/scheduler/framework_test.go +++ b/test/integration/scheduler/framework_test.go @@ -456,7 +456,6 @@ func TestScorePlugin(t *testing.T) { Enabled: []schedulerconfig.Plugin{ { Name: scorePluginName, - Weight: 1, }, }, },