Merge pull request #83418 from ahg-g/ahg-first-priority
Refactor scheduler.New so that all framework-related parameters are options
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
scheduler "k8s.io/kubernetes/pkg/scheduler"
|
||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||
@@ -456,23 +457,13 @@ func TestPreFilterPlugin(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
// Set empty plugin config for testing
|
||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "prefilter-plugin", nil),
|
||||
false, nil, registry, plugins, emptyPluginConfig, time.Second)
|
||||
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "prefilter-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
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 {
|
||||
fail bool
|
||||
reject bool
|
||||
@@ -495,18 +486,18 @@ func TestPreFilterPlugin(t *testing.T) {
|
||||
preFilterPlugin.failPreFilter = test.fail
|
||||
preFilterPlugin.rejectPreFilter = test.reject
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
if err != nil {
|
||||
t.Errorf("Error while creating a test pod: %v", err)
|
||||
}
|
||||
|
||||
if test.reject || test.fail {
|
||||
if err = waitForPodUnschedulable(cs, pod); err != nil {
|
||||
if err = waitForPodUnschedulable(context.clientSet, pod); err != nil {
|
||||
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
} else {
|
||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
}
|
||||
@@ -516,7 +507,7 @@ func TestPreFilterPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
preFilterPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,27 +529,30 @@ func TestScorePlugin(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
context, cs := initTestContextForScorePlugin(t, plugins, registry)
|
||||
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "score-plugin", nil), 10,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
for i, fail := range []bool{false, true} {
|
||||
scorePlugin.failScore = fail
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
if err != nil {
|
||||
t.Fatalf("Error while creating a test pod: %v", err)
|
||||
}
|
||||
|
||||
if fail {
|
||||
if err = waitForPodUnschedulable(cs, pod); err != nil {
|
||||
if err = waitForPodUnschedulable(context.clientSet, pod); err != nil {
|
||||
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
} else {
|
||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||
} else {
|
||||
p, err := getPod(cs, pod.Name, pod.Namespace)
|
||||
p, err := getPod(context.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 {
|
||||
@@ -572,7 +566,7 @@ func TestScorePlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
scorePlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,17 +588,20 @@ func TestNormalizeScorePlugin(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
context, cs := initTestContextForScorePlugin(t, plugins, registry)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "score-plugin", nil), 10,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
if err != nil {
|
||||
t.Fatalf("Error while creating a test pod: %v", err)
|
||||
}
|
||||
|
||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||
}
|
||||
|
||||
@@ -634,37 +631,29 @@ func TestReservePlugin(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
// Set empty plugin config for testing
|
||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "reserve-plugin", nil),
|
||||
false, nil, registry, plugins, emptyPluginConfig, time.Second)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "reserve-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
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)
|
||||
}
|
||||
|
||||
for _, fail := range []bool{false, true} {
|
||||
reservePlugin.failReserve = fail
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.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(cs, pod.Namespace, pod.Name)); err != nil {
|
||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second,
|
||||
podSchedulingError(context.clientSet, pod.Namespace, pod.Name)); err != nil {
|
||||
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
||||
}
|
||||
} else {
|
||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -674,7 +663,7 @@ func TestReservePlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
reservePlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -702,18 +691,12 @@ func TestPrebindPlugin(t *testing.T) {
|
||||
},
|
||||
}
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "prebind-plugin", nil),
|
||||
false, nil, registry, plugins, preBindPluginConfig, time.Second)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "prebind-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkPluginConfig(preBindPluginConfig),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
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 {
|
||||
fail bool
|
||||
reject bool
|
||||
@@ -740,17 +723,17 @@ func TestPrebindPlugin(t *testing.T) {
|
||||
preBindPlugin.failPreBind = test.fail
|
||||
preBindPlugin.rejectPreBind = test.reject
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.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(cs, pod.Namespace, pod.Name)); err != nil {
|
||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.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(cs, pod); err != nil {
|
||||
} else if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
|
||||
@@ -759,7 +742,7 @@ func TestPrebindPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
preBindPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,18 +786,12 @@ func TestUnreservePlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "unreserve-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "unreserve-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
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
|
||||
}{
|
||||
@@ -830,21 +807,21 @@ func TestUnreservePlugin(t *testing.T) {
|
||||
preBindPlugin.failPreBind = test.preBindFail
|
||||
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &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 {
|
||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.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(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
if unreservePlugin.numUnreserveCalled > 0 {
|
||||
@@ -854,7 +831,7 @@ func TestUnreservePlugin(t *testing.T) {
|
||||
|
||||
unreservePlugin.reset()
|
||||
preBindPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -919,13 +896,14 @@ func TestBindPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t, testContext,
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
context := initTestSchedulerWithOptions(t, testContext, false, nil, time.Second,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
// Add a few nodes.
|
||||
_, err := createNodes(cs, "test-node", nil, 2)
|
||||
_, err := createNodes(context.clientSet, "test-node", nil, 2)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot create nodes: %v", err)
|
||||
}
|
||||
@@ -976,19 +954,19 @@ func TestBindPlugin(t *testing.T) {
|
||||
postBindPlugin.pluginInvokeEventChan = pluginInvokeEventChan
|
||||
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.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(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||
continue
|
||||
}
|
||||
pod, err = cs.CoreV1().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{})
|
||||
pod, err = context.clientSet.CoreV1().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("can't get pod: %v", err)
|
||||
}
|
||||
@@ -1021,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(cs, pod.Namespace, pod.Name)); err != nil {
|
||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.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 {
|
||||
@@ -1046,7 +1024,7 @@ func TestBindPlugin(t *testing.T) {
|
||||
bindPlugin1.reset()
|
||||
bindPlugin2.reset()
|
||||
unreservePlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1090,18 +1068,12 @@ func TestPostBindPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "postbind-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "postbind-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
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
|
||||
@@ -1118,21 +1090,21 @@ func TestPostBindPlugin(t *testing.T) {
|
||||
preBindPlugin.failPreBind = test.preBindFail
|
||||
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &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 {
|
||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.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(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
if postBindPlugin.numPostBindCalled == 0 {
|
||||
@@ -1142,7 +1114,7 @@ func TestPostBindPlugin(t *testing.T) {
|
||||
|
||||
postBindPlugin.reset()
|
||||
preBindPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1171,18 +1143,12 @@ func TestPermitPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "permit-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "permit-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
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 {
|
||||
fail bool
|
||||
reject bool
|
||||
@@ -1228,22 +1194,22 @@ func TestPermitPlugin(t *testing.T) {
|
||||
perPlugin.waitAndAllowPermit = false
|
||||
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.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(cs, pod.Namespace, pod.Name)); err != nil {
|
||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.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(cs, pod); err != nil {
|
||||
if err = waitForPodUnschedulable(context.clientSet, pod); err != nil {
|
||||
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
} else {
|
||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
}
|
||||
@@ -1254,7 +1220,7 @@ func TestPermitPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
perPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1283,18 +1249,12 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "permit-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "permit-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
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 {
|
||||
waitReject bool
|
||||
waitAllow bool
|
||||
@@ -1317,29 +1277,29 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
||||
permitPlugin.waitAndAllowPermit = test.waitAllow
|
||||
|
||||
// Create two pods.
|
||||
waitingPod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "waiting-pod", Namespace: context.ns.Name}))
|
||||
waitingPod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "waiting-pod", Namespace: context.ns.Name}))
|
||||
if err != nil {
|
||||
t.Errorf("Error while creating the waiting pod: %v", err)
|
||||
}
|
||||
signallingPod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "signalling-pod", Namespace: context.ns.Name}))
|
||||
signallingPod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "signalling-pod", Namespace: context.ns.Name}))
|
||||
if err != nil {
|
||||
t.Errorf("Error while creating the signalling pod: %v", err)
|
||||
}
|
||||
|
||||
if test.waitReject {
|
||||
if err = waitForPodUnschedulable(cs, waitingPod); err != nil {
|
||||
if err = waitForPodUnschedulable(context.clientSet, waitingPod); err != nil {
|
||||
t.Errorf("test #%v: Didn't expect the waiting pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
if err = waitForPodUnschedulable(cs, signallingPod); err != nil {
|
||||
if err = waitForPodUnschedulable(context.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(cs, waitingPod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, waitingPod); err != nil {
|
||||
t.Errorf("test #%v: Expected the waiting pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
if err = waitForPodToSchedule(cs, signallingPod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, signallingPod); err != nil {
|
||||
t.Errorf("test #%v: Expected the signalling pod to be scheduled. error: %v", i, err)
|
||||
}
|
||||
}
|
||||
@@ -1349,7 +1309,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
permitPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{waitingPod, signallingPod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{waitingPod, signallingPod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1360,7 +1320,7 @@ func TestFilterPlugin(t *testing.T) {
|
||||
registry := framework.Registry{filterPluginName: newPlugin(filterPlugin)}
|
||||
|
||||
// Setup initial filter plugin for testing.
|
||||
plugin := &schedulerconfig.Plugins{
|
||||
plugins := &schedulerconfig.Plugins{
|
||||
Filter: &schedulerconfig.PluginSet{
|
||||
Enabled: []schedulerconfig.Plugin{
|
||||
{
|
||||
@@ -1369,37 +1329,28 @@ func TestFilterPlugin(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
// Set empty plugin config for testing
|
||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "filter-plugin", nil),
|
||||
false, nil, registry, plugin, emptyPluginConfig, time.Second)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "filter-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
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)
|
||||
}
|
||||
|
||||
for _, fail := range []bool{false, true} {
|
||||
filterPlugin.failFilter = fail
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.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(cs, pod.Namespace, pod.Name)); err != nil {
|
||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podUnschedulable(context.clientSet, pod.Namespace, pod.Name)); err != nil {
|
||||
t.Errorf("Didn't expect the pod to be scheduled.")
|
||||
}
|
||||
} else {
|
||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -1409,7 +1360,7 @@ func TestFilterPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
filterPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1420,7 +1371,7 @@ func TestPostFilterPlugin(t *testing.T) {
|
||||
registry := framework.Registry{postFilterPluginName: newPlugin(postFilterPlugin)}
|
||||
|
||||
// Setup initial post-filter plugin for testing.
|
||||
pluginsConfig := &schedulerconfig.Plugins{
|
||||
plugins := &schedulerconfig.Plugins{
|
||||
PostFilter: &schedulerconfig.PluginSet{
|
||||
Enabled: []schedulerconfig.Plugin{
|
||||
{
|
||||
@@ -1429,37 +1380,28 @@ func TestPostFilterPlugin(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
// Set empty plugin config for testing
|
||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "post-filter-plugin", nil),
|
||||
false, nil, registry, pluginsConfig, emptyPluginConfig, time.Second)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "post-filter-plugin", nil), 2,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
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)
|
||||
}
|
||||
|
||||
for _, fail := range []bool{false, true} {
|
||||
postFilterPlugin.failPostFilter = fail
|
||||
// Create a best effort pod.
|
||||
pod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
pod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||
if err != nil {
|
||||
t.Errorf("Error while creating a test pod: %v", err)
|
||||
}
|
||||
|
||||
if fail {
|
||||
if err = waitForPodUnschedulable(cs, pod); err != nil {
|
||||
if err = waitForPodUnschedulable(context.clientSet, pod); err != nil {
|
||||
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
||||
}
|
||||
} else {
|
||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -1469,7 +1411,7 @@ func TestPostFilterPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
postFilterPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1498,19 +1440,19 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "preempt-with-permit-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "preempt-with-permit-plugin", nil), 0,
|
||||
scheduler.WithFrameworkPlugins(plugins),
|
||||
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||
scheduler.WithFrameworkRegistry(registry))
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
// Add one node.
|
||||
nodeRes := &v1.ResourceList{
|
||||
v1.ResourcePods: *resource.NewQuantity(32, resource.DecimalSI),
|
||||
v1.ResourceCPU: *resource.NewMilliQuantity(500, resource.DecimalSI),
|
||||
v1.ResourceMemory: *resource.NewQuantity(500, resource.DecimalSI),
|
||||
}
|
||||
_, err := createNodes(cs, "test-node", nodeRes, 1)
|
||||
_, err := createNodes(context.clientSet, "test-node", nodeRes, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot create nodes: %v", err)
|
||||
}
|
||||
@@ -1529,9 +1471,9 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create two pods.
|
||||
waitingPod := initPausePod(cs, &pausePodConfig{Name: "waiting-pod", Namespace: context.ns.Name, Priority: &lowPriority, Resources: &resourceRequest})
|
||||
waitingPod := initPausePod(context.clientSet, &pausePodConfig{Name: "waiting-pod", Namespace: context.ns.Name, Priority: &lowPriority, Resources: &resourceRequest})
|
||||
waitingPod.Spec.TerminationGracePeriodSeconds = new(int64)
|
||||
waitingPod, err = createPausePod(cs, waitingPod)
|
||||
waitingPod, err = createPausePod(context.clientSet, waitingPod)
|
||||
if err != nil {
|
||||
t.Errorf("Error while creating the waiting pod: %v", err)
|
||||
}
|
||||
@@ -1542,17 +1484,17 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
|
||||
return w, nil
|
||||
})
|
||||
|
||||
preemptorPod, err := createPausePod(cs,
|
||||
initPausePod(cs, &pausePodConfig{Name: "preemptor-pod", Namespace: context.ns.Name, Priority: &highPriority, Resources: &resourceRequest}))
|
||||
preemptorPod, err := createPausePod(context.clientSet,
|
||||
initPausePod(context.clientSet, &pausePodConfig{Name: "preemptor-pod", Namespace: context.ns.Name, Priority: &highPriority, Resources: &resourceRequest}))
|
||||
if err != nil {
|
||||
t.Errorf("Error while creating the preemptor pod: %v", err)
|
||||
}
|
||||
|
||||
if err = waitForPodToSchedule(cs, preemptorPod); err != nil {
|
||||
if err = waitForPodToSchedule(context.clientSet, preemptorPod); err != nil {
|
||||
t.Errorf("Expected the preemptor pod to be scheduled. error: %v", err)
|
||||
}
|
||||
|
||||
if _, err := getPod(cs, waitingPod.Name, waitingPod.Namespace); err == nil {
|
||||
if _, err := getPod(context.clientSet, waitingPod.Name, waitingPod.Namespace); err == nil {
|
||||
t.Error("Expected the waiting pod to get preempted and deleted")
|
||||
}
|
||||
|
||||
@@ -1561,22 +1503,17 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
permitPlugin.reset()
|
||||
cleanupPods(cs, t, []*v1.Pod{waitingPod, preemptorPod})
|
||||
cleanupPods(context.clientSet, t, []*v1.Pod{waitingPod, preemptorPod})
|
||||
}
|
||||
|
||||
func initTestContextForScorePlugin(t *testing.T, plugins *schedulerconfig.Plugins, registry framework.Registry) (*testContext, *clientset.Clientset) {
|
||||
// Set empty plugin config for testing
|
||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "score-plugin", nil),
|
||||
false, nil, registry, plugins, emptyPluginConfig, time.Second)
|
||||
|
||||
cs := context.clientSet
|
||||
_, err := createNodes(cs, "test-node", nil, 10)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot create nodes: %v", err)
|
||||
func initTestSchedulerForFrameworkTest(t *testing.T, context *testContext, nodeCount int, opts ...scheduler.Option) *testContext {
|
||||
opts = append(opts, scheduler.WithFrameworkConfigProducerRegistry(nil))
|
||||
c := initTestSchedulerWithOptions(t, context, false, nil, time.Second, opts...)
|
||||
if nodeCount > 0 {
|
||||
_, err := createNodes(c.clientSet, "test-node", nil, nodeCount)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot create nodes: %v", err)
|
||||
}
|
||||
}
|
||||
return context, cs
|
||||
return c
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user