Revert "Add Un-reserve extension point for the scheduling framework"

This reverts commit 8b5182581a.
This commit is contained in:
Han Kang
2019-05-07 21:17:29 -07:00
parent 7673b2d161
commit 51992d61a0
4 changed files with 11 additions and 159 deletions

View File

@@ -18,11 +18,11 @@ package scheduler
import (
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"testing"
"time"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
)
@@ -30,12 +30,11 @@ import (
// TesterPlugin is common ancestor for a test plugin that allows injection of
// failures and some other test functionalities.
type TesterPlugin struct {
numReserveCalled int
numPrebindCalled int
numUnreserveCalled int
failReserve bool
failPrebind bool
rejectPrebind bool
numReserveCalled int
numPrebindCalled int
failReserve bool
failPrebind bool
rejectPrebind bool
}
type ReservePlugin struct {
@@ -46,27 +45,19 @@ type PrebindPlugin struct {
TesterPlugin
}
type UnreservePlugin struct {
TesterPlugin
}
const (
reservePluginName = "reserve-plugin"
prebindPluginName = "prebind-plugin"
unreservePluginName = "unreserve-plugin"
reservePluginName = "reserve-plugin"
prebindPluginName = "prebind-plugin"
)
var _ = framework.ReservePlugin(&ReservePlugin{})
var _ = framework.PrebindPlugin(&PrebindPlugin{})
var _ = framework.UnreservePlugin(&UnreservePlugin{})
// Name returns name of the plugin.
func (rp *ReservePlugin) Name() string {
return reservePluginName
}
var resPlugin = &ReservePlugin{}
// Reserve is a test function that returns an error or nil, depending on the
// value of "failReserve".
func (rp *ReservePlugin) Reserve(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
@@ -77,13 +68,14 @@ func (rp *ReservePlugin) Reserve(pc *framework.PluginContext, pod *v1.Pod, nodeN
return nil
}
var resPlugin = &ReservePlugin{}
var pbdPlugin = &PrebindPlugin{}
// NewReservePlugin is the factory for reserve plugin.
func NewReservePlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return resPlugin, nil
}
var pbdPlugin = &PrebindPlugin{}
// Name returns name of the plugin.
func (pp *PrebindPlugin) Name() string {
return prebindPluginName
@@ -106,29 +98,6 @@ func NewPrebindPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framewor
return pbdPlugin, nil
}
var unresPlugin = &UnreservePlugin{}
// Name returns name of the plugin.
func (up *UnreservePlugin) Name() string {
return unreservePluginName
}
// Unreserve is a test function that returns an error or nil, depending on the
// value of "failUnreserve".
func (up *UnreservePlugin) Unreserve(pc *framework.PluginContext, pod *v1.Pod, nodeName string) {
up.numUnreserveCalled++
}
// reset used to reset numUnreserveCalled.
func (up *UnreservePlugin) reset() {
up.numUnreserveCalled = 0
}
// NewUnreservePlugin is the factory for unreserve plugin.
func NewUnreservePlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return unresPlugin, nil
}
// TestReservePlugin tests invocation of reserve plugins.
func TestReservePlugin(t *testing.T) {
// Create a plugin registry for testing. Register only a reserve plugin.
@@ -247,86 +216,3 @@ func TestPrebindPlugin(t *testing.T) {
cleanupPods(cs, t, []*v1.Pod{pod})
}
}
// TestUnreservePlugin tests invocation of un-reserve plugin
func TestUnreservePlugin(t *testing.T) {
// TODO: register more plugin which would trigger un-reserve plugin
registry := framework.Registry{
unreservePluginName: NewUnreservePlugin,
prebindPluginName: NewPrebindPlugin,
}
// Create the master and the scheduler with the test plugin set.
context := initTestSchedulerWithOptions(t,
initTestMaster(t, "unreserve-plugin", nil),
false, nil, registry, false, time.Second)
defer cleanupTest(t, context)
cs := context.clientSet
// Add a few nodes.
_, err := createNodes(cs, "test-node", nil, 2)
if err != nil {
t.Fatalf("Cannot create nodes: %v", err)
}
tests := []struct {
prebindFail bool
prebindReject bool
}{
{
prebindFail: false,
prebindReject: false,
},
{
prebindFail: true,
prebindReject: false,
},
{
prebindFail: false,
prebindReject: true,
},
{
prebindFail: true,
prebindReject: true,
},
}
for i, test := range tests {
pbdPlugin.failPrebind = test.prebindFail
pbdPlugin.rejectPrebind = test.prebindReject
// Create a best effort pod.
pod, err := createPausePod(cs,
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
if test.prebindFail {
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)
}
if unresPlugin.numUnreserveCalled != 1 {
t.Errorf("test #%v: Expected the unreserve plugin to be called only once.", i)
}
} else {
if test.prebindReject {
if err = waitForPodUnschedulable(cs, pod); err != nil {
t.Errorf("test #%v: Didn't expected the pod to be scheduled. error: %v", i, err)
}
if unresPlugin.numUnreserveCalled != 1 {
t.Errorf("test #%v: Expected the unreserve plugin to be called only once.", i)
}
} else {
if err = waitForPodToSchedule(cs, pod); err != nil {
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
}
if unresPlugin.numUnreserveCalled > 0 {
t.Errorf("test #%v: Didn't expected the unreserve plugin to be called.", i)
}
}
}
unresPlugin.reset()
cleanupPods(cs, t, []*v1.Pod{pod})
}
}