Skip to content

Commit af2e042

Browse files
author
draveness
committed
feat: use PreBind instead of Prebind in the scheduling framework
1 parent 03f0934 commit af2e042

File tree

8 files changed

+101
-101
lines changed

8 files changed

+101
-101
lines changed

pkg/scheduler/framework/plugins/examples/multipoint/multipoint.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package multipoint
1818

1919
import (
20-
"k8s.io/api/core/v1"
20+
v1 "k8s.io/api/core/v1"
2121
"k8s.io/apimachinery/pkg/runtime"
2222
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
2323
)
@@ -27,7 +27,7 @@ import (
2727
type CommunicatingPlugin struct{}
2828

2929
var _ = framework.ReservePlugin(CommunicatingPlugin{})
30-
var _ = framework.PrebindPlugin(CommunicatingPlugin{})
30+
var _ = framework.PreBindPlugin(CommunicatingPlugin{})
3131

3232
// Name is the name of the plug used in Registry and configurations.
3333
const Name = "multipoint-communicating-plugin"
@@ -50,8 +50,8 @@ func (mc CommunicatingPlugin) Reserve(pc *framework.PluginContext, pod *v1.Pod,
5050
return nil
5151
}
5252

53-
// Prebind is the functions invoked by the framework at "prebind" extension point.
54-
func (mc CommunicatingPlugin) Prebind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
53+
// PreBind is the functions invoked by the framework at "prebind" extension point.
54+
func (mc CommunicatingPlugin) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
5555
if pod == nil {
5656
return framework.NewStatus(framework.Error, "pod cannot be nil")
5757
}

pkg/scheduler/framework/plugins/examples/prebind/prebind.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ package prebind
1919
import (
2020
"fmt"
2121

22-
"k8s.io/api/core/v1"
22+
v1 "k8s.io/api/core/v1"
2323
"k8s.io/apimachinery/pkg/runtime"
2424
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
2525
)
2626

27-
// StatelessPrebindExample is an example of a simple plugin that has no state
27+
// StatelessPreBindExample is an example of a simple plugin that has no state
2828
// and implements only one hook for prebind.
29-
type StatelessPrebindExample struct{}
29+
type StatelessPreBindExample struct{}
3030

31-
var _ = framework.PrebindPlugin(StatelessPrebindExample{})
31+
var _ = framework.PreBindPlugin(StatelessPreBindExample{})
3232

3333
// Name is the name of the plugin used in Registry and configurations.
3434
const Name = "stateless-prebind-plugin-example"
3535

3636
// Name returns name of the plugin. It is used in logs, etc.
37-
func (sr StatelessPrebindExample) Name() string {
37+
func (sr StatelessPreBindExample) Name() string {
3838
return Name
3939
}
4040

41-
// Prebind is the functions invoked by the framework at "prebind" extension point.
42-
func (sr StatelessPrebindExample) Prebind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
41+
// PreBind is the functions invoked by the framework at "prebind" extension point.
42+
func (sr StatelessPreBindExample) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
4343
if pod == nil {
4444
return framework.NewStatus(framework.Error, fmt.Sprintf("pod cannot be nil"))
4545
}
@@ -51,5 +51,5 @@ func (sr StatelessPrebindExample) Prebind(pc *framework.PluginContext, pod *v1.P
5151

5252
// New initializes a new plugin and returns it.
5353
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
54-
return &StatelessPrebindExample{}, nil
54+
return &StatelessPreBindExample{}, nil
5555
}

pkg/scheduler/framework/plugins/examples/stateful/stateful.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"fmt"
2121
"sync"
2222

23-
"k8s.io/api/core/v1"
23+
v1 "k8s.io/api/core/v1"
2424
"k8s.io/apimachinery/pkg/runtime"
2525
"k8s.io/klog"
2626
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
@@ -36,7 +36,7 @@ type MultipointExample struct {
3636
}
3737

3838
var _ = framework.ReservePlugin(&MultipointExample{})
39-
var _ = framework.PrebindPlugin(&MultipointExample{})
39+
var _ = framework.PreBindPlugin(&MultipointExample{})
4040

4141
// Name is the name of the plug used in Registry and configurations.
4242
const Name = "multipoint-plugin-example"
@@ -53,9 +53,9 @@ func (mp *MultipointExample) Reserve(pc *framework.PluginContext, pod *v1.Pod, n
5353
return nil
5454
}
5555

56-
// Prebind is the functions invoked by the framework at "prebind" extension point.
57-
func (mp *MultipointExample) Prebind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
58-
// Prebind could be called concurrently for different pods.
56+
// PreBind is the functions invoked by the framework at "prebind" extension point.
57+
func (mp *MultipointExample) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
58+
// PreBind could be called concurrently for different pods.
5959
mp.mu.Lock()
6060
defer mp.mu.Unlock()
6161
mp.numRuns++

pkg/scheduler/framework/v1alpha1/framework.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type framework struct {
4545
scorePlugins []ScorePlugin
4646
scoreWithNormalizePlugins []ScoreWithNormalizePlugin
4747
reservePlugins []ReservePlugin
48-
prebindPlugins []PrebindPlugin
48+
preBindPlugins []PreBindPlugin
4949
bindPlugins []BindPlugin
5050
postBindPlugins []PostBindPlugin
5151
unreservePlugins []UnreservePlugin
@@ -186,11 +186,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
186186
if plugins.PreBind != nil {
187187
for _, pb := range plugins.PreBind.Enabled {
188188
if pg, ok := pluginsMap[pb.Name]; ok {
189-
p, ok := pg.(PrebindPlugin)
189+
p, ok := pg.(PreBindPlugin)
190190
if !ok {
191191
return nil, fmt.Errorf("plugin %q does not extend prebind plugin", pb.Name)
192192
}
193-
f.prebindPlugins = append(f.prebindPlugins, p)
193+
f.preBindPlugins = append(f.preBindPlugins, p)
194194
} else {
195195
return nil, fmt.Errorf("prebind plugin %q does not exist", pb.Name)
196196
}
@@ -425,13 +425,13 @@ func (f *framework) RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1.
425425
return pluginToNodeScores, nil
426426
}
427427

428-
// RunPrebindPlugins runs the set of configured prebind plugins. It returns a
428+
// RunPreBindPlugins runs the set of configured prebind plugins. It returns a
429429
// failure (bool) if any of the plugins returns an error. It also returns an
430430
// error containing the rejection message or the error occurred in the plugin.
431-
func (f *framework) RunPrebindPlugins(
431+
func (f *framework) RunPreBindPlugins(
432432
pc *PluginContext, pod *v1.Pod, nodeName string) *Status {
433-
for _, pl := range f.prebindPlugins {
434-
status := pl.Prebind(pc, pod, nodeName)
433+
for _, pl := range f.preBindPlugins {
434+
status := pl.PreBind(pc, pod, nodeName)
435435
if !status.IsSuccess() {
436436
if status.Code() == Unschedulable {
437437
msg := fmt.Sprintf("rejected by %q at prebind: %v", pl.Name(), status.Message())

pkg/scheduler/framework/v1alpha1/interface.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ type ReservePlugin interface {
225225
Reserve(pc *PluginContext, p *v1.Pod, nodeName string) *Status
226226
}
227227

228-
// PrebindPlugin is an interface that must be implemented by "prebind" plugins.
228+
// PreBindPlugin is an interface that must be implemented by "prebind" plugins.
229229
// These plugins are called before a pod being scheduled.
230-
type PrebindPlugin interface {
230+
type PreBindPlugin interface {
231231
Plugin
232-
// Prebind is called before binding a pod. All prebind plugins must return
232+
// PreBind is called before binding a pod. All prebind plugins must return
233233
// success or the pod will be rejected and won't be sent for binding.
234-
Prebind(pc *PluginContext, p *v1.Pod, nodeName string) *Status
234+
PreBind(pc *PluginContext, p *v1.Pod, nodeName string) *Status
235235
}
236236

237237
// PostBindPlugin is an interface that must be implemented by "postbind" plugins.
@@ -311,12 +311,12 @@ type Framework interface {
311311
// a non-success status.
312312
RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1.Node) (PluginToNodeScores, *Status)
313313

314-
// RunPrebindPlugins runs the set of configured prebind plugins. It returns
314+
// RunPreBindPlugins runs the set of configured prebind plugins. It returns
315315
// *Status and its code is set to non-success if any of the plugins returns
316316
// anything but Success. If the Status code is "Unschedulable", it is
317317
// considered as a scheduling check failure, otherwise, it is considered as an
318318
// internal error. In either case the pod is not going to be bound.
319-
RunPrebindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string) *Status
319+
RunPreBindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string) *Status
320320

321321
// RunPostBindPlugins runs the set of configured postbind plugins.
322322
RunPostBindPlugins(pc *PluginContext, pod *v1.Pod, nodeName string)

pkg/scheduler/internal/queue/scheduling_queue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (*fakeFramework) RunScorePlugins(pc *framework.PluginContext, pod *v1.Pod,
179179
return nil, nil
180180
}
181181

182-
func (*fakeFramework) RunPrebindPlugins(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
182+
func (*fakeFramework) RunPreBindPlugins(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
183183
return nil
184184
}
185185

pkg/scheduler/scheduler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,10 @@ func (sched *Scheduler) scheduleOne() {
632632
}
633633

634634
// Run "prebind" plugins.
635-
prebindStatus := fwk.RunPrebindPlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost)
636-
if !prebindStatus.IsSuccess() {
635+
preBindStatus := fwk.RunPreBindPlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost)
636+
if !preBindStatus.IsSuccess() {
637637
var reason string
638-
if prebindStatus.Code() == framework.Unschedulable {
638+
if preBindStatus.Code() == framework.Unschedulable {
639639
metrics.PodScheduleFailures.Inc()
640640
reason = v1.PodReasonUnschedulable
641641
} else {
@@ -647,7 +647,7 @@ func (sched *Scheduler) scheduleOne() {
647647
}
648648
// trigger un-reserve plugins to clean up state associated with the reserved Pod
649649
fwk.RunUnreservePlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost)
650-
sched.recordSchedulingFailure(assumedPod, prebindStatus.AsError(), reason, prebindStatus.Message())
650+
sched.recordSchedulingFailure(assumedPod, preBindStatus.AsError(), reason, preBindStatus.Message())
651651
return
652652
}
653653

0 commit comments

Comments
 (0)