feat: use PostBind instead of Postbind in the scheduling framework

This commit is contained in:
draveness 2019-08-23 02:02:26 +08:00
parent f3816fb757
commit 03f0934c80
5 changed files with 54 additions and 54 deletions

View File

@ -47,7 +47,7 @@ type framework struct {
reservePlugins []ReservePlugin reservePlugins []ReservePlugin
prebindPlugins []PrebindPlugin prebindPlugins []PrebindPlugin
bindPlugins []BindPlugin bindPlugins []BindPlugin
postbindPlugins []PostbindPlugin postBindPlugins []PostBindPlugin
unreservePlugins []UnreservePlugin unreservePlugins []UnreservePlugin
permitPlugins []PermitPlugin permitPlugins []PermitPlugin
} }
@ -214,11 +214,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
if plugins.PostBind != nil { if plugins.PostBind != nil {
for _, pb := range plugins.PostBind.Enabled { for _, pb := range plugins.PostBind.Enabled {
if pg, ok := pluginsMap[pb.Name]; ok { if pg, ok := pluginsMap[pb.Name]; ok {
p, ok := pg.(PostbindPlugin) p, ok := pg.(PostBindPlugin)
if !ok { if !ok {
return nil, fmt.Errorf("plugin %q does not extend postbind plugin", pb.Name) return nil, fmt.Errorf("plugin %q does not extend postbind plugin", pb.Name)
} }
f.postbindPlugins = append(f.postbindPlugins, p) f.postBindPlugins = append(f.postBindPlugins, p)
} else { } else {
return nil, fmt.Errorf("postbind plugin %q does not exist", pb.Name) return nil, fmt.Errorf("postbind plugin %q does not exist", pb.Name)
} }
@ -467,11 +467,11 @@ func (f *framework) RunBindPlugins(pc *PluginContext, pod *v1.Pod, nodeName stri
return status return status
} }
// RunPostbindPlugins runs the set of configured postbind plugins. // RunPostBindPlugins runs the set of configured postbind plugins.
func (f *framework) RunPostbindPlugins( func (f *framework) RunPostBindPlugins(
pc *PluginContext, pod *v1.Pod, nodeName string) { pc *PluginContext, pod *v1.Pod, nodeName string) {
for _, pl := range f.postbindPlugins { for _, pl := range f.postBindPlugins {
pl.Postbind(pc, pod, nodeName) pl.PostBind(pc, pod, nodeName)
} }
} }

View File

@ -234,15 +234,15 @@ type PrebindPlugin interface {
Prebind(pc *PluginContext, p *v1.Pod, nodeName string) *Status Prebind(pc *PluginContext, p *v1.Pod, nodeName string) *Status
} }
// PostbindPlugin is an interface that must be implemented by "postbind" plugins. // PostBindPlugin is an interface that must be implemented by "postbind" plugins.
// These plugins are called after a pod is successfully bound to a node. // These plugins are called after a pod is successfully bound to a node.
type PostbindPlugin interface { type PostBindPlugin interface {
Plugin Plugin
// Postbind is called after a pod is successfully bound. These plugins are // PostBind is called after a pod is successfully bound. These plugins are
// informational. A common application of this extension point is for cleaning // informational. A common application of this extension point is for cleaning
// up. If a plugin needs to clean-up its state after a pod is scheduled and // up. If a plugin needs to clean-up its state after a pod is scheduled and
// bound, Postbind is the extension point that it should register. // bound, PostBind is the extension point that it should register.
Postbind(pc *PluginContext, p *v1.Pod, nodeName string) PostBind(pc *PluginContext, p *v1.Pod, nodeName string)
} }
// UnreservePlugin is an interface for Unreserve plugins. This is an informational // UnreservePlugin is an interface for Unreserve plugins. This is an informational
@ -318,8 +318,8 @@ type Framework interface {
// internal error. In either case the pod is not going to be bound. // internal error. In either case the pod is not going to be bound.
RunPrebindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string) *Status RunPrebindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string) *Status
// RunPostbindPlugins runs the set of configured postbind plugins. // RunPostBindPlugins runs the set of configured postbind plugins.
RunPostbindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string) RunPostBindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string)
// RunReservePlugins runs the set of configured reserve plugins. If any of these // RunReservePlugins runs the set of configured reserve plugins. If any of these
// plugins returns an error, it does not continue running the remaining ones and // plugins returns an error, it does not continue running the remaining ones and

View File

@ -187,7 +187,7 @@ func (*fakeFramework) RunBindPlugins(pc *framework.PluginContext, pod *v1.Pod, n
return nil return nil
} }
func (*fakeFramework) RunPostbindPlugins(pc *framework.PluginContext, pod *v1.Pod, nodeName string) {} func (*fakeFramework) RunPostBindPlugins(pc *framework.PluginContext, pod *v1.Pod, nodeName string) {}
func (*fakeFramework) RunPostFilterPlugins(pc *framework.PluginContext, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses framework.NodeToStatusMap) *framework.Status { func (*fakeFramework) RunPostFilterPlugins(pc *framework.PluginContext, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses framework.NodeToStatusMap) *framework.Status {
return nil return nil

View File

@ -670,7 +670,7 @@ func (sched *Scheduler) scheduleOne() {
metrics.PodScheduleSuccesses.Inc() metrics.PodScheduleSuccesses.Inc()
// Run "postbind" plugins. // Run "postbind" plugins.
fwk.RunPostbindPlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost) fwk.RunPostBindPlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost)
} }
}() }()
} }

View File

@ -77,9 +77,9 @@ type BindPlugin struct {
pluginInvokeEventChan chan pluginInvokeEvent pluginInvokeEventChan chan pluginInvokeEvent
} }
type PostbindPlugin struct { type PostBindPlugin struct {
name string name string
numPostbindCalled int numPostBindCalled int
pluginInvokeEventChan chan pluginInvokeEvent pluginInvokeEventChan chan pluginInvokeEvent
} }
@ -109,7 +109,7 @@ const (
reservePluginName = "reserve-plugin" reservePluginName = "reserve-plugin"
prebindPluginName = "prebind-plugin" prebindPluginName = "prebind-plugin"
unreservePluginName = "unreserve-plugin" unreservePluginName = "unreserve-plugin"
postbindPluginName = "postbind-plugin" postBindPluginName = "postbind-plugin"
permitPluginName = "permit-plugin" permitPluginName = "permit-plugin"
) )
@ -122,7 +122,7 @@ var _ = framework.ReservePlugin(&ReservePlugin{})
var _ = framework.PostFilterPlugin(&PostFilterPlugin{}) var _ = framework.PostFilterPlugin(&PostFilterPlugin{})
var _ = framework.PrebindPlugin(&PrebindPlugin{}) var _ = framework.PrebindPlugin(&PrebindPlugin{})
var _ = framework.BindPlugin(&BindPlugin{}) var _ = framework.BindPlugin(&BindPlugin{})
var _ = framework.PostbindPlugin(&PostbindPlugin{}) var _ = framework.PostBindPlugin(&PostBindPlugin{})
var _ = framework.UnreservePlugin(&UnreservePlugin{}) var _ = framework.UnreservePlugin(&UnreservePlugin{})
var _ = framework.PermitPlugin(&PermitPlugin{}) var _ = framework.PermitPlugin(&PermitPlugin{})
@ -303,21 +303,21 @@ func (bp *BindPlugin) reset() {
} }
// Name returns name of the plugin. // Name returns name of the plugin.
func (pp *PostbindPlugin) Name() string { func (pp *PostBindPlugin) Name() string {
return pp.name return pp.name
} }
// Postbind is a test function, which counts the number of times called. // PostBind is a test function, which counts the number of times called.
func (pp *PostbindPlugin) Postbind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) { func (pp *PostBindPlugin) PostBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) {
pp.numPostbindCalled++ pp.numPostBindCalled++
if pp.pluginInvokeEventChan != nil { if pp.pluginInvokeEventChan != nil {
pp.pluginInvokeEventChan <- pluginInvokeEvent{pluginName: pp.Name(), val: pp.numPostbindCalled} pp.pluginInvokeEventChan <- pluginInvokeEvent{pluginName: pp.Name(), val: pp.numPostBindCalled}
} }
} }
// reset used to reset postbind plugin. // reset used to reset postbind plugin.
func (pp *PostbindPlugin) reset() { func (pp *PostBindPlugin) reset() {
pp.numPostbindCalled = 0 pp.numPostBindCalled = 0
} }
// Name returns name of the plugin. // Name returns name of the plugin.
@ -884,7 +884,7 @@ func TestBindPlugin(t *testing.T) {
bindPlugin1 := &BindPlugin{PluginName: "bind-plugin-1", client: testContext.clientSet} bindPlugin1 := &BindPlugin{PluginName: "bind-plugin-1", client: testContext.clientSet}
bindPlugin2 := &BindPlugin{PluginName: "bind-plugin-2", client: testContext.clientSet} bindPlugin2 := &BindPlugin{PluginName: "bind-plugin-2", client: testContext.clientSet}
unreservePlugin := &UnreservePlugin{name: "mock-unreserve-plugin"} unreservePlugin := &UnreservePlugin{name: "mock-unreserve-plugin"}
postbindPlugin := &PostbindPlugin{name: "mock-post-bind-plugin"} postBindPlugin := &PostBindPlugin{name: "mock-post-bind-plugin"}
// Create a plugin registry for testing. Register an unreserve, a bind plugin and a postBind plugin. // Create a plugin registry for testing. Register an unreserve, a bind plugin and a postBind plugin.
registry := framework.Registry{ registry := framework.Registry{
unreservePlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { unreservePlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
@ -896,8 +896,8 @@ func TestBindPlugin(t *testing.T) {
bindPlugin2.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { bindPlugin2.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return bindPlugin2, nil return bindPlugin2, nil
}, },
postbindPlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { postBindPlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return postbindPlugin, nil return postBindPlugin, nil
}, },
} }
@ -910,7 +910,7 @@ func TestBindPlugin(t *testing.T) {
Enabled: []schedulerconfig.Plugin{{Name: bindPlugin1.Name()}, {Name: bindPlugin2.Name()}}, Enabled: []schedulerconfig.Plugin{{Name: bindPlugin1.Name()}, {Name: bindPlugin2.Name()}},
}, },
PostBind: &schedulerconfig.PluginSet{ PostBind: &schedulerconfig.PluginSet{
Enabled: []schedulerconfig.Plugin{{Name: postbindPlugin.Name()}}, Enabled: []schedulerconfig.Plugin{{Name: postBindPlugin.Name()}},
}, },
} }
// Set reserve and bind config for testing // Set reserve and bind config for testing
@ -928,7 +928,7 @@ func TestBindPlugin(t *testing.T) {
Args: runtime.Unknown{}, Args: runtime.Unknown{},
}, },
{ {
Name: postbindPlugin.Name(), Name: postBindPlugin.Name(),
Args: runtime.Unknown{}, Args: runtime.Unknown{},
}, },
} }
@ -956,21 +956,21 @@ func TestBindPlugin(t *testing.T) {
{ {
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Skip, "")}, bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Skip, "")},
expectBoundByScheduler: true, expectBoundByScheduler: true,
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postbindPlugin.Name(), val: 1}}, expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
}, },
// bindplugin2 succeeded to bind the pod // bindplugin2 succeeded to bind the pod
{ {
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Success, "")}, bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Success, "")},
expectBoundByPlugin: true, expectBoundByPlugin: true,
expectBindPluginName: bindPlugin2.Name(), expectBindPluginName: bindPlugin2.Name(),
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postbindPlugin.Name(), val: 1}}, expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
}, },
// bindplugin1 succeeded to bind the pod // bindplugin1 succeeded to bind the pod
{ {
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Success, ""), framework.NewStatus(framework.Success, "")}, bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Success, ""), framework.NewStatus(framework.Success, "")},
expectBoundByPlugin: true, expectBoundByPlugin: true,
expectBindPluginName: bindPlugin1.Name(), expectBindPluginName: bindPlugin1.Name(),
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: postbindPlugin.Name(), val: 1}}, expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
}, },
// bind plugin fails to bind the pod // bind plugin fails to bind the pod
{ {
@ -988,7 +988,7 @@ func TestBindPlugin(t *testing.T) {
bindPlugin1.pluginInvokeEventChan = pluginInvokeEventChan bindPlugin1.pluginInvokeEventChan = pluginInvokeEventChan
bindPlugin2.pluginInvokeEventChan = pluginInvokeEventChan bindPlugin2.pluginInvokeEventChan = pluginInvokeEventChan
unreservePlugin.pluginInvokeEventChan = pluginInvokeEventChan unreservePlugin.pluginInvokeEventChan = pluginInvokeEventChan
postbindPlugin.pluginInvokeEventChan = pluginInvokeEventChan postBindPlugin.pluginInvokeEventChan = pluginInvokeEventChan
// Create a best effort pod. // Create a best effort pod.
pod, err := createPausePod(cs, pod, err := createPausePod(cs,
@ -1027,9 +1027,9 @@ func TestBindPlugin(t *testing.T) {
} }
} }
if err = wait.Poll(10*time.Millisecond, 30*time.Second, func() (done bool, err error) { if err = wait.Poll(10*time.Millisecond, 30*time.Second, func() (done bool, err error) {
return postbindPlugin.numPostbindCalled == 1, nil return postBindPlugin.numPostBindCalled == 1, nil
}); err != nil { }); err != nil {
t.Errorf("test #%v: Expected the postbind plugin to be called once, was called %d times.", i, postbindPlugin.numPostbindCalled) t.Errorf("test #%v: Expected the postbind plugin to be called once, was called %d times.", i, postBindPlugin.numPostBindCalled)
} }
if unreservePlugin.numUnreserveCalled != 0 { if unreservePlugin.numUnreserveCalled != 0 {
t.Errorf("test #%v: Expected the unreserve plugin not to be called, was called %d times.", i, unreservePlugin.numUnreserveCalled) t.Errorf("test #%v: Expected the unreserve plugin not to be called, was called %d times.", i, unreservePlugin.numUnreserveCalled)
@ -1039,8 +1039,8 @@ func TestBindPlugin(t *testing.T) {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil { if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err) t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
} }
if postbindPlugin.numPostbindCalled > 0 { if postBindPlugin.numPostBindCalled > 0 {
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postbindPlugin.numPostbindCalled) t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
} }
} }
for j := range test.expectInvokeEvents { for j := range test.expectInvokeEvents {
@ -1057,7 +1057,7 @@ func TestBindPlugin(t *testing.T) {
t.Errorf("test #%v: Waiting for invoke event %d timeout.", i, j) t.Errorf("test #%v: Waiting for invoke event %d timeout.", i, j)
} }
} }
postbindPlugin.reset() postBindPlugin.reset()
bindPlugin1.reset() bindPlugin1.reset()
bindPlugin2.reset() bindPlugin2.reset()
unreservePlugin.reset() unreservePlugin.reset()
@ -1065,14 +1065,14 @@ func TestBindPlugin(t *testing.T) {
} }
} }
// TestPostbindPlugin tests invocation of postbind plugins. // TestPostBindPlugin tests invocation of postbind plugins.
func TestPostbindPlugin(t *testing.T) { func TestPostBindPlugin(t *testing.T) {
// Create a plugin registry for testing. Register a prebind and a postbind plugin. // Create a plugin registry for testing. Register a prebind and a postbind plugin.
prebindPlugin := &PrebindPlugin{} prebindPlugin := &PrebindPlugin{}
postbindPlugin := &PostbindPlugin{name: postbindPluginName} postBindPlugin := &PostBindPlugin{name: postBindPluginName}
registry := framework.Registry{ registry := framework.Registry{
prebindPluginName: newPlugin(prebindPlugin), prebindPluginName: newPlugin(prebindPlugin),
postbindPluginName: newPlugin(postbindPlugin), postBindPluginName: newPlugin(postBindPlugin),
} }
// Setup initial prebind and postbind plugin for testing. // Setup initial prebind and postbind plugin for testing.
@ -1087,7 +1087,7 @@ func TestPostbindPlugin(t *testing.T) {
PostBind: &schedulerconfig.PluginSet{ PostBind: &schedulerconfig.PluginSet{
Enabled: []schedulerconfig.Plugin{ Enabled: []schedulerconfig.Plugin{
{ {
Name: postbindPluginName, Name: postBindPluginName,
}, },
}, },
}, },
@ -1099,7 +1099,7 @@ func TestPostbindPlugin(t *testing.T) {
Args: runtime.Unknown{}, Args: runtime.Unknown{},
}, },
{ {
Name: postbindPluginName, Name: postBindPluginName,
Args: runtime.Unknown{}, Args: runtime.Unknown{},
}, },
} }
@ -1154,28 +1154,28 @@ func TestPostbindPlugin(t *testing.T) {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil { if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err) t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
} }
if postbindPlugin.numPostbindCalled > 0 { if postBindPlugin.numPostBindCalled > 0 {
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postbindPlugin.numPostbindCalled) t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
} }
} else { } else {
if test.prebindReject { if test.prebindReject {
if err = waitForPodUnschedulable(cs, pod); err != nil { if err = waitForPodUnschedulable(cs, pod); err != nil {
t.Errorf("test #%v: Didn't expected the pod to be scheduled. error: %v", i, err) t.Errorf("test #%v: Didn't expected the pod to be scheduled. error: %v", i, err)
} }
if postbindPlugin.numPostbindCalled > 0 { if postBindPlugin.numPostBindCalled > 0 {
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postbindPlugin.numPostbindCalled) t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
} }
} else { } else {
if err = waitForPodToSchedule(cs, pod); err != nil { if err = waitForPodToSchedule(cs, pod); err != nil {
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err) t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
} }
if postbindPlugin.numPostbindCalled == 0 { if postBindPlugin.numPostBindCalled == 0 {
t.Errorf("test #%v: Expected the postbind plugin to be called, was called %d times.", i, postbindPlugin.numPostbindCalled) t.Errorf("test #%v: Expected the postbind plugin to be called, was called %d times.", i, postBindPlugin.numPostBindCalled)
} }
} }
} }
postbindPlugin.reset() postBindPlugin.reset()
prebindPlugin.reset() prebindPlugin.reset()
cleanupPods(cs, t, []*v1.Pod{pod}) cleanupPods(cs, t, []*v1.Pod{pod})
} }