Refactor: move generic functions of integration test to util directory

This commit is contained in:
fengzixu
2020-02-29 14:56:39 +09:00
parent b378b17560
commit b67a033de2
12 changed files with 754 additions and 707 deletions

View File

@@ -33,6 +33,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
testutils "k8s.io/kubernetes/test/integration/util"
)
type PreFilterPlugin struct {
@@ -482,10 +483,10 @@ func TestPreFilterPlugin(t *testing.T) {
}
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "prefilter-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "prefilter-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
fail bool
@@ -509,18 +510,18 @@ func TestPreFilterPlugin(t *testing.T) {
preFilterPlugin.failPreFilter = test.fail
preFilterPlugin.rejectPreFilter = test.reject
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
if test.reject || test.fail {
if err = waitForPodUnschedulable(testCtx.clientSet, pod); err != nil {
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
}
} else {
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
}
}
@@ -530,7 +531,7 @@ func TestPreFilterPlugin(t *testing.T) {
}
preFilterPlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -553,29 +554,29 @@ func TestScorePlugin(t *testing.T) {
},
}
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "score-plugin", nil), 10,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "score-plugin", nil), 10,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
for i, fail := range []bool{false, true} {
scorePlugin.failScore = fail
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Fatalf("Error while creating a test pod: %v", err)
}
if fail {
if err = waitForPodUnschedulable(testCtx.clientSet, pod); err != nil {
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
}
} else {
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err)
} else {
p, err := getPod(testCtx.clientSet, pod.Name, pod.Namespace)
p, err := getPod(testCtx.ClientSet, pod.Name, pod.Namespace)
if err != nil {
t.Errorf("Failed to retrieve the pod. error: %v", err)
} else if p.Spec.NodeName != scorePlugin.highScoreNode {
@@ -589,7 +590,7 @@ func TestScorePlugin(t *testing.T) {
}
scorePlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -612,20 +613,20 @@ func TestNormalizeScorePlugin(t *testing.T) {
},
},
}
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "score-plugin", nil), 10,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "score-plugin", nil), 10,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Fatalf("Error while creating a test pod: %v", err)
}
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err)
}
@@ -660,27 +661,27 @@ func TestReservePlugin(t *testing.T) {
}
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "reserve-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "reserve-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
for _, fail := range []bool{false, true} {
reservePlugin.failReserve = fail
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
if fail {
if err = wait.Poll(10*time.Millisecond, 30*time.Second,
podSchedulingError(testCtx.clientSet, pod.Namespace, pod.Name)); err != nil {
podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
}
} else {
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err)
}
}
@@ -690,7 +691,7 @@ func TestReservePlugin(t *testing.T) {
}
reservePlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -715,10 +716,10 @@ func TestPrebindPlugin(t *testing.T) {
}
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "prebind-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "prebind-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
fail bool
@@ -746,17 +747,17 @@ func TestPrebindPlugin(t *testing.T) {
preBindPlugin.failPreBind = test.fail
preBindPlugin.rejectPreBind = test.reject
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
if test.fail || test.reject {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.clientSet, pod.Namespace, pod.Name)); err != nil {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
}
} else if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
} else if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
}
@@ -765,7 +766,7 @@ func TestPrebindPlugin(t *testing.T) {
}
preBindPlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -801,10 +802,10 @@ func TestUnreservePlugin(t *testing.T) {
}
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "unreserve-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "unreserve-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
preBindFail bool
@@ -821,21 +822,21 @@ func TestUnreservePlugin(t *testing.T) {
preBindPlugin.failPreBind = test.preBindFail
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.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(testCtx.clientSet, pod.Namespace, pod.Name)); err != nil {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
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 {
t.Errorf("test #%v: Expected the unreserve plugin to be called %d times, was called %d times.", i, preBindPlugin.numPreBindCalled, unreservePlugin.numUnreserveCalled)
}
} else {
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
}
if unreservePlugin.numUnreserveCalled > 0 {
@@ -845,7 +846,7 @@ func TestUnreservePlugin(t *testing.T) {
unreservePlugin.reset()
preBindPlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -856,9 +857,9 @@ type pluginInvokeEvent struct {
// TestBindPlugin tests invocation of bind plugins.
func TestBindPlugin(t *testing.T) {
testContext := initTestMaster(t, "bind-plugin", nil)
bindPlugin1 := &BindPlugin{PluginName: "bind-plugin-1", client: testContext.clientSet}
bindPlugin2 := &BindPlugin{PluginName: "bind-plugin-2", client: testContext.clientSet}
testContext := testutils.InitTestMaster(t, "bind-plugin", nil)
bindPlugin1 := &BindPlugin{PluginName: "bind-plugin-1", client: testContext.ClientSet}
bindPlugin2 := &BindPlugin{PluginName: "bind-plugin-2", client: testContext.ClientSet}
unreservePlugin := &UnreservePlugin{name: "mock-unreserve-plugin"}
postBindPlugin := &PostBindPlugin{name: "mock-post-bind-plugin"}
// Create a plugin registry for testing. Register an unreserve, a bind plugin and a postBind plugin.
@@ -896,13 +897,13 @@ func TestBindPlugin(t *testing.T) {
}
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerWithOptions(t, testContext, false, nil, time.Second,
testCtx := testutils.InitTestSchedulerWithOptions(t, testContext, false, nil, time.Second,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
// Add a few nodes.
_, err := createNodes(testCtx.clientSet, "test-node", nil, 2)
_, err := createNodes(testCtx.ClientSet, "test-node", nil, 2)
if err != nil {
t.Fatalf("Cannot create nodes: %v", err)
}
@@ -953,19 +954,19 @@ func TestBindPlugin(t *testing.T) {
postBindPlugin.pluginInvokeEventChan = pluginInvokeEventChan
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
if test.expectBoundByScheduler || test.expectBoundByPlugin {
// bind plugins skipped to bind the pod
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
continue
}
pod, err = testCtx.clientSet.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{})
pod, err = testCtx.ClientSet.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{})
if err != nil {
t.Errorf("can't get pod: %v", err)
}
@@ -998,7 +999,7 @@ func TestBindPlugin(t *testing.T) {
}
} else {
// bind plugin fails to bind the pod
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.clientSet, pod.Namespace, pod.Name)); err != nil {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
}
if postBindPlugin.numPostBindCalled > 0 {
@@ -1023,7 +1024,7 @@ func TestBindPlugin(t *testing.T) {
bindPlugin1.reset()
bindPlugin2.reset()
unreservePlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -1059,10 +1060,10 @@ func TestPostBindPlugin(t *testing.T) {
}
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "postbind-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "postbind-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
preBindFail bool
@@ -1080,21 +1081,21 @@ func TestPostBindPlugin(t *testing.T) {
preBindPlugin.failPreBind = test.preBindFail
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.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(testCtx.clientSet, pod.Namespace, pod.Name)); err != nil {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
}
if postBindPlugin.numPostBindCalled > 0 {
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
}
} else {
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
}
if postBindPlugin.numPostBindCalled == 0 {
@@ -1104,7 +1105,7 @@ func TestPostBindPlugin(t *testing.T) {
postBindPlugin.reset()
preBindPlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -1115,10 +1116,10 @@ func TestPermitPlugin(t *testing.T) {
registry, prof := initRegistryAndConfig(perPlugin)
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "permit-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "permit-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
fail bool
@@ -1165,22 +1166,22 @@ func TestPermitPlugin(t *testing.T) {
perPlugin.waitAndAllowPermit = false
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
if test.fail {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.clientSet, pod.Namespace, pod.Name)); err != nil {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
}
} else {
if test.reject || test.timeout {
if err = waitForPodUnschedulable(testCtx.clientSet, pod); err != nil {
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
}
} else {
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
}
}
@@ -1191,7 +1192,7 @@ func TestPermitPlugin(t *testing.T) {
}
perPlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -1203,10 +1204,10 @@ func TestMultiplePermitPlugins(t *testing.T) {
registry, prof := initRegistryAndConfig(perPlugin1, perPlugin2)
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "multi-permit-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "multi-permit-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
// Both permit plugins will return Wait for permitting
perPlugin1.timeoutPermit = true
@@ -1214,8 +1215,8 @@ func TestMultiplePermitPlugins(t *testing.T) {
// Create a test pod.
podName := "test-pod"
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: podName, Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: podName, Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
@@ -1239,7 +1240,7 @@ func TestMultiplePermitPlugins(t *testing.T) {
}
perPlugin2.allowAllPods()
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err)
}
@@ -1247,7 +1248,7 @@ func TestMultiplePermitPlugins(t *testing.T) {
t.Errorf("Expected the permit plugin to be called.")
}
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
// TestPermitPluginsCancelled tests whether all permit plugins are cancelled when pod is rejected.
@@ -1258,10 +1259,10 @@ func TestPermitPluginsCancelled(t *testing.T) {
registry, prof := initRegistryAndConfig(perPlugin1, perPlugin2)
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "permit-plugins", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "permit-plugins", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
// Both permit plugins will return Wait for permitting
perPlugin1.timeoutPermit = true
@@ -1269,8 +1270,8 @@ func TestPermitPluginsCancelled(t *testing.T) {
// Create a test pod.
podName := "test-pod"
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: podName, Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: podName, Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
@@ -1299,10 +1300,10 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
registry, prof := initRegistryAndConfig(permitPlugin)
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "permit-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "permit-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
waitReject bool
@@ -1326,29 +1327,29 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
permitPlugin.waitAndAllowPermit = test.waitAllow
// Create two pods.
waitingPod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "waiting-pod", Namespace: testCtx.ns.Name}))
waitingPod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "waiting-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating the waiting pod: %v", err)
}
signallingPod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "signalling-pod", Namespace: testCtx.ns.Name}))
signallingPod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "signalling-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating the signalling pod: %v", err)
}
if test.waitReject {
if err = waitForPodUnschedulable(testCtx.clientSet, waitingPod); err != nil {
if err = waitForPodUnschedulable(testCtx.ClientSet, waitingPod); err != nil {
t.Errorf("test #%v: Didn't expect the waiting pod to be scheduled. error: %v", i, err)
}
if err = waitForPodUnschedulable(testCtx.clientSet, signallingPod); err != nil {
if err = waitForPodUnschedulable(testCtx.ClientSet, signallingPod); err != nil {
t.Errorf("test #%v: Didn't expect the signalling pod to be scheduled. error: %v", i, err)
}
} else {
if err = waitForPodToSchedule(testCtx.clientSet, waitingPod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, waitingPod); err != nil {
t.Errorf("test #%v: Expected the waiting pod to be scheduled. error: %v", i, err)
}
if err = waitForPodToSchedule(testCtx.clientSet, signallingPod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, signallingPod); err != nil {
t.Errorf("test #%v: Expected the signalling pod to be scheduled. error: %v", i, err)
}
}
@@ -1358,7 +1359,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
}
permitPlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{waitingPod, signallingPod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{waitingPod, signallingPod})
}
}
@@ -1383,26 +1384,26 @@ func TestFilterPlugin(t *testing.T) {
}
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "filter-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "filter-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
for _, fail := range []bool{false, true} {
filterPlugin.failFilter = fail
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
if fail {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podUnschedulable(testCtx.clientSet, pod.Namespace, pod.Name)); err != nil {
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podUnschedulable(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
t.Errorf("Didn't expect the pod to be scheduled.")
}
} else {
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err)
}
}
@@ -1412,7 +1413,7 @@ func TestFilterPlugin(t *testing.T) {
}
filterPlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -1437,26 +1438,26 @@ func TestPreScorePlugin(t *testing.T) {
}
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "pre-score-plugin", nil), 2,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "pre-score-plugin", nil), 2,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
for _, fail := range []bool{false, true} {
preScorePlugin.failPreScore = fail
// Create a best effort pod.
pod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.ns.Name}))
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
if err != nil {
t.Errorf("Error while creating a test pod: %v", err)
}
if fail {
if err = waitForPodUnschedulable(testCtx.clientSet, pod); err != nil {
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
}
} else {
if err = waitForPodToSchedule(testCtx.clientSet, pod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err)
}
}
@@ -1466,7 +1467,7 @@ func TestPreScorePlugin(t *testing.T) {
}
preScorePlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{pod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
}
}
@@ -1477,10 +1478,10 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
registry, prof := initRegistryAndConfig(permitPlugin)
// Create the master and the scheduler with the test plugin set.
testCtx := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "preempt-with-permit-plugin", nil), 0,
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "preempt-with-permit-plugin", nil), 0,
scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer cleanupTest(t, testCtx)
defer testutils.CleanupTest(t, testCtx)
// Add one node.
nodeRes := &v1.ResourceList{
@@ -1488,7 +1489,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
v1.ResourceCPU: *resource.NewMilliQuantity(500, resource.DecimalSI),
v1.ResourceMemory: *resource.NewQuantity(500, resource.DecimalSI),
}
_, err := createNodes(testCtx.clientSet, "test-node", nodeRes, 1)
_, err := createNodes(testCtx.ClientSet, "test-node", nodeRes, 1)
if err != nil {
t.Fatalf("Cannot create nodes: %v", err)
}
@@ -1507,9 +1508,9 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
}
// Create two pods.
waitingPod := initPausePod(testCtx.clientSet, &pausePodConfig{Name: "waiting-pod", Namespace: testCtx.ns.Name, Priority: &lowPriority, Resources: &resourceRequest})
waitingPod := initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "waiting-pod", Namespace: testCtx.NS.Name, Priority: &lowPriority, Resources: &resourceRequest})
waitingPod.Spec.TerminationGracePeriodSeconds = new(int64)
waitingPod, err = createPausePod(testCtx.clientSet, waitingPod)
waitingPod, err = createPausePod(testCtx.ClientSet, waitingPod)
if err != nil {
t.Errorf("Error while creating the waiting pod: %v", err)
}
@@ -1520,17 +1521,17 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
return w, nil
})
preemptorPod, err := createPausePod(testCtx.clientSet,
initPausePod(testCtx.clientSet, &pausePodConfig{Name: "preemptor-pod", Namespace: testCtx.ns.Name, Priority: &highPriority, Resources: &resourceRequest}))
preemptorPod, err := createPausePod(testCtx.ClientSet,
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "preemptor-pod", Namespace: testCtx.NS.Name, Priority: &highPriority, Resources: &resourceRequest}))
if err != nil {
t.Errorf("Error while creating the preemptor pod: %v", err)
}
if err = waitForPodToSchedule(testCtx.clientSet, preemptorPod); err != nil {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, preemptorPod); err != nil {
t.Errorf("Expected the preemptor pod to be scheduled. error: %v", err)
}
if _, err := getPod(testCtx.clientSet, waitingPod.Name, waitingPod.Namespace); err == nil {
if _, err := getPod(testCtx.ClientSet, waitingPod.Name, waitingPod.Namespace); err == nil {
t.Error("Expected the waiting pod to get preempted and deleted")
}
@@ -1539,13 +1540,13 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
}
permitPlugin.reset()
cleanupPods(testCtx.clientSet, t, []*v1.Pod{waitingPod, preemptorPod})
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{waitingPod, preemptorPod})
}
func initTestSchedulerForFrameworkTest(t *testing.T, testCtx *testContext, nodeCount int, opts ...scheduler.Option) *testContext {
c := initTestSchedulerWithOptions(t, testCtx, false, nil, time.Second, opts...)
func initTestSchedulerForFrameworkTest(t *testing.T, testCtx *testutils.TestContext, nodeCount int, opts ...scheduler.Option) *testutils.TestContext {
c := testutils.InitTestSchedulerWithOptions(t, testCtx, false, nil, time.Second, opts...)
if nodeCount > 0 {
_, err := createNodes(c.clientSet, "test-node", nil, nodeCount)
_, err := createNodes(c.ClientSet, "test-node", nil, nodeCount)
if err != nil {
t.Fatalf("Cannot create nodes: %v", err)
}