mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
feat: use PreBind instead of Prebind in the scheduling framework
This commit is contained in:
parent
03f0934c80
commit
af2e0428f6
@ -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")
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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++
|
||||||
|
@ -45,7 +45,7 @@ type framework struct {
|
|||||||
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
|
||||||
@ -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)
|
||||||
}
|
}
|
||||||
@ -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())
|
||||||
|
@ -225,13 +225,13 @@ 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.
|
||||||
@ -311,12 +311,12 @@ 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)
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
@ -107,7 +107,7 @@ 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"
|
||||||
@ -120,7 +120,7 @@ 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{})
|
||||||
@ -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"
|
||||||
@ -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})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1068,10 +1068,10 @@ 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),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1080,7 +1080,7 @@ func TestPostBindPlugin(t *testing.T) {
|
|||||||
PreBind: &schedulerconfig.PluginSet{
|
PreBind: &schedulerconfig.PluginSet{
|
||||||
Enabled: []schedulerconfig.Plugin{
|
Enabled: []schedulerconfig.Plugin{
|
||||||
{
|
{
|
||||||
Name: prebindPluginName,
|
Name: preBindPluginName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1095,7 +1095,7 @@ 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{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -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,7 +1150,7 @@ 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)
|
||||||
}
|
}
|
||||||
@ -1158,7 +1158,7 @@ func TestPostBindPlugin(t *testing.T) {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
@ -1176,7 +1176,7 @@ func TestPostBindPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
postBindPlugin.reset()
|
postBindPlugin.reset()
|
||||||
prebindPlugin.reset()
|
preBindPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user