mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +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
|
// framework is the component responsible for initializing and running scheduler
|
||||||
// plugins.
|
// plugins.
|
||||||
type framework struct {
|
type framework struct {
|
||||||
registry Registry
|
registry Registry
|
||||||
nodeInfoSnapshot *schedulernodeinfo.Snapshot
|
nodeInfoSnapshot *schedulernodeinfo.Snapshot
|
||||||
waitingPods *waitingPodsMap
|
waitingPods *waitingPodsMap
|
||||||
pluginNameToWeightMap map[string]int
|
pluginNameToWeightMap map[string]int
|
||||||
queueSortPlugins []QueueSortPlugin
|
queueSortPlugins []QueueSortPlugin
|
||||||
preFilterPlugins []PreFilterPlugin
|
preFilterPlugins []PreFilterPlugin
|
||||||
filterPlugins []FilterPlugin
|
filterPlugins []FilterPlugin
|
||||||
postFilterPlugins []PostFilterPlugin
|
postFilterPlugins []PostFilterPlugin
|
||||||
scorePlugins []ScorePlugin
|
scorePlugins []ScorePlugin
|
||||||
scoreWithNormalizePlugins []ScoreWithNormalizePlugin
|
reservePlugins []ReservePlugin
|
||||||
reservePlugins []ReservePlugin
|
preBindPlugins []PreBindPlugin
|
||||||
preBindPlugins []PreBindPlugin
|
bindPlugins []BindPlugin
|
||||||
bindPlugins []BindPlugin
|
postBindPlugins []PostBindPlugin
|
||||||
postBindPlugins []PostBindPlugin
|
unreservePlugins []UnreservePlugin
|
||||||
unreservePlugins []UnreservePlugin
|
permitPlugins []PermitPlugin
|
||||||
permitPlugins []PermitPlugin
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -133,7 +132,6 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
|
|||||||
if plugins.Score != nil {
|
if plugins.Score != nil {
|
||||||
for _, sc := range plugins.Score.Enabled {
|
for _, sc := range plugins.Score.Enabled {
|
||||||
if pg, ok := pluginsMap[sc.Name]; ok {
|
if pg, ok := pluginsMap[sc.Name]; ok {
|
||||||
// First, make sure the plugin implements ScorePlugin interface.
|
|
||||||
p, ok := pg.(ScorePlugin)
|
p, ok := pg.(ScorePlugin)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("plugin %q does not extend score plugin", sc.Name)
|
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())
|
return nil, fmt.Errorf("score plugin %q is not configured with weight", p.Name())
|
||||||
}
|
}
|
||||||
f.scorePlugins = append(f.scorePlugins, p)
|
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 {
|
} else {
|
||||||
return nil, fmt.Errorf("score plugin %q does not exist", sc.Name)
|
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)
|
return nil, NewStatus(Error, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run NormalizeScore method for each ScoreWithNormalizePlugin in parallel.
|
// Run NormalizeScore method for each ScorePlugin in parallel.
|
||||||
workqueue.ParallelizeUntil(ctx, 16, len(f.scoreWithNormalizePlugins), func(index int) {
|
workqueue.ParallelizeUntil(ctx, 16, len(f.scorePlugins), func(index int) {
|
||||||
pl := f.scoreWithNormalizePlugins[index]
|
pl := f.scorePlugins[index]
|
||||||
nodeScoreList := pluginToNodeScores[pl.Name()]
|
nodeScoreList := pluginToNodeScores[pl.Name()]
|
||||||
status := pl.NormalizeScore(pc, pod, nodeScoreList)
|
status := pl.NormalizeScore(pc, pod, nodeScoreList)
|
||||||
if !status.IsSuccess() {
|
if !status.IsSuccess() {
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
@ -39,7 +39,7 @@ const (
|
|||||||
|
|
||||||
// TestScoreWithNormalizePlugin implements ScoreWithNormalizePlugin interface.
|
// TestScoreWithNormalizePlugin implements ScoreWithNormalizePlugin interface.
|
||||||
// TestScorePlugin only implements ScorePlugin interface.
|
// TestScorePlugin only implements ScorePlugin interface.
|
||||||
var _ = ScoreWithNormalizePlugin(&TestScoreWithNormalizePlugin{})
|
var _ = ScorePlugin(&TestScoreWithNormalizePlugin{})
|
||||||
var _ = ScorePlugin(&TestScorePlugin{})
|
var _ = ScorePlugin(&TestScorePlugin{})
|
||||||
|
|
||||||
func newScoreWithNormalizePlugin1(injArgs *runtime.Unknown, f FrameworkHandle) (Plugin, error) {
|
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)
|
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.
|
// PluginNotImplementingScore doesn't implement the ScorePlugin interface.
|
||||||
type PluginNotImplementingScore struct{}
|
type PluginNotImplementingScore struct{}
|
||||||
|
|
||||||
|
@ -238,16 +238,13 @@ type ScorePlugin interface {
|
|||||||
// indicating the rank of the node. All scoring plugins must return success or
|
// indicating the rank of the node. All scoring plugins must return success or
|
||||||
// the pod will be rejected.
|
// the pod will be rejected.
|
||||||
Score(pc *PluginContext, p *v1.Pod, nodeName string) (int, *Status)
|
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"
|
// 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
|
// method. A successful run of NormalizeScore will update the scores list and return
|
||||||
// a success status.
|
// 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
|
NormalizeScore(pc *PluginContext, p *v1.Pod, scores NodeScoreList) *Status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ var _ = framework.PreFilterPlugin(&PreFilterPlugin{})
|
|||||||
var _ = framework.ScorePlugin(&ScorePlugin{})
|
var _ = framework.ScorePlugin(&ScorePlugin{})
|
||||||
var _ = framework.FilterPlugin(&FilterPlugin{})
|
var _ = framework.FilterPlugin(&FilterPlugin{})
|
||||||
var _ = framework.ScorePlugin(&ScorePlugin{})
|
var _ = framework.ScorePlugin(&ScorePlugin{})
|
||||||
var _ = framework.ScoreWithNormalizePlugin(&ScoreWithNormalizePlugin{})
|
var _ = framework.ScorePlugin(&ScoreWithNormalizePlugin{})
|
||||||
var _ = framework.ReservePlugin(&ReservePlugin{})
|
var _ = framework.ReservePlugin(&ReservePlugin{})
|
||||||
var _ = framework.PostFilterPlugin(&PostFilterPlugin{})
|
var _ = framework.PostFilterPlugin(&PostFilterPlugin{})
|
||||||
var _ = framework.PreBindPlugin(&PreBindPlugin{})
|
var _ = framework.PreBindPlugin(&PreBindPlugin{})
|
||||||
@ -162,6 +162,10 @@ func (sp *ScorePlugin) Score(pc *framework.PluginContext, p *v1.Pod, nodeName st
|
|||||||
return score, nil
|
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.
|
// Name returns name of the score plugin.
|
||||||
func (sp *ScoreWithNormalizePlugin) Name() string {
|
func (sp *ScoreWithNormalizePlugin) Name() string {
|
||||||
return scoreWithNormalizePluginName
|
return scoreWithNormalizePluginName
|
||||||
|
Loading…
Reference in New Issue
Block a user