mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #83042 from draveness/feature/remove-score-with-normalize-extension
feat(scheduler): consolidate ScoreWithNormalizePlugin into ScorePlugin
This commit is contained in:
commit
5e4abfb946
@ -34,22 +34,21 @@ import (
|
||||
// framework is the component responsible for initializing and running scheduler
|
||||
// plugins.
|
||||
type framework struct {
|
||||
registry Registry
|
||||
nodeInfoSnapshot *schedulernodeinfo.Snapshot
|
||||
waitingPods *waitingPodsMap
|
||||
pluginNameToWeightMap map[string]int
|
||||
queueSortPlugins []QueueSortPlugin
|
||||
preFilterPlugins []PreFilterPlugin
|
||||
filterPlugins []FilterPlugin
|
||||
postFilterPlugins []PostFilterPlugin
|
||||
scorePlugins []ScorePlugin
|
||||
scoreWithNormalizePlugins []ScoreWithNormalizePlugin
|
||||
reservePlugins []ReservePlugin
|
||||
preBindPlugins []PreBindPlugin
|
||||
bindPlugins []BindPlugin
|
||||
postBindPlugins []PostBindPlugin
|
||||
unreservePlugins []UnreservePlugin
|
||||
permitPlugins []PermitPlugin
|
||||
registry Registry
|
||||
nodeInfoSnapshot *schedulernodeinfo.Snapshot
|
||||
waitingPods *waitingPodsMap
|
||||
pluginNameToWeightMap map[string]int
|
||||
queueSortPlugins []QueueSortPlugin
|
||||
preFilterPlugins []PreFilterPlugin
|
||||
filterPlugins []FilterPlugin
|
||||
postFilterPlugins []PostFilterPlugin
|
||||
scorePlugins []ScorePlugin
|
||||
reservePlugins []ReservePlugin
|
||||
preBindPlugins []PreBindPlugin
|
||||
bindPlugins []BindPlugin
|
||||
postBindPlugins []PostBindPlugin
|
||||
unreservePlugins []UnreservePlugin
|
||||
permitPlugins []PermitPlugin
|
||||
}
|
||||
|
||||
const (
|
||||
@ -133,7 +132,6 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
|
||||
if plugins.Score != nil {
|
||||
for _, sc := range plugins.Score.Enabled {
|
||||
if pg, ok := pluginsMap[sc.Name]; ok {
|
||||
// First, make sure the plugin implements ScorePlugin interface.
|
||||
p, ok := pg.(ScorePlugin)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("plugin %q does not extend score plugin", sc.Name)
|
||||
@ -142,13 +140,6 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
|
||||
return nil, fmt.Errorf("score plugin %q is not configured with weight", p.Name())
|
||||
}
|
||||
f.scorePlugins = append(f.scorePlugins, p)
|
||||
|
||||
// Next, if the plugin also implements ScoreWithNormalizePlugin interface,
|
||||
// add it to the normalizeScore plugin list.
|
||||
np, ok := pg.(ScoreWithNormalizePlugin)
|
||||
if ok {
|
||||
f.scoreWithNormalizePlugins = append(f.scoreWithNormalizePlugins, np)
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("score plugin %q does not exist", sc.Name)
|
||||
}
|
||||
@ -422,9 +413,9 @@ func (f *framework) RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1.
|
||||
return nil, NewStatus(Error, msg)
|
||||
}
|
||||
|
||||
// Run NormalizeScore method for each ScoreWithNormalizePlugin in parallel.
|
||||
workqueue.ParallelizeUntil(ctx, 16, len(f.scoreWithNormalizePlugins), func(index int) {
|
||||
pl := f.scoreWithNormalizePlugins[index]
|
||||
// Run NormalizeScore method for each ScorePlugin in parallel.
|
||||
workqueue.ParallelizeUntil(ctx, 16, len(f.scorePlugins), func(index int) {
|
||||
pl := f.scorePlugins[index]
|
||||
nodeScoreList := pluginToNodeScores[pl.Name()]
|
||||
status := pl.NormalizeScore(pc, pod, nodeScoreList)
|
||||
if !status.IsSuccess() {
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
@ -39,7 +39,7 @@ const (
|
||||
|
||||
// TestScoreWithNormalizePlugin implements ScoreWithNormalizePlugin interface.
|
||||
// TestScorePlugin only implements ScorePlugin interface.
|
||||
var _ = ScoreWithNormalizePlugin(&TestScoreWithNormalizePlugin{})
|
||||
var _ = ScorePlugin(&TestScoreWithNormalizePlugin{})
|
||||
var _ = ScorePlugin(&TestScorePlugin{})
|
||||
|
||||
func newScoreWithNormalizePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error) {
|
||||
@ -101,6 +101,10 @@ func (pl *TestScorePlugin) Score(pc *PluginContext, p *v1.Pod, nodeName string)
|
||||
return setScoreRes(pl.inj)
|
||||
}
|
||||
|
||||
func (pl *TestScorePlugin) NormalizeScore(pc *PluginContext, pod *v1.Pod, scores NodeScoreList) *Status {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PluginNotImplementingScore doesn't implement the ScorePlugin interface.
|
||||
type PluginNotImplementingScore struct{}
|
||||
|
||||
|
@ -238,16 +238,13 @@ type ScorePlugin interface {
|
||||
// indicating the rank of the node. All scoring plugins must return success or
|
||||
// the pod will be rejected.
|
||||
Score(pc *PluginContext, p *v1.Pod, nodeName string) (int, *Status)
|
||||
}
|
||||
|
||||
// ScoreWithNormalizePlugin is an interface that must be implemented by "score"
|
||||
// plugins that also need to normalize the node scoring results produced by the same
|
||||
// plugin's "Score" method.
|
||||
type ScoreWithNormalizePlugin interface {
|
||||
ScorePlugin
|
||||
// NormalizeScore is called for all node scores produced by the same plugin's "Score"
|
||||
// method. A successful run of NormalizeScore will update the scores list and return
|
||||
// a success status.
|
||||
//
|
||||
// NOTE: This function is optional, and you could implement it as a no-op by simply
|
||||
// returning nil.
|
||||
NormalizeScore(pc *PluginContext, p *v1.Pod, scores NodeScoreList) *Status
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ var _ = framework.PreFilterPlugin(&PreFilterPlugin{})
|
||||
var _ = framework.ScorePlugin(&ScorePlugin{})
|
||||
var _ = framework.FilterPlugin(&FilterPlugin{})
|
||||
var _ = framework.ScorePlugin(&ScorePlugin{})
|
||||
var _ = framework.ScoreWithNormalizePlugin(&ScoreWithNormalizePlugin{})
|
||||
var _ = framework.ScorePlugin(&ScoreWithNormalizePlugin{})
|
||||
var _ = framework.ReservePlugin(&ReservePlugin{})
|
||||
var _ = framework.PostFilterPlugin(&PostFilterPlugin{})
|
||||
var _ = framework.PreBindPlugin(&PreBindPlugin{})
|
||||
@ -162,6 +162,10 @@ func (sp *ScorePlugin) Score(pc *framework.PluginContext, p *v1.Pod, nodeName st
|
||||
return score, nil
|
||||
}
|
||||
|
||||
func (sp *ScorePlugin) NormalizeScore(pc *framework.PluginContext, pod *v1.Pod, scores framework.NodeScoreList) *framework.Status {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Name returns name of the score plugin.
|
||||
func (sp *ScoreWithNormalizePlugin) Name() string {
|
||||
return scoreWithNormalizePluginName
|
||||
|
Loading…
Reference in New Issue
Block a user