From f3816fb757732200a9357fd06241411de63a545a Mon Sep 17 00:00:00 2001 From: draveness Date: Fri, 23 Aug 2019 01:56:28 +0800 Subject: [PATCH] feat: use PreFilter instead of Prefilter in the scheduling framework --- pkg/scheduler/core/generic_scheduler.go | 6 +-- pkg/scheduler/framework/v1alpha1/framework.go | 14 +++--- pkg/scheduler/framework/v1alpha1/interface.go | 12 ++--- .../internal/queue/scheduling_queue_test.go | 2 +- test/integration/scheduler/framework_test.go | 46 +++++++++---------- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/pkg/scheduler/core/generic_scheduler.go b/pkg/scheduler/core/generic_scheduler.go index aa5f598f1fb..1fe3b913d76 100644 --- a/pkg/scheduler/core/generic_scheduler.go +++ b/pkg/scheduler/core/generic_scheduler.go @@ -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() diff --git a/pkg/scheduler/framework/v1alpha1/framework.go b/pkg/scheduler/framework/v1alpha1/framework.go index 252d02e0cdc..2c8c0aca676 100644 --- a/pkg/scheduler/framework/v1alpha1/framework.go +++ b/pkg/scheduler/framework/v1alpha1/framework.go @@ -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()) diff --git a/pkg/scheduler/framework/v1alpha1/interface.go b/pkg/scheduler/framework/v1alpha1/interface.go index 70c59490c36..7af0d87cc98 100644 --- a/pkg/scheduler/framework/v1alpha1/interface.go +++ b/pkg/scheduler/framework/v1alpha1/interface.go @@ -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", diff --git a/pkg/scheduler/internal/queue/scheduling_queue_test.go b/pkg/scheduler/internal/queue/scheduling_queue_test.go index 1bdce2c517c..0c6b7a7148d 100644 --- a/pkg/scheduler/internal/queue/scheduling_queue_test.go +++ b/pkg/scheduler/internal/queue/scheduling_queue_test.go @@ -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 } diff --git a/test/integration/scheduler/framework_test.go b/test/integration/scheduler/framework_test.go index 37ec42b9e24..074595da0f6 100644 --- a/test/integration/scheduler/framework_test.go +++ b/test/integration/scheduler/framework_test.go @@ -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}) } }