mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
feat: use PreFilter instead of Prefilter in the scheduling framework
This commit is contained in:
parent
2af52db689
commit
f3816fb757
@ -195,9 +195,9 @@ func (g *genericScheduler) Schedule(pod *v1.Pod, pluginContext *framework.Plugin
|
||||
}
|
||||
|
||||
// Run "prefilter" plugins.
|
||||
prefilterStatus := g.framework.RunPrefilterPlugins(pluginContext, pod)
|
||||
if !prefilterStatus.IsSuccess() {
|
||||
return result, prefilterStatus.AsError()
|
||||
preFilterStatus := g.framework.RunPreFilterPlugins(pluginContext, pod)
|
||||
if !preFilterStatus.IsSuccess() {
|
||||
return result, preFilterStatus.AsError()
|
||||
}
|
||||
|
||||
numNodes := g.cache.NodeTree().NumNodes()
|
||||
|
@ -39,7 +39,7 @@ type framework struct {
|
||||
waitingPods *waitingPodsMap
|
||||
pluginNameToWeightMap map[string]int
|
||||
queueSortPlugins []QueueSortPlugin
|
||||
prefilterPlugins []PrefilterPlugin
|
||||
preFilterPlugins []PreFilterPlugin
|
||||
filterPlugins []FilterPlugin
|
||||
postFilterPlugins []PostFilterPlugin
|
||||
scorePlugins []ScorePlugin
|
||||
@ -105,11 +105,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
|
||||
if plugins.PreFilter != nil {
|
||||
for _, pf := range plugins.PreFilter.Enabled {
|
||||
if pg, ok := pluginsMap[pf.Name]; ok {
|
||||
p, ok := pg.(PrefilterPlugin)
|
||||
p, ok := pg.(PreFilterPlugin)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("plugin %q does not extend prefilter plugin", pf.Name)
|
||||
}
|
||||
f.prefilterPlugins = append(f.prefilterPlugins, p)
|
||||
f.preFilterPlugins = append(f.preFilterPlugins, p)
|
||||
} else {
|
||||
return nil, fmt.Errorf("prefilter plugin %q does not exist", pf.Name)
|
||||
}
|
||||
@ -283,14 +283,14 @@ func (f *framework) QueueSortFunc() LessFunc {
|
||||
return f.queueSortPlugins[0].Less
|
||||
}
|
||||
|
||||
// RunPrefilterPlugins runs the set of configured prefilter plugins. It returns
|
||||
// RunPreFilterPlugins runs the set of configured PreFilter plugins. It returns
|
||||
// *Status and its code is set to non-success if any of the plugins returns
|
||||
// anything but Success. If a non-success status is returned, then the scheduling
|
||||
// cycle is aborted.
|
||||
func (f *framework) RunPrefilterPlugins(
|
||||
func (f *framework) RunPreFilterPlugins(
|
||||
pc *PluginContext, pod *v1.Pod) *Status {
|
||||
for _, pl := range f.prefilterPlugins {
|
||||
status := pl.Prefilter(pc, pod)
|
||||
for _, pl := range f.preFilterPlugins {
|
||||
status := pl.PreFilter(pc, pod)
|
||||
if !status.IsSuccess() {
|
||||
if status.Code() == Unschedulable {
|
||||
msg := fmt.Sprintf("rejected by %q at prefilter: %v", pl.Name(), status.Message())
|
||||
|
@ -152,13 +152,13 @@ type QueueSortPlugin interface {
|
||||
Less(*PodInfo, *PodInfo) bool
|
||||
}
|
||||
|
||||
// PrefilterPlugin is an interface that must be implemented by "prefilter" plugins.
|
||||
// PreFilterPlugin is an interface that must be implemented by "prefilter" plugins.
|
||||
// These plugins are called at the beginning of the scheduling cycle.
|
||||
type PrefilterPlugin interface {
|
||||
type PreFilterPlugin interface {
|
||||
Plugin
|
||||
// Prefilter is called at the beginning of the scheduling cycle. All prefilter
|
||||
// PreFilter is called at the beginning of the scheduling cycle. All PreFilter
|
||||
// plugins must return success or the pod will be rejected.
|
||||
Prefilter(pc *PluginContext, p *v1.Pod) *Status
|
||||
PreFilter(pc *PluginContext, p *v1.Pod) *Status
|
||||
}
|
||||
|
||||
// FilterPlugin is an interface for Filter plugins. These plugins are called at the
|
||||
@ -289,11 +289,11 @@ type Framework interface {
|
||||
// QueueSortFunc returns the function to sort pods in scheduling queue
|
||||
QueueSortFunc() LessFunc
|
||||
|
||||
// RunPrefilterPlugins runs the set of configured prefilter plugins. It returns
|
||||
// RunPreFilterPlugins runs the set of configured prefilter plugins. It returns
|
||||
// *Status and its code is set to non-success if any of the plugins returns
|
||||
// anything but Success. If a non-success status is returned, then the scheduling
|
||||
// cycle is aborted.
|
||||
RunPrefilterPlugins(pc *PluginContext, pod *v1.Pod) *Status
|
||||
RunPreFilterPlugins(pc *PluginContext, pod *v1.Pod) *Status
|
||||
|
||||
// RunFilterPlugins runs the set of configured filter plugins for pod on the
|
||||
// given host. If any of these plugins returns any status other than "Success",
|
||||
|
@ -167,7 +167,7 @@ func (*fakeFramework) NodeInfoSnapshot() *internalcache.NodeInfoSnapshot {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*fakeFramework) RunPrefilterPlugins(pc *framework.PluginContext, pod *v1.Pod) *framework.Status {
|
||||
func (*fakeFramework) RunPreFilterPlugins(pc *framework.PluginContext, pod *v1.Pod) *framework.Status {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,10 @@ import (
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
)
|
||||
|
||||
type PrefilterPlugin struct {
|
||||
numPrefilterCalled int
|
||||
failPrefilter bool
|
||||
rejectPrefilter bool
|
||||
type PreFilterPlugin struct {
|
||||
numPreFilterCalled int
|
||||
failPreFilter bool
|
||||
rejectPreFilter bool
|
||||
}
|
||||
|
||||
type ScorePlugin struct {
|
||||
@ -113,7 +113,7 @@ const (
|
||||
permitPluginName = "permit-plugin"
|
||||
)
|
||||
|
||||
var _ = framework.PrefilterPlugin(&PrefilterPlugin{})
|
||||
var _ = framework.PreFilterPlugin(&PreFilterPlugin{})
|
||||
var _ = framework.ScorePlugin(&ScorePlugin{})
|
||||
var _ = framework.FilterPlugin(&FilterPlugin{})
|
||||
var _ = framework.ScorePlugin(&ScorePlugin{})
|
||||
@ -321,27 +321,27 @@ func (pp *PostbindPlugin) reset() {
|
||||
}
|
||||
|
||||
// Name returns name of the plugin.
|
||||
func (pp *PrefilterPlugin) Name() string {
|
||||
func (pp *PreFilterPlugin) Name() string {
|
||||
return prefilterPluginName
|
||||
}
|
||||
|
||||
// Prefilter is a test function that returns (true, nil) or errors for testing.
|
||||
func (pp *PrefilterPlugin) Prefilter(pc *framework.PluginContext, pod *v1.Pod) *framework.Status {
|
||||
pp.numPrefilterCalled++
|
||||
if pp.failPrefilter {
|
||||
// PreFilter is a test function that returns (true, nil) or errors for testing.
|
||||
func (pp *PreFilterPlugin) PreFilter(pc *framework.PluginContext, pod *v1.Pod) *framework.Status {
|
||||
pp.numPreFilterCalled++
|
||||
if pp.failPreFilter {
|
||||
return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name))
|
||||
}
|
||||
if pp.rejectPrefilter {
|
||||
if pp.rejectPreFilter {
|
||||
return framework.NewStatus(framework.Unschedulable, fmt.Sprintf("reject pod %v", pod.Name))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// reset used to reset prefilter plugin.
|
||||
func (pp *PrefilterPlugin) reset() {
|
||||
pp.numPrefilterCalled = 0
|
||||
pp.failPrefilter = false
|
||||
pp.rejectPrefilter = false
|
||||
func (pp *PreFilterPlugin) reset() {
|
||||
pp.numPreFilterCalled = 0
|
||||
pp.failPreFilter = false
|
||||
pp.rejectPreFilter = false
|
||||
}
|
||||
|
||||
// Name returns name of the plugin.
|
||||
@ -426,11 +426,11 @@ func newPermitPlugin(permitPlugin *PermitPlugin) framework.PluginFactory {
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrefilterPlugin tests invocation of prefilter plugins.
|
||||
func TestPrefilterPlugin(t *testing.T) {
|
||||
// TestPreFilterPlugin tests invocation of prefilter plugins.
|
||||
func TestPreFilterPlugin(t *testing.T) {
|
||||
// Create a plugin registry for testing. Register only a pre-filter plugin.
|
||||
prefilterPlugin := &PrefilterPlugin{}
|
||||
registry := framework.Registry{prefilterPluginName: newPlugin(prefilterPlugin)}
|
||||
preFilterPlugin := &PreFilterPlugin{}
|
||||
registry := framework.Registry{prefilterPluginName: newPlugin(preFilterPlugin)}
|
||||
|
||||
// Setup initial prefilter plugin for testing.
|
||||
plugins := &schedulerconfig.Plugins{
|
||||
@ -478,8 +478,8 @@ func TestPrefilterPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
prefilterPlugin.failPrefilter = test.fail
|
||||
prefilterPlugin.rejectPrefilter = test.reject
|
||||
preFilterPlugin.failPreFilter = test.fail
|
||||
preFilterPlugin.rejectPreFilter = test.reject
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
@ -497,11 +497,11 @@ func TestPrefilterPlugin(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if prefilterPlugin.numPrefilterCalled == 0 {
|
||||
if preFilterPlugin.numPreFilterCalled == 0 {
|
||||
t.Errorf("Expected the prefilter plugin to be called.")
|
||||
}
|
||||
|
||||
prefilterPlugin.reset()
|
||||
preFilterPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user