Set score plugin's weight to 1 if it is not set

This commit is contained in:
Jun Gong 2019-07-18 21:57:24 +08:00
parent 66347b516c
commit 2dc5cf8c43
2 changed files with 7 additions and 7 deletions

View File

@ -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 // A weight of zero is not permitted, plugins can be disabled explicitly
// when configured. // 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 { if !ok {
return nil, fmt.Errorf("plugin %v does not extend score plugin", sc.Name) return nil, fmt.Errorf("plugin %v does not extend score plugin", sc.Name)
} }
f.scorePlugins = append(f.scorePlugins, p) if f.pluginNameToWeightMap[p.Name()] == 0 {
if _, exists := f.pluginNameToWeightMap[p.Name()]; !exists { return nil, fmt.Errorf("score plugin %v is not configured with weight", p.Name())
return nil, fmt.Errorf("score plugin %v is not configured with weight", sc.Name)
} }
f.scorePlugins = append(f.scorePlugins, p)
} else { } else {
return nil, fmt.Errorf("score plugin %v does not exist", sc.Name) 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) { workqueue.ParallelizeUntil(ctx, 16, len(nodes), func(index int) {
for _, pl := range f.scorePlugins { for _, pl := range f.scorePlugins {
// Score plugins' weight has been checked when they are initialized. // 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) score, status := pl.Score(pc, pod, nodes[index].Name)
if !status.IsSuccess() { if !status.IsSuccess() {
errCh.SendErrorWithCancel(fmt.Errorf(status.Message()), cancel) errCh.SendErrorWithCancel(fmt.Errorf(status.Message()), cancel)

View File

@ -456,7 +456,6 @@ func TestScorePlugin(t *testing.T) {
Enabled: []schedulerconfig.Plugin{ Enabled: []schedulerconfig.Plugin{
{ {
Name: scorePluginName, Name: scorePluginName,
Weight: 1,
}, },
}, },
}, },