Merge pull request #81800 from draveness/feature/update-post-filter-plugin-name

feat: update scheduling framework interface with camelcase
This commit is contained in:
Kubernetes Prow Robot
2019-08-23 06:53:49 -07:00
committed by GitHub
9 changed files with 195 additions and 195 deletions

View File

@@ -195,9 +195,9 @@ func (g *genericScheduler) Schedule(pod *v1.Pod, pluginContext *framework.Plugin
} }
// Run "prefilter" plugins. // Run "prefilter" plugins.
prefilterStatus := g.framework.RunPrefilterPlugins(pluginContext, pod) preFilterStatus := g.framework.RunPreFilterPlugins(pluginContext, pod)
if !prefilterStatus.IsSuccess() { if !preFilterStatus.IsSuccess() {
return result, prefilterStatus.AsError() return result, preFilterStatus.AsError()
} }
numNodes := g.cache.NodeTree().NumNodes() numNodes := g.cache.NodeTree().NumNodes()

View File

@@ -17,7 +17,7 @@ limitations under the License.
package multipoint package multipoint
import ( import (
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
) )
@@ -27,7 +27,7 @@ import (
type CommunicatingPlugin struct{} type CommunicatingPlugin struct{}
var _ = framework.ReservePlugin(CommunicatingPlugin{}) var _ = framework.ReservePlugin(CommunicatingPlugin{})
var _ = framework.PrebindPlugin(CommunicatingPlugin{}) var _ = framework.PreBindPlugin(CommunicatingPlugin{})
// Name is the name of the plug used in Registry and configurations. // Name is the name of the plug used in Registry and configurations.
const Name = "multipoint-communicating-plugin" const Name = "multipoint-communicating-plugin"
@@ -50,8 +50,8 @@ func (mc CommunicatingPlugin) Reserve(pc *framework.PluginContext, pod *v1.Pod,
return nil return nil
} }
// Prebind is the functions invoked by the framework at "prebind" extension point. // PreBind is the functions invoked by the framework at "prebind" extension point.
func (mc CommunicatingPlugin) Prebind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status { func (mc CommunicatingPlugin) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
if pod == nil { if pod == nil {
return framework.NewStatus(framework.Error, "pod cannot be nil") return framework.NewStatus(framework.Error, "pod cannot be nil")
} }

View File

@@ -19,27 +19,27 @@ package prebind
import ( import (
"fmt" "fmt"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
) )
// StatelessPrebindExample is an example of a simple plugin that has no state // StatelessPreBindExample is an example of a simple plugin that has no state
// and implements only one hook for prebind. // and implements only one hook for prebind.
type StatelessPrebindExample struct{} type StatelessPreBindExample struct{}
var _ = framework.PrebindPlugin(StatelessPrebindExample{}) var _ = framework.PreBindPlugin(StatelessPreBindExample{})
// Name is the name of the plugin used in Registry and configurations. // Name is the name of the plugin used in Registry and configurations.
const Name = "stateless-prebind-plugin-example" const Name = "stateless-prebind-plugin-example"
// Name returns name of the plugin. It is used in logs, etc. // Name returns name of the plugin. It is used in logs, etc.
func (sr StatelessPrebindExample) Name() string { func (sr StatelessPreBindExample) Name() string {
return Name return Name
} }
// Prebind is the functions invoked by the framework at "prebind" extension point. // PreBind is the functions invoked by the framework at "prebind" extension point.
func (sr StatelessPrebindExample) Prebind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status { func (sr StatelessPreBindExample) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
if pod == nil { if pod == nil {
return framework.NewStatus(framework.Error, fmt.Sprintf("pod cannot be nil")) return framework.NewStatus(framework.Error, fmt.Sprintf("pod cannot be nil"))
} }
@@ -51,5 +51,5 @@ func (sr StatelessPrebindExample) Prebind(pc *framework.PluginContext, pod *v1.P
// New initializes a new plugin and returns it. // New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &StatelessPrebindExample{}, nil return &StatelessPreBindExample{}, nil
} }

View File

@@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog" "k8s.io/klog"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
@@ -36,7 +36,7 @@ type MultipointExample struct {
} }
var _ = framework.ReservePlugin(&MultipointExample{}) var _ = framework.ReservePlugin(&MultipointExample{})
var _ = framework.PrebindPlugin(&MultipointExample{}) var _ = framework.PreBindPlugin(&MultipointExample{})
// Name is the name of the plug used in Registry and configurations. // Name is the name of the plug used in Registry and configurations.
const Name = "multipoint-plugin-example" const Name = "multipoint-plugin-example"
@@ -53,9 +53,9 @@ func (mp *MultipointExample) Reserve(pc *framework.PluginContext, pod *v1.Pod, n
return nil return nil
} }
// Prebind is the functions invoked by the framework at "prebind" extension point. // PreBind is the functions invoked by the framework at "prebind" extension point.
func (mp *MultipointExample) Prebind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status { func (mp *MultipointExample) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
// Prebind could be called concurrently for different pods. // PreBind could be called concurrently for different pods.
mp.mu.Lock() mp.mu.Lock()
defer mp.mu.Unlock() defer mp.mu.Unlock()
mp.numRuns++ mp.numRuns++

View File

@@ -39,15 +39,15 @@ type framework struct {
waitingPods *waitingPodsMap waitingPods *waitingPodsMap
pluginNameToWeightMap map[string]int pluginNameToWeightMap map[string]int
queueSortPlugins []QueueSortPlugin queueSortPlugins []QueueSortPlugin
prefilterPlugins []PrefilterPlugin preFilterPlugins []PreFilterPlugin
filterPlugins []FilterPlugin filterPlugins []FilterPlugin
postFilterPlugins []PostFilterPlugin postFilterPlugins []PostFilterPlugin
scorePlugins []ScorePlugin scorePlugins []ScorePlugin
scoreWithNormalizePlugins []ScoreWithNormalizePlugin scoreWithNormalizePlugins []ScoreWithNormalizePlugin
reservePlugins []ReservePlugin reservePlugins []ReservePlugin
prebindPlugins []PrebindPlugin preBindPlugins []PreBindPlugin
bindPlugins []BindPlugin bindPlugins []BindPlugin
postbindPlugins []PostbindPlugin postBindPlugins []PostBindPlugin
unreservePlugins []UnreservePlugin unreservePlugins []UnreservePlugin
permitPlugins []PermitPlugin permitPlugins []PermitPlugin
} }
@@ -105,11 +105,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
if plugins.PreFilter != nil { if plugins.PreFilter != nil {
for _, pf := range plugins.PreFilter.Enabled { for _, pf := range plugins.PreFilter.Enabled {
if pg, ok := pluginsMap[pf.Name]; ok { if pg, ok := pluginsMap[pf.Name]; ok {
p, ok := pg.(PrefilterPlugin) p, ok := pg.(PreFilterPlugin)
if !ok { if !ok {
return nil, fmt.Errorf("plugin %q does not extend prefilter plugin", pf.Name) 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 { } else {
return nil, fmt.Errorf("prefilter plugin %q does not exist", pf.Name) return nil, fmt.Errorf("prefilter plugin %q does not exist", pf.Name)
} }
@@ -186,11 +186,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
if plugins.PreBind != nil { if plugins.PreBind != nil {
for _, pb := range plugins.PreBind.Enabled { for _, pb := range plugins.PreBind.Enabled {
if pg, ok := pluginsMap[pb.Name]; ok { if pg, ok := pluginsMap[pb.Name]; ok {
p, ok := pg.(PrebindPlugin) p, ok := pg.(PreBindPlugin)
if !ok { if !ok {
return nil, fmt.Errorf("plugin %q does not extend prebind plugin", pb.Name) return nil, fmt.Errorf("plugin %q does not extend prebind plugin", pb.Name)
} }
f.prebindPlugins = append(f.prebindPlugins, p) f.preBindPlugins = append(f.preBindPlugins, p)
} else { } else {
return nil, fmt.Errorf("prebind plugin %q does not exist", pb.Name) return nil, fmt.Errorf("prebind plugin %q does not exist", pb.Name)
} }
@@ -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)
} }
@@ -283,14 +283,14 @@ func (f *framework) QueueSortFunc() LessFunc {
return f.queueSortPlugins[0].Less 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 // *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 // anything but Success. If a non-success status is returned, then the scheduling
// cycle is aborted. // cycle is aborted.
func (f *framework) RunPrefilterPlugins( func (f *framework) RunPreFilterPlugins(
pc *PluginContext, pod *v1.Pod) *Status { pc *PluginContext, pod *v1.Pod) *Status {
for _, pl := range f.prefilterPlugins { for _, pl := range f.preFilterPlugins {
status := pl.Prefilter(pc, pod) status := pl.PreFilter(pc, pod)
if !status.IsSuccess() { if !status.IsSuccess() {
if status.Code() == Unschedulable { if status.Code() == Unschedulable {
msg := fmt.Sprintf("rejected by %q at prefilter: %v", pl.Name(), status.Message()) msg := fmt.Sprintf("rejected by %q at prefilter: %v", pl.Name(), status.Message())
@@ -425,13 +425,13 @@ func (f *framework) RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1.
return pluginToNodeScores, nil return pluginToNodeScores, nil
} }
// RunPrebindPlugins runs the set of configured prebind plugins. It returns a // RunPreBindPlugins runs the set of configured prebind plugins. It returns a
// failure (bool) if any of the plugins returns an error. It also returns an // failure (bool) if any of the plugins returns an error. It also returns an
// error containing the rejection message or the error occurred in the plugin. // error containing the rejection message or the error occurred in the plugin.
func (f *framework) RunPrebindPlugins( func (f *framework) RunPreBindPlugins(
pc *PluginContext, pod *v1.Pod, nodeName string) *Status { pc *PluginContext, pod *v1.Pod, nodeName string) *Status {
for _, pl := range f.prebindPlugins { for _, pl := range f.preBindPlugins {
status := pl.Prebind(pc, pod, nodeName) status := pl.PreBind(pc, pod, nodeName)
if !status.IsSuccess() { if !status.IsSuccess() {
if status.Code() == Unschedulable { if status.Code() == Unschedulable {
msg := fmt.Sprintf("rejected by %q at prebind: %v", pl.Name(), status.Message()) msg := fmt.Sprintf("rejected by %q at prebind: %v", pl.Name(), status.Message())
@@ -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

@@ -152,13 +152,13 @@ type QueueSortPlugin interface {
Less(*PodInfo, *PodInfo) bool 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. // These plugins are called at the beginning of the scheduling cycle.
type PrefilterPlugin interface { type PreFilterPlugin interface {
Plugin 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. // 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 // FilterPlugin is an interface for Filter plugins. These plugins are called at the
@@ -225,24 +225,24 @@ type ReservePlugin interface {
Reserve(pc *PluginContext, p *v1.Pod, nodeName string) *Status Reserve(pc *PluginContext, p *v1.Pod, nodeName string) *Status
} }
// PrebindPlugin is an interface that must be implemented by "prebind" plugins. // PreBindPlugin is an interface that must be implemented by "prebind" plugins.
// These plugins are called before a pod being scheduled. // These plugins are called before a pod being scheduled.
type PrebindPlugin interface { type PreBindPlugin interface {
Plugin Plugin
// Prebind is called before binding a pod. All prebind plugins must return // PreBind is called before binding a pod. All prebind plugins must return
// success or the pod will be rejected and won't be sent for binding. // success or the pod will be rejected and won't be sent for binding.
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
@@ -289,11 +289,11 @@ type Framework interface {
// QueueSortFunc returns the function to sort pods in scheduling queue // QueueSortFunc returns the function to sort pods in scheduling queue
QueueSortFunc() LessFunc 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 // *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 // anything but Success. If a non-success status is returned, then the scheduling
// cycle is aborted. // 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 // 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", // given host. If any of these plugins returns any status other than "Success",
@@ -311,15 +311,15 @@ type Framework interface {
// a non-success status. // a non-success status.
RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1.Node) (PluginToNodeScores, *Status) RunScorePlugins(pc *PluginContext, pod *v1.Pod, nodes []*v1.Node) (PluginToNodeScores, *Status)
// RunPrebindPlugins runs the set of configured prebind plugins. It returns // RunPreBindPlugins runs the set of configured prebind plugins. It returns
// *Status and its code is set to non-success if any of the plugins returns // *Status and its code is set to non-success if any of the plugins returns
// anything but Success. If the Status code is "Unschedulable", it is // anything but Success. If the Status code is "Unschedulable", it is
// considered as a scheduling check failure, otherwise, it is considered as an // considered as a scheduling check failure, otherwise, it is considered as an
// 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

@@ -167,7 +167,7 @@ func (*fakeFramework) NodeInfoSnapshot() *internalcache.NodeInfoSnapshot {
return nil 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 return nil
} }
@@ -179,7 +179,7 @@ func (*fakeFramework) RunScorePlugins(pc *framework.PluginContext, pod *v1.Pod,
return nil, nil return nil, nil
} }
func (*fakeFramework) RunPrebindPlugins(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status { func (*fakeFramework) RunPreBindPlugins(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
return nil return nil
} }
@@ -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

@@ -632,10 +632,10 @@ func (sched *Scheduler) scheduleOne() {
} }
// Run "prebind" plugins. // Run "prebind" plugins.
prebindStatus := fwk.RunPrebindPlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost) preBindStatus := fwk.RunPreBindPlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost)
if !prebindStatus.IsSuccess() { if !preBindStatus.IsSuccess() {
var reason string var reason string
if prebindStatus.Code() == framework.Unschedulable { if preBindStatus.Code() == framework.Unschedulable {
metrics.PodScheduleFailures.Inc() metrics.PodScheduleFailures.Inc()
reason = v1.PodReasonUnschedulable reason = v1.PodReasonUnschedulable
} else { } else {
@@ -647,7 +647,7 @@ func (sched *Scheduler) scheduleOne() {
} }
// trigger un-reserve plugins to clean up state associated with the reserved Pod // trigger un-reserve plugins to clean up state associated with the reserved Pod
fwk.RunUnreservePlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost) fwk.RunUnreservePlugins(pluginContext, assumedPod, scheduleResult.SuggestedHost)
sched.recordSchedulingFailure(assumedPod, prebindStatus.AsError(), reason, prebindStatus.Message()) sched.recordSchedulingFailure(assumedPod, preBindStatus.AsError(), reason, preBindStatus.Message())
return return
} }
@@ -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

@@ -31,10 +31,10 @@ import (
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
) )
type PrefilterPlugin struct { type PreFilterPlugin struct {
numPrefilterCalled int numPreFilterCalled int
failPrefilter bool failPreFilter bool
rejectPrefilter bool rejectPreFilter bool
} }
type ScorePlugin struct { type ScorePlugin struct {
@@ -63,10 +63,10 @@ type PostFilterPlugin struct {
failPostFilter bool failPostFilter bool
} }
type PrebindPlugin struct { type PreBindPlugin struct {
numPrebindCalled int numPreBindCalled int
failPrebind bool failPreBind bool
rejectPrebind bool rejectPreBind bool
} }
type BindPlugin struct { type BindPlugin struct {
@@ -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
} }
@@ -107,22 +107,22 @@ const (
filterPluginName = "filter-plugin" filterPluginName = "filter-plugin"
postFilterPluginName = "postfilter-plugin" postFilterPluginName = "postfilter-plugin"
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"
) )
var _ = framework.PrefilterPlugin(&PrefilterPlugin{}) var _ = framework.PreFilterPlugin(&PreFilterPlugin{})
var _ = framework.ScorePlugin(&ScorePlugin{}) var _ = framework.ScorePlugin(&ScorePlugin{})
var _ = framework.FilterPlugin(&FilterPlugin{}) var _ = framework.FilterPlugin(&FilterPlugin{})
var _ = framework.ScorePlugin(&ScorePlugin{}) var _ = framework.ScorePlugin(&ScorePlugin{})
var _ = framework.ScoreWithNormalizePlugin(&ScoreWithNormalizePlugin{}) var _ = framework.ScoreWithNormalizePlugin(&ScoreWithNormalizePlugin{})
var _ = framework.ReservePlugin(&ReservePlugin{}) 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{})
@@ -249,27 +249,27 @@ func (pfp *PostFilterPlugin) reset() {
} }
// Name returns name of the plugin. // Name returns name of the plugin.
func (pp *PrebindPlugin) Name() string { func (pp *PreBindPlugin) Name() string {
return prebindPluginName return preBindPluginName
} }
// Prebind is a test function that returns (true, nil) or errors for testing. // PreBind is a test function that returns (true, nil) or errors for testing.
func (pp *PrebindPlugin) Prebind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status { func (pp *PreBindPlugin) PreBind(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
pp.numPrebindCalled++ pp.numPreBindCalled++
if pp.failPrebind { if pp.failPreBind {
return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name)) return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name))
} }
if pp.rejectPrebind { if pp.rejectPreBind {
return framework.NewStatus(framework.Unschedulable, fmt.Sprintf("reject pod %v", pod.Name)) return framework.NewStatus(framework.Unschedulable, fmt.Sprintf("reject pod %v", pod.Name))
} }
return nil return nil
} }
// reset used to reset prebind plugin. // reset used to reset prebind plugin.
func (pp *PrebindPlugin) reset() { func (pp *PreBindPlugin) reset() {
pp.numPrebindCalled = 0 pp.numPreBindCalled = 0
pp.failPrebind = false pp.failPreBind = false
pp.rejectPrebind = false pp.rejectPreBind = false
} }
const bindPluginAnnotation = "bindPluginName" const bindPluginAnnotation = "bindPluginName"
@@ -303,45 +303,45 @@ 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.
func (pp *PrefilterPlugin) Name() string { func (pp *PreFilterPlugin) Name() string {
return prefilterPluginName return prefilterPluginName
} }
// Prefilter is a test function that returns (true, nil) or errors for testing. // 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 { func (pp *PreFilterPlugin) PreFilter(pc *framework.PluginContext, pod *v1.Pod) *framework.Status {
pp.numPrefilterCalled++ pp.numPreFilterCalled++
if pp.failPrefilter { if pp.failPreFilter {
return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name)) 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 framework.NewStatus(framework.Unschedulable, fmt.Sprintf("reject pod %v", pod.Name))
} }
return nil return nil
} }
// reset used to reset prefilter plugin. // reset used to reset prefilter plugin.
func (pp *PrefilterPlugin) reset() { func (pp *PreFilterPlugin) reset() {
pp.numPrefilterCalled = 0 pp.numPreFilterCalled = 0
pp.failPrefilter = false pp.failPreFilter = false
pp.rejectPrefilter = false pp.rejectPreFilter = false
} }
// Name returns name of the plugin. // Name returns name of the plugin.
@@ -426,11 +426,11 @@ func newPermitPlugin(permitPlugin *PermitPlugin) framework.PluginFactory {
} }
} }
// TestPrefilterPlugin tests invocation of prefilter plugins. // TestPreFilterPlugin tests invocation of prefilter plugins.
func TestPrefilterPlugin(t *testing.T) { func TestPreFilterPlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a pre-filter plugin. // Create a plugin registry for testing. Register only a pre-filter plugin.
prefilterPlugin := &PrefilterPlugin{} preFilterPlugin := &PreFilterPlugin{}
registry := framework.Registry{prefilterPluginName: newPlugin(prefilterPlugin)} registry := framework.Registry{prefilterPluginName: newPlugin(preFilterPlugin)}
// Setup initial prefilter plugin for testing. // Setup initial prefilter plugin for testing.
plugins := &schedulerconfig.Plugins{ plugins := &schedulerconfig.Plugins{
@@ -478,8 +478,8 @@ func TestPrefilterPlugin(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
prefilterPlugin.failPrefilter = test.fail preFilterPlugin.failPreFilter = test.fail
prefilterPlugin.rejectPrefilter = test.reject preFilterPlugin.rejectPreFilter = test.reject
// Create a best effort pod. // Create a best effort pod.
pod, err := createPausePod(cs, pod, err := createPausePod(cs,
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name})) 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.") t.Errorf("Expected the prefilter plugin to be called.")
} }
prefilterPlugin.reset() preFilterPlugin.reset()
cleanupPods(cs, t, []*v1.Pod{pod}) cleanupPods(cs, t, []*v1.Pod{pod})
} }
} }
@@ -667,15 +667,15 @@ func TestReservePlugin(t *testing.T) {
// TestPrebindPlugin tests invocation of prebind plugins. // TestPrebindPlugin tests invocation of prebind plugins.
func TestPrebindPlugin(t *testing.T) { func TestPrebindPlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a prebind plugin. // Create a plugin registry for testing. Register only a prebind plugin.
prebindPlugin := &PrebindPlugin{} preBindPlugin := &PreBindPlugin{}
registry := framework.Registry{prebindPluginName: newPlugin(prebindPlugin)} registry := framework.Registry{preBindPluginName: newPlugin(preBindPlugin)}
// Setup initial prebind plugin for testing. // Setup initial prebind plugin for testing.
plugins := &schedulerconfig.Plugins{ plugins := &schedulerconfig.Plugins{
PreBind: &schedulerconfig.PluginSet{ PreBind: &schedulerconfig.PluginSet{
Enabled: []schedulerconfig.Plugin{ Enabled: []schedulerconfig.Plugin{
{ {
Name: prebindPluginName, Name: preBindPluginName,
}, },
}, },
}, },
@@ -683,7 +683,7 @@ func TestPrebindPlugin(t *testing.T) {
// Set reserve prebind config for testing // Set reserve prebind config for testing
preBindPluginConfig := []schedulerconfig.PluginConfig{ preBindPluginConfig := []schedulerconfig.PluginConfig{
{ {
Name: prebindPluginName, Name: preBindPluginName,
Args: runtime.Unknown{}, Args: runtime.Unknown{},
}, },
} }
@@ -723,8 +723,8 @@ func TestPrebindPlugin(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
prebindPlugin.failPrebind = test.fail preBindPlugin.failPreBind = test.fail
prebindPlugin.rejectPrebind = test.reject preBindPlugin.rejectPreBind = test.reject
// Create a best effort pod. // Create a best effort pod.
pod, err := createPausePod(cs, pod, err := createPausePod(cs,
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name})) initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
@@ -748,11 +748,11 @@ func TestPrebindPlugin(t *testing.T) {
} }
} }
if prebindPlugin.numPrebindCalled == 0 { if preBindPlugin.numPreBindCalled == 0 {
t.Errorf("Expected the prebind plugin to be called.") t.Errorf("Expected the prebind plugin to be called.")
} }
prebindPlugin.reset() preBindPlugin.reset()
cleanupPods(cs, t, []*v1.Pod{pod}) cleanupPods(cs, t, []*v1.Pod{pod})
} }
} }
@@ -760,11 +760,11 @@ func TestPrebindPlugin(t *testing.T) {
// TestUnreservePlugin tests invocation of un-reserve plugin // TestUnreservePlugin tests invocation of un-reserve plugin
func TestUnreservePlugin(t *testing.T) { func TestUnreservePlugin(t *testing.T) {
// TODO: register more plugin which would trigger un-reserve plugin // TODO: register more plugin which would trigger un-reserve plugin
prebindPlugin := &PrebindPlugin{} preBindPlugin := &PreBindPlugin{}
unreservePlugin := &UnreservePlugin{name: unreservePluginName} unreservePlugin := &UnreservePlugin{name: unreservePluginName}
registry := framework.Registry{ registry := framework.Registry{
unreservePluginName: newPlugin(unreservePlugin), unreservePluginName: newPlugin(unreservePlugin),
prebindPluginName: newPlugin(prebindPlugin), preBindPluginName: newPlugin(preBindPlugin),
} }
// Setup initial unreserve and prebind plugin for testing. // Setup initial unreserve and prebind plugin for testing.
@@ -779,7 +779,7 @@ func TestUnreservePlugin(t *testing.T) {
PreBind: &schedulerconfig.PluginSet{ PreBind: &schedulerconfig.PluginSet{
Enabled: []schedulerconfig.Plugin{ Enabled: []schedulerconfig.Plugin{
{ {
Name: prebindPluginName, Name: preBindPluginName,
}, },
}, },
}, },
@@ -791,7 +791,7 @@ func TestUnreservePlugin(t *testing.T) {
Args: runtime.Unknown{}, Args: runtime.Unknown{},
}, },
{ {
Name: prebindPluginName, Name: preBindPluginName,
Args: runtime.Unknown{}, Args: runtime.Unknown{},
}, },
} }
@@ -810,30 +810,30 @@ func TestUnreservePlugin(t *testing.T) {
} }
tests := []struct { tests := []struct {
prebindFail bool preBindFail bool
prebindReject bool preBindReject bool
}{ }{
{ {
prebindFail: false, preBindFail: false,
prebindReject: false, preBindReject: false,
}, },
{ {
prebindFail: true, preBindFail: true,
prebindReject: false, preBindReject: false,
}, },
{ {
prebindFail: false, preBindFail: false,
prebindReject: true, preBindReject: true,
}, },
{ {
prebindFail: true, preBindFail: true,
prebindReject: true, preBindReject: true,
}, },
} }
for i, test := range tests { for i, test := range tests {
prebindPlugin.failPrebind = test.prebindFail preBindPlugin.failPreBind = test.preBindFail
prebindPlugin.rejectPrebind = test.prebindReject preBindPlugin.rejectPreBind = test.preBindReject
// Create a best effort pod. // Create a best effort pod.
pod, err := createPausePod(cs, pod, err := createPausePod(cs,
@@ -842,20 +842,20 @@ func TestUnreservePlugin(t *testing.T) {
t.Errorf("Error while creating a test pod: %v", err) t.Errorf("Error while creating a test pod: %v", err)
} }
if test.prebindFail { if test.preBindFail {
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 unreservePlugin.numUnreserveCalled == 0 || unreservePlugin.numUnreserveCalled != prebindPlugin.numPrebindCalled { if unreservePlugin.numUnreserveCalled == 0 || unreservePlugin.numUnreserveCalled != preBindPlugin.numPreBindCalled {
t.Errorf("test #%v: Expected the unreserve plugin to be called %d times, was called %d times.", i, prebindPlugin.numPrebindCalled, unreservePlugin.numUnreserveCalled) t.Errorf("test #%v: Expected the unreserve plugin to be called %d times, was called %d times.", i, preBindPlugin.numPreBindCalled, unreservePlugin.numUnreserveCalled)
} }
} 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 unreservePlugin.numUnreserveCalled == 0 { if unreservePlugin.numUnreserveCalled == 0 {
t.Errorf("test #%v: Expected the unreserve plugin to be called %d times, was called %d times.", i, prebindPlugin.numPrebindCalled, unreservePlugin.numUnreserveCalled) t.Errorf("test #%v: Expected the unreserve plugin to be called %d times, was called %d times.", i, preBindPlugin.numPreBindCalled, unreservePlugin.numUnreserveCalled)
} }
} else { } else {
if err = waitForPodToSchedule(cs, pod); err != nil { if err = waitForPodToSchedule(cs, pod); err != nil {
@@ -868,7 +868,7 @@ func TestUnreservePlugin(t *testing.T) {
} }
unreservePlugin.reset() unreservePlugin.reset()
prebindPlugin.reset() preBindPlugin.reset()
cleanupPods(cs, t, []*v1.Pod{pod}) cleanupPods(cs, t, []*v1.Pod{pod})
} }
} }
@@ -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.
@@ -1080,14 +1080,14 @@ func TestPostbindPlugin(t *testing.T) {
PreBind: &schedulerconfig.PluginSet{ PreBind: &schedulerconfig.PluginSet{
Enabled: []schedulerconfig.Plugin{ Enabled: []schedulerconfig.Plugin{
{ {
Name: prebindPluginName, Name: preBindPluginName,
}, },
}, },
}, },
PostBind: &schedulerconfig.PluginSet{ PostBind: &schedulerconfig.PluginSet{
Enabled: []schedulerconfig.Plugin{ Enabled: []schedulerconfig.Plugin{
{ {
Name: postbindPluginName, Name: postBindPluginName,
}, },
}, },
}, },
@@ -1095,11 +1095,11 @@ func TestPostbindPlugin(t *testing.T) {
// Set reserve prebind and postbind config for testing // Set reserve prebind and postbind config for testing
pluginConfig := []schedulerconfig.PluginConfig{ pluginConfig := []schedulerconfig.PluginConfig{
{ {
Name: prebindPluginName, Name: preBindPluginName,
Args: runtime.Unknown{}, Args: runtime.Unknown{},
}, },
{ {
Name: postbindPluginName, Name: postBindPluginName,
Args: runtime.Unknown{}, Args: runtime.Unknown{},
}, },
} }
@@ -1118,30 +1118,30 @@ func TestPostbindPlugin(t *testing.T) {
} }
tests := []struct { tests := []struct {
prebindFail bool preBindFail bool
prebindReject bool preBindReject bool
}{ }{
{ {
prebindFail: false, preBindFail: false,
prebindReject: false, preBindReject: false,
}, },
{ {
prebindFail: true, preBindFail: true,
prebindReject: false, preBindReject: false,
}, },
{ {
prebindFail: false, preBindFail: false,
prebindReject: true, preBindReject: true,
}, },
{ {
prebindFail: true, preBindFail: true,
prebindReject: true, preBindReject: true,
}, },
} }
for i, test := range tests { for i, test := range tests {
prebindPlugin.failPrebind = test.prebindFail preBindPlugin.failPreBind = test.preBindFail
prebindPlugin.rejectPrebind = test.prebindReject preBindPlugin.rejectPreBind = test.preBindReject
// Create a best effort pod. // Create a best effort pod.
pod, err := createPausePod(cs, pod, err := createPausePod(cs,
@@ -1150,33 +1150,33 @@ func TestPostbindPlugin(t *testing.T) {
t.Errorf("Error while creating a test pod: %v", err) t.Errorf("Error while creating a test pod: %v", err)
} }
if test.prebindFail { if test.preBindFail {
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})
} }
} }