mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Precheck score plugins' weight when initializing
This commit is contained in:
parent
b5dfcf357a
commit
66347b516c
@ -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
|
// A weight of zero is not permitted, plugins can be disabled explicitly
|
||||||
// when configured.
|
// when configured.
|
||||||
f.pluginNameToWeightMap[name] = int(pg[name].Weight)
|
if pg[name].Weight != 0 {
|
||||||
if f.pluginNameToWeightMap[name] == 0 {
|
f.pluginNameToWeightMap[name] = int(pg[name].Weight)
|
||||||
f.pluginNameToWeightMap[name] = 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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)
|
return nil, fmt.Errorf("plugin %v does not extend score plugin", sc.Name)
|
||||||
}
|
}
|
||||||
f.scorePlugins = append(f.scorePlugins, p)
|
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 {
|
} 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)
|
||||||
}
|
}
|
||||||
@ -276,12 +278,8 @@ func (f *framework) RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1.
|
|||||||
errCh := schedutil.NewErrorChannel()
|
errCh := schedutil.NewErrorChannel()
|
||||||
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 {
|
||||||
weight, weightExists := f.pluginNameToWeightMap[pl.Name()]
|
// Score plugins' weight has been checked when they are initialized.
|
||||||
if !weightExists {
|
weight, _ := f.pluginNameToWeightMap[pl.Name()]
|
||||||
err := fmt.Errorf("weight does not exist for plugin %v", pl.Name())
|
|
||||||
errCh.SendErrorWithCancel(err, cancel)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
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)
|
||||||
|
@ -456,6 +456,7 @@ func TestScorePlugin(t *testing.T) {
|
|||||||
Enabled: []schedulerconfig.Plugin{
|
Enabled: []schedulerconfig.Plugin{
|
||||||
{
|
{
|
||||||
Name: scorePluginName,
|
Name: scorePluginName,
|
||||||
|
Weight: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user