Skip to content

Commit 03f0934

Browse files
author
draveness
committed
feat: use PostBind instead of Postbind in the scheduling framework
1 parent f3816fb commit 03f0934

File tree

5 files changed

+54
-54
lines changed

5 files changed

+54
-54
lines changed

pkg/scheduler/framework/v1alpha1/framework.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type framework struct {
4747
reservePlugins []ReservePlugin
4848
prebindPlugins []PrebindPlugin
4949
bindPlugins []BindPlugin
50-
postbindPlugins []PostbindPlugin
50+
postBindPlugins []PostBindPlugin
5151
unreservePlugins []UnreservePlugin
5252
permitPlugins []PermitPlugin
5353
}
@@ -214,11 +214,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
214214
if plugins.PostBind != nil {
215215
for _, pb := range plugins.PostBind.Enabled {
216216
if pg, ok := pluginsMap[pb.Name]; ok {
217-
p, ok := pg.(PostbindPlugin)
217+
p, ok := pg.(PostBindPlugin)
218218
if !ok {
219219
return nil, fmt.Errorf("plugin %q does not extend postbind plugin", pb.Name)
220220
}
221-
f.postbindPlugins = append(f.postbindPlugins, p)
221+
f.postBindPlugins = append(f.postBindPlugins, p)
222222
} else {
223223
return nil, fmt.Errorf("postbind plugin %q does not exist", pb.Name)
224224
}
@@ -467,11 +467,11 @@ func (f *framework) RunBindPlugins(pc *PluginContext, pod *v1.Pod, nodeName stri
467467
return status
468468
}
469469

470-
// RunPostbindPlugins runs the set of configured postbind plugins.
471-
func (f *framework) RunPostbindPlugins(
470+
// RunPostBindPlugins runs the set of configured postbind plugins.
471+
func (f *framework) RunPostBindPlugins(
472472
pc *PluginContext, pod *v1.Pod, nodeName string) {
473-
for _, pl := range f.postbindPlugins {
474-
pl.Postbind(pc, pod, nodeName)
473+
for _, pl := range f.postBindPlugins {
474+
pl.PostBind(pc, pod, nodeName)
475475
}
476476
}
477477

pkg/scheduler/framework/v1alpha1/interface.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,15 @@ type PrebindPlugin interface {
234234
Prebind(pc *PluginContext, p *v1.Pod, nodeName string) *Status
235235
}
236236

237-
// PostbindPlugin is an interface that must be implemented by "postbind" plugins.
237+
// PostBindPlugin is an interface that must be implemented by "postbind" plugins.
238238
// These plugins are called after a pod is successfully bound to a node.
239-
type PostbindPlugin interface {
239+
type PostBindPlugin interface {
240240
Plugin
241-
// Postbind is called after a pod is successfully bound. These plugins are
241+
// PostBind is called after a pod is successfully bound. These plugins are
242242
// informational. A common application of this extension point is for cleaning
243243
// up. If a plugin needs to clean-up its state after a pod is scheduled and
244-
// bound, Postbind is the extension point that it should register.
245-
Postbind(pc *PluginContext, p *v1.Pod, nodeName string)
244+
// bound, PostBind is the extension point that it should register.
245+
PostBind(pc *PluginContext, p *v1.Pod, nodeName string)
246246
}
247247

248248
// UnreservePlugin is an interface for Unreserve plugins. This is an informational
@@ -318,8 +318,8 @@ type Framework interface {
318318
// internal error. In either case the pod is not going to be bound.
319319
RunPrebindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string) *Status
320320

321-
// RunPostbindPlugins runs the set of configured postbind plugins.
322-
RunPostbindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string)
321+
// RunPostBindPlugins runs the set of configured postbind plugins.
322+
RunPostBindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string)
323323

324324
// RunReservePlugins runs the set of configured reserve plugins. If any of these
325325
// plugins returns an error, it does not continue running the remaining ones and

pkg/scheduler/internal/queue/scheduling_queue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (*fakeFramework) RunBindPlugins(pc *framework.PluginContext, pod *v1.Pod, n
187187
return nil
188188
}
189189

190-
func (*fakeFramework) RunPostbindPlugins(pc *framework.PluginContext, pod *v1.Pod, nodeName string) {}
190+
func (*fakeFramework) RunPostBindPlugins(pc *framework.PluginContext, pod *v1.Pod, nodeName string) {}
191191

192192
func (*fakeFramework) RunPostFilterPlugins(pc *framework.PluginContext, pod *v1.Pod, nodes []*v1.Node, filteredNodesStatuses framework.NodeToStatusMap) *framework.Status {
193193
return nil

pkg/scheduler/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ func (sched *Scheduler) scheduleOne() {
670670
metrics.PodScheduleSuccesses.Inc()
671671

672672
// Run "postbind" plugins.
673-
fwk.RunPostbindPlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost)
673+
fwk.RunPostBindPlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost)
674674
}
675675
}()
676676
}

test/integration/scheduler/framework_test.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ type BindPlugin struct {
7777
pluginInvokeEventChan chan pluginInvokeEvent
7878
}
7979

80-
type PostbindPlugin struct {
80+
type PostBindPlugin struct {
8181
name string
82-
numPostbindCalled int
82+
numPostBindCalled int
8383
pluginInvokeEventChan chan pluginInvokeEvent
8484
}
8585

@@ -109,7 +109,7 @@ const (
109109
reservePluginName = "reserve-plugin"
110110
prebindPluginName = "prebind-plugin"
111111
unreservePluginName = "unreserve-plugin"
112-
postbindPluginName = "postbind-plugin"
112+
postBindPluginName = "postbind-plugin"
113113
permitPluginName = "permit-plugin"
114114
)
115115

@@ -122,7 +122,7 @@ var _ = framework.ReservePlugin(&ReservePlugin{})
122122
var _ = framework.PostFilterPlugin(&PostFilterPlugin{})
123123
var _ = framework.PrebindPlugin(&PrebindPlugin{})
124124
var _ = framework.BindPlugin(&BindPlugin{})
125-
var _ = framework.PostbindPlugin(&PostbindPlugin{})
125+
var _ = framework.PostBindPlugin(&PostBindPlugin{})
126126
var _ = framework.UnreservePlugin(&UnreservePlugin{})
127127
var _ = framework.PermitPlugin(&PermitPlugin{})
128128

@@ -303,21 +303,21 @@ func (bp *BindPlugin) reset() {
303303
}
304304

305305
// Name returns name of the plugin.
306-
func (pp *PostbindPlugin) Name() string {
306+
func (pp *PostBindPlugin) Name() string {
307307
return pp.name
308308
}
309309

310-
// Postbind is a test function, which counts the number of times called.
311-
func (pp *PostbindPlugin) Postbind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) {
312-
pp.numPostbindCalled++
310+
// PostBind is a test function, which counts the number of times called.
311+
func (pp *PostBindPlugin) PostBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) {
312+
pp.numPostBindCalled++
313313
if pp.pluginInvokeEventChan != nil {
314-
pp.pluginInvokeEventChan <- pluginInvokeEvent{pluginName: pp.Name(), val: pp.numPostbindCalled}
314+
pp.pluginInvokeEventChan <- pluginInvokeEvent{pluginName: pp.Name(), val: pp.numPostBindCalled}
315315
}
316316
}
317317

318318
// reset used to reset postbind plugin.
319-
func (pp *PostbindPlugin) reset() {
320-
pp.numPostbindCalled = 0
319+
func (pp *PostBindPlugin) reset() {
320+
pp.numPostBindCalled = 0
321321
}
322322

323323
// Name returns name of the plugin.
@@ -884,7 +884,7 @@ func TestBindPlugin(t *testing.T) {
884884
bindPlugin1 := &BindPlugin{PluginName: "bind-plugin-1", client: testContext.clientSet}
885885
bindPlugin2 := &BindPlugin{PluginName: "bind-plugin-2", client: testContext.clientSet}
886886
unreservePlugin := &UnreservePlugin{name: "mock-unreserve-plugin"}
887-
postbindPlugin := &PostbindPlugin{name: "mock-post-bind-plugin"}
887+
postBindPlugin := &PostBindPlugin{name: "mock-post-bind-plugin"}
888888
// Create a plugin registry for testing. Register an unreserve, a bind plugin and a postBind plugin.
889889
registry := framework.Registry{
890890
unreservePlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
@@ -896,8 +896,8 @@ func TestBindPlugin(t *testing.T) {
896896
bindPlugin2.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
897897
return bindPlugin2, nil
898898
},
899-
postbindPlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
900-
return postbindPlugin, nil
899+
postBindPlugin.Name(): func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
900+
return postBindPlugin, nil
901901
},
902902
}
903903

@@ -910,7 +910,7 @@ func TestBindPlugin(t *testing.T) {
910910
Enabled: []schedulerconfig.Plugin{{Name: bindPlugin1.Name()}, {Name: bindPlugin2.Name()}},
911911
},
912912
PostBind: &schedulerconfig.PluginSet{
913-
Enabled: []schedulerconfig.Plugin{{Name: postbindPlugin.Name()}},
913+
Enabled: []schedulerconfig.Plugin{{Name: postBindPlugin.Name()}},
914914
},
915915
}
916916
// Set reserve and bind config for testing
@@ -928,7 +928,7 @@ func TestBindPlugin(t *testing.T) {
928928
Args: runtime.Unknown{},
929929
},
930930
{
931-
Name: postbindPlugin.Name(),
931+
Name: postBindPlugin.Name(),
932932
Args: runtime.Unknown{},
933933
},
934934
}
@@ -956,21 +956,21 @@ func TestBindPlugin(t *testing.T) {
956956
{
957957
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Skip, "")},
958958
expectBoundByScheduler: true,
959-
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postbindPlugin.Name(), val: 1}},
959+
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
960960
},
961961
// bindplugin2 succeeded to bind the pod
962962
{
963963
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Success, "")},
964964
expectBoundByPlugin: true,
965965
expectBindPluginName: bindPlugin2.Name(),
966-
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postbindPlugin.Name(), val: 1}},
966+
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
967967
},
968968
// bindplugin1 succeeded to bind the pod
969969
{
970970
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Success, ""), framework.NewStatus(framework.Success, "")},
971971
expectBoundByPlugin: true,
972972
expectBindPluginName: bindPlugin1.Name(),
973-
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: postbindPlugin.Name(), val: 1}},
973+
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
974974
},
975975
// bind plugin fails to bind the pod
976976
{
@@ -988,7 +988,7 @@ func TestBindPlugin(t *testing.T) {
988988
bindPlugin1.pluginInvokeEventChan = pluginInvokeEventChan
989989
bindPlugin2.pluginInvokeEventChan = pluginInvokeEventChan
990990
unreservePlugin.pluginInvokeEventChan = pluginInvokeEventChan
991-
postbindPlugin.pluginInvokeEventChan = pluginInvokeEventChan
991+
postBindPlugin.pluginInvokeEventChan = pluginInvokeEventChan
992992

993993
// Create a best effort pod.
994994
pod, err := createPausePod(cs,
@@ -1027,9 +1027,9 @@ func TestBindPlugin(t *testing.T) {
10271027
}
10281028
}
10291029
if err = wait.Poll(10*time.Millisecond, 30*time.Second, func() (done bool, err error) {
1030-
return postbindPlugin.numPostbindCalled == 1, nil
1030+
return postBindPlugin.numPostBindCalled == 1, nil
10311031
}); err != nil {
1032-
t.Errorf("test #%v: Expected the postbind plugin to be called once, was called %d times.", i, postbindPlugin.numPostbindCalled)
1032+
t.Errorf("test #%v: Expected the postbind plugin to be called once, was called %d times.", i, postBindPlugin.numPostBindCalled)
10331033
}
10341034
if unreservePlugin.numUnreserveCalled != 0 {
10351035
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) {
10391039
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
10401040
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
10411041
}
1042-
if postbindPlugin.numPostbindCalled > 0 {
1043-
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postbindPlugin.numPostbindCalled)
1042+
if postBindPlugin.numPostBindCalled > 0 {
1043+
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
10441044
}
10451045
}
10461046
for j := range test.expectInvokeEvents {
@@ -1057,22 +1057,22 @@ func TestBindPlugin(t *testing.T) {
10571057
t.Errorf("test #%v: Waiting for invoke event %d timeout.", i, j)
10581058
}
10591059
}
1060-
postbindPlugin.reset()
1060+
postBindPlugin.reset()
10611061
bindPlugin1.reset()
10621062
bindPlugin2.reset()
10631063
unreservePlugin.reset()
10641064
cleanupPods(cs, t, []*v1.Pod{pod})
10651065
}
10661066
}
10671067

1068-
// TestPostbindPlugin tests invocation of postbind plugins.
1069-
func TestPostbindPlugin(t *testing.T) {
1068+
// TestPostBindPlugin tests invocation of postbind plugins.
1069+
func TestPostBindPlugin(t *testing.T) {
10701070
// Create a plugin registry for testing. Register a prebind and a postbind plugin.
10711071
prebindPlugin := &PrebindPlugin{}
1072-
postbindPlugin := &PostbindPlugin{name: postbindPluginName}
1072+
postBindPlugin := &PostBindPlugin{name: postBindPluginName}
10731073
registry := framework.Registry{
10741074
prebindPluginName: newPlugin(prebindPlugin),
1075-
postbindPluginName: newPlugin(postbindPlugin),
1075+
postBindPluginName: newPlugin(postBindPlugin),
10761076
}
10771077

10781078
// Setup initial prebind and postbind plugin for testing.
@@ -1087,7 +1087,7 @@ func TestPostbindPlugin(t *testing.T) {
10871087
PostBind: &schedulerconfig.PluginSet{
10881088
Enabled: []schedulerconfig.Plugin{
10891089
{
1090-
Name: postbindPluginName,
1090+
Name: postBindPluginName,
10911091
},
10921092
},
10931093
},
@@ -1099,7 +1099,7 @@ func TestPostbindPlugin(t *testing.T) {
10991099
Args: runtime.Unknown{},
11001100
},
11011101
{
1102-
Name: postbindPluginName,
1102+
Name: postBindPluginName,
11031103
Args: runtime.Unknown{},
11041104
},
11051105
}
@@ -1154,28 +1154,28 @@ func TestPostbindPlugin(t *testing.T) {
11541154
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
11551155
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
11561156
}
1157-
if postbindPlugin.numPostbindCalled > 0 {
1158-
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postbindPlugin.numPostbindCalled)
1157+
if postBindPlugin.numPostBindCalled > 0 {
1158+
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
11591159
}
11601160
} else {
11611161
if test.prebindReject {
11621162
if err = waitForPodUnschedulable(cs, pod); err != nil {
11631163
t.Errorf("test #%v: Didn't expected the pod to be scheduled. error: %v", i, err)
11641164
}
1165-
if postbindPlugin.numPostbindCalled > 0 {
1166-
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postbindPlugin.numPostbindCalled)
1165+
if postBindPlugin.numPostBindCalled > 0 {
1166+
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
11671167
}
11681168
} else {
11691169
if err = waitForPodToSchedule(cs, pod); err != nil {
11701170
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
11711171
}
1172-
if postbindPlugin.numPostbindCalled == 0 {
1173-
t.Errorf("test #%v: Expected the postbind plugin to be called, was called %d times.", i, postbindPlugin.numPostbindCalled)
1172+
if postBindPlugin.numPostBindCalled == 0 {
1173+
t.Errorf("test #%v: Expected the postbind plugin to be called, was called %d times.", i, postBindPlugin.numPostBindCalled)
11741174
}
11751175
}
11761176
}
11771177

1178-
postbindPlugin.reset()
1178+
postBindPlugin.reset()
11791179
prebindPlugin.reset()
11801180
cleanupPods(cs, t, []*v1.Pod{pod})
11811181
}

0 commit comments

Comments
 (0)