diff --git a/docs/development/development.md b/docs/development/development.md index 490023b33c..8c88df7d24 100644 --- a/docs/development/development.md +++ b/docs/development/development.md @@ -118,7 +118,7 @@ make e2e-test-kind If you want to run e2e test in a existing cluster with volcano deployed, run the following: ```bash -export VK_BIN= need to set vcctl binary path (eg:.../src/volcano.sh/volcano/_output/bin/) +export VC_BIN= need to set vcctl binary path (eg:.../src/volcano.sh/volcano/_output/bin/) KUBECONFIG=${KUBECONFIG} go test ./test/e2e ``` diff --git a/hack/run-e2e-kind.sh b/hack/run-e2e-kind.sh index 80c38feac4..530b89a2a3 100755 --- a/hack/run-e2e-kind.sh +++ b/hack/run-e2e-kind.sh @@ -1,7 +1,7 @@ #!/bin/bash export VK_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.. -export VK_BIN=${VK_ROOT}/${BIN_DIR}/${BIN_OSARCH} +export VC_BIN=${VK_ROOT}/${BIN_DIR}/${BIN_OSARCH} export LOG_LEVEL=3 export SHOW_VOLCANO_LOGS=${SHOW_VOLCANO_LOGS:-1} export CLEANUP_CLUSTER=${CLEANUP_CLUSTER:-1} diff --git a/test/e2e/admission.go b/test/e2e/admission.go index a6a631935c..02531eecb7 100644 --- a/test/e2e/admission.go +++ b/test/e2e/admission.go @@ -34,7 +34,7 @@ var _ = Describe("Job E2E Test: Test Admission service", func() { It("Default queue would be added", func() { jobName := "job-default-queue" namespace := "test" - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) _, err := createJobInner(context, &jobSpec{ @@ -60,7 +60,7 @@ var _ = Describe("Job E2E Test: Test Admission service", func() { It("Invalid CPU unit", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) namespace := "test" @@ -109,7 +109,7 @@ var _ = Describe("Job E2E Test: Test Admission service", func() { It("Invalid memory unit", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) namespace := "test" @@ -160,7 +160,7 @@ var _ = Describe("Job E2E Test: Test Admission service", func() { It("Create default-scheduler pod", func() { podName := "pod-default-scheduler" namespace := "test" - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) pod := &corev1.Pod{ @@ -188,7 +188,7 @@ var _ = Describe("Job E2E Test: Test Admission service", func() { podName := "pod-volcano" pgName := "pending-pg" namespace := "test" - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) pg := &schedulingv1alpha2.PodGroup{ diff --git a/test/e2e/cli_util.go b/test/e2e/cli_util.go index cc69af6eb5..b4d8bd3b6e 100644 --- a/test/e2e/cli_util.go +++ b/test/e2e/cli_util.go @@ -72,7 +72,10 @@ func RunCliCommand(command []string) string { command = append(command, "--master", masterURL()) } command = append(command, "--kubeconfig", kubeconfigPath(homeDir())) - output, err := exec.Command(VolcanoCliBinary(), command...).Output() + vcctl := VolcanoCliBinary() + Expect(fileExist(vcctl)).To(BeTrue(), fmt.Sprintf( + "vcctl binary: %s is required for E2E tests, please update VC_BIN environment", vcctl)) + output, err := exec.Command(vcctl, command...).Output() Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Command %s failed to execute: %s", strings.Join(command, ""), err)) return string(output) @@ -83,8 +86,10 @@ func RunCliCommandWithoutKubeConfig(command []string) string { if masterURL() != "" { command = append(command, "--master", masterURL()) } - - output, err := exec.Command(VolcanoCliBinary(), command...).Output() + vcctl := VolcanoCliBinary() + Expect(fileExist(vcctl)).To(BeTrue(), fmt.Sprintf( + "vcctl binary: %s is required for E2E tests, please update VC_BIN environment", vcctl)) + output, err := exec.Command(vcctl, command...).Output() Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Command %s failed to execute: %s", strings.Join(command, ""), err)) return string(output) diff --git a/test/e2e/command.go b/test/e2e/command.go index aee135e681..8c5755f742 100644 --- a/test/e2e/command.go +++ b/test/e2e/command.go @@ -36,7 +36,7 @@ var _ = Describe("Job E2E Test: Test Job Command", func() { var outBuffer bytes.Buffer jobName := "test-job" namespace := "test" - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) @@ -70,7 +70,7 @@ var _ = Describe("Job E2E Test: Test Job Command", func() { jobName := "test-suspend-running-job" taskName := "long-live-task" namespace := "test" - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) job := createJob(context, &jobSpec{ @@ -113,7 +113,7 @@ var _ = Describe("Job E2E Test: Test Job Command", func() { }) It("Suspend pending job", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) @@ -157,7 +157,7 @@ var _ = Describe("Job E2E Test: Test Job Command", func() { jobName := "test-del-job" namespace := "test" - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) diff --git a/test/e2e/job_controlled_resource.go b/test/e2e/job_controlled_resource.go index c19e01755c..9f1d094eae 100644 --- a/test/e2e/job_controlled_resource.go +++ b/test/e2e/job_controlled_resource.go @@ -32,7 +32,7 @@ var _ = Describe("Job E2E Test: Test Job PVCs", func() { taskName := "pvctask" pvName := "job-pv-name" pvcName := "job-pvc-name-exist" - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) var tt v12.HostPathType @@ -136,7 +136,7 @@ var _ = Describe("Job E2E Test: Test Job PVCs", func() { It("Generate PodGroup and valid minResource when creating job", func() { jobName := "job-name-podgroup" namespace := "test" - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) resource := v12.ResourceList{ diff --git a/test/e2e/job_error_handling.go b/test/e2e/job_error_handling.go index 7bc72c1837..7be56559f4 100644 --- a/test/e2e/job_error_handling.go +++ b/test/e2e/job_error_handling.go @@ -17,9 +17,10 @@ limitations under the License. package e2e import ( + "strconv" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "strconv" "k8s.io/api/core/v1" @@ -31,7 +32,7 @@ import ( var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event: PodFailed; Action: RestartJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -68,7 +69,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event: PodFailed; Action: TerminateJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -105,7 +106,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event: PodFailed; Action: AbortJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -142,7 +143,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event: PodEvicted; Action: RestartJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -186,7 +187,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event: PodEvicted; Action: TerminateJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -230,7 +231,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event: PodEvicted; Action: AbortJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -274,7 +275,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event: Any; Action: RestartJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -318,7 +319,7 @@ var _ = Describe("Job Error Handling", func() { It("Job error handling: Restart job when job is unschedulable", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) @@ -377,7 +378,7 @@ var _ = Describe("Job Error Handling", func() { It("Job error handling: Abort job when job is unschedulable", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) @@ -432,7 +433,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event: TaskCompleted; Action: CompletedJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -472,7 +473,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, error code: 3; Action: RestartJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -510,7 +511,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event[]: PodEvicted, PodFailed; Action: TerminateJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -556,7 +557,7 @@ var _ = Describe("Job Error Handling", func() { }) It("Task level LifecyclePolicy, Event: PodFailed; Action: RestartJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -592,7 +593,7 @@ var _ = Describe("Job Error Handling", func() { }) It("Task level LifecyclePolicy, Event: PodEvicted; Action: RestartJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -636,7 +637,7 @@ var _ = Describe("Job Error Handling", func() { }) It("Task level LifecyclePolicy, Event: PodEvicted; Action: TerminateJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -679,7 +680,7 @@ var _ = Describe("Job Error Handling", func() { }) It("Task level LifecyclePolicy, Event: TaskCompleted; Action: CompletedJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -719,7 +720,7 @@ var _ = Describe("Job Error Handling", func() { It("job level LifecyclePolicy, Event: PodFailed; Action: AbortJob and Task level lifecyclePolicy, Event : PodFailed; Action: RestartJob", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -762,7 +763,9 @@ var _ = Describe("Job Error Handling", func() { It("Task Priority", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{ + priorityClasses: []string{masterPriority, workerPriority}, + }) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) diff --git a/test/e2e/job_lifecycle.go b/test/e2e/job_lifecycle.go index 17b750ae27..c01d1cef79 100644 --- a/test/e2e/job_lifecycle.go +++ b/test/e2e/job_lifecycle.go @@ -30,7 +30,7 @@ import ( var _ = Describe("Job Life Cycle", func() { It("Delete job that is pending state", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -62,7 +62,7 @@ var _ = Describe("Job Life Cycle", func() { It("Delete job that is Running state", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -93,7 +93,7 @@ var _ = Describe("Job Life Cycle", func() { It("Delete job that is Completed state", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -126,7 +126,7 @@ var _ = Describe("Job Life Cycle", func() { It("Delete job that is Failed job", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -165,7 +165,7 @@ var _ = Describe("Job Life Cycle", func() { It("Delete job that is terminated job", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -204,7 +204,7 @@ var _ = Describe("Job Life Cycle", func() { It("Create and Delete job with CPU requirement", func() { By("init test context") - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) By("create job") @@ -243,7 +243,7 @@ var _ = Describe("Job Life Cycle", func() { }) It("Checking Event Generation for job", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) job := createJob(context, &jobSpec{ @@ -271,7 +271,7 @@ var _ = Describe("Job Life Cycle", func() { }) It("Checking Unschedulable Event Generation for job", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) nodeName, rep := computeNode(context, oneCPU) diff --git a/test/e2e/job_plugins.go b/test/e2e/job_plugins.go index 24f688bae3..d8b4204f25 100644 --- a/test/e2e/job_plugins.go +++ b/test/e2e/job_plugins.go @@ -33,7 +33,7 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() { namespace := "test" taskName := "task" foundVolume := false - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) nodeName, rep := computeNode(context, oneCPU) @@ -105,7 +105,7 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() { namespace := "test" taskName := "task" foundVolume := false - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) _, rep := computeNode(context, oneCPU) @@ -178,7 +178,7 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() { taskName := "task" foundVolume := false foundEnv := false - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) _, rep := computeNode(context, oneCPU) diff --git a/test/e2e/job_scheduling.go b/test/e2e/job_scheduling.go index 6e45c27b56..b1379afc80 100644 --- a/test/e2e/job_scheduling.go +++ b/test/e2e/job_scheduling.go @@ -36,7 +36,7 @@ import ( var _ = Describe("Job E2E Test", func() { It("Schedule Job", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) @@ -57,7 +57,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Schedule Multiple Jobs", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) @@ -91,7 +91,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Gang scheduling", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU)/2 + 1 @@ -128,7 +128,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Gang scheduling: Full Occupied", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) @@ -159,7 +159,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Preemption", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) slot := oneCPU @@ -191,7 +191,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Multiple Preemption", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) slot := oneCPU @@ -232,7 +232,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Schedule BestEffort Job", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) slot := oneCPU @@ -262,7 +262,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Statement", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) slot := oneCPU @@ -299,7 +299,7 @@ var _ = Describe("Job E2E Test", func() { }) It("support binpack policy", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) slot := oneCPU @@ -382,7 +382,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Schedule v1.Job type using Volcano scheduler", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) namespace := "test" parallel := int32(2) @@ -418,7 +418,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Schedule v1.Job type using Volcano scheduler with error case", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) namespace := "test" parallel := int32(2) @@ -479,7 +479,7 @@ var _ = Describe("Job E2E Test", func() { }) It("Namespace Fair Share", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) const fairShareNamespace = "fairshare" @@ -585,7 +585,9 @@ var _ = Describe("Job E2E Test", func() { }) It("Queue Fair Share", func() { - context := initTestContext() + context := initTestContext(options{ + queues: []string{defaultQueue1, defaultQueue2}, + }) defer cleanupTestContext(context) slot := halfCPU diff --git a/test/e2e/mpi.go b/test/e2e/mpi.go index 4ba32c7112..1549210509 100644 --- a/test/e2e/mpi.go +++ b/test/e2e/mpi.go @@ -25,7 +25,7 @@ import ( var _ = Describe("MPI E2E Test", func() { It("will run and complete finally", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) slot := oneCPU diff --git a/test/e2e/pg_controller.go b/test/e2e/pg_controller.go index 8f3490230a..ac82cfd12b 100644 --- a/test/e2e/pg_controller.go +++ b/test/e2e/pg_controller.go @@ -30,7 +30,7 @@ var _ = Describe("PG E2E Test: Test PG controller", func() { podName := "pod-volcano" namespace := "test" label := map[string]string{"schedulerName": "volcano"} - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rc := &corev1.ReplicationController{ @@ -85,7 +85,7 @@ var _ = Describe("PG E2E Test: Test PG controller", func() { podName := "pod-default-scheduler" namespace := "test" label := map[string]string{"a": "b"} - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) rc := &corev1.ReplicationController{ diff --git a/test/e2e/predicates.go b/test/e2e/predicates.go index 1a106587d8..7d0e3d0b98 100644 --- a/test/e2e/predicates.go +++ b/test/e2e/predicates.go @@ -27,7 +27,7 @@ import ( var _ = Describe("Predicates E2E Test", func() { It("Hostport", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) nn := clusterNodeNumber(context) @@ -55,7 +55,7 @@ var _ = Describe("Predicates E2E Test", func() { }) It("NodeAffinity", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) slot := oneCPU @@ -104,7 +104,7 @@ var _ = Describe("Predicates E2E Test", func() { }) It("Pod Affinity", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) slot := oneCPU @@ -153,7 +153,7 @@ var _ = Describe("Predicates E2E Test", func() { }) It("Pod Anti-Affinity", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) slot := oneCPU @@ -203,7 +203,7 @@ var _ = Describe("Predicates E2E Test", func() { }) It("Taints", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) taints := []v1.Taint{ @@ -242,7 +242,7 @@ var _ = Describe("Predicates E2E Test", func() { }) It("Taints and Tolerations", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) taints := []v1.Taint{ diff --git a/test/e2e/queue.go b/test/e2e/queue.go index cbdc46366a..dd7243b6e3 100644 --- a/test/e2e/queue.go +++ b/test/e2e/queue.go @@ -27,7 +27,9 @@ import ( var _ = Describe("Queue E2E Test", func() { It("Reclaim", func() { - context := initTestContext() + context := initTestContext(options{ + queues: []string{defaultQueue1, defaultQueue2}, + }) defer cleanupTestContext(context) slot := oneCPU diff --git a/test/e2e/tensorflow.go b/test/e2e/tensorflow.go index 50851dc90a..947e24c899 100644 --- a/test/e2e/tensorflow.go +++ b/test/e2e/tensorflow.go @@ -28,7 +28,7 @@ import ( var _ = Describe("TensorFlow E2E Test", func() { It("Will Start in pending state and goes through other phases to get complete phase", func() { - context := initTestContext() + context := initTestContext(options{}) defer cleanupTestContext(context) jobName := "tensorflow-dist-mnist" diff --git a/test/e2e/util.go b/test/e2e/util.go index f89d739346..ebf3be6693 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -97,9 +97,9 @@ func kubeconfigPath(home string) string { return filepath.Join(home, ".kube", "config") // default kubeconfig path is $HOME/.kube/config } -//VolcanoCliBinary function gets the volcano cli binary +// VolcanoCliBinary function gets the volcano cli binary func VolcanoCliBinary() string { - if bin := os.Getenv("VK_BIN"); bin != "" { + if bin := os.Getenv("VC_BIN"); bin != "" { return filepath.Join(bin, "vcctl") } return "" @@ -109,62 +109,49 @@ type context struct { kubeclient *kubernetes.Clientset vcclient *vcclient.Clientset - namespace string - queues []string + namespace string + queues []string + priorityClasses []string +} + +type options struct { + namespace string + queues []string + priorityClasses []string } -func initTestContext() *context { - cxt := &context{ - namespace: defaultNamespace, - queues: []string{defaultQueue1, defaultQueue2}, +func initTestContext(o options) *context { + if o.namespace == "" { + o.namespace = defaultNamespace + } + ctx := &context{ + namespace: o.namespace, + queues: o.queues, + priorityClasses: o.priorityClasses, } home := homeDir() Expect(home).NotTo(Equal("")) configPath := kubeconfigPath(home) Expect(configPath).NotTo(Equal("")) - vcctl := VolcanoCliBinary() - Expect(fileExist(vcctl)).To(BeTrue(), fmt.Sprintf( - "vcctl binary: %s is required for E2E tests, please update VK_BIN environment", vcctl)) + config, err := clientcmd.BuildConfigFromFlags(masterURL(), configPath) Expect(err).NotTo(HaveOccurred()) - cxt.vcclient = vcclient.NewForConfigOrDie(config) - cxt.kubeclient = kubernetes.NewForConfigOrDie(config) - - //Ensure at least one worker is ready - err = waitClusterReady(cxt) - Expect(err).NotTo(HaveOccurred(), - "k8s cluster is required to have one ready worker node at least.") + ctx.vcclient = vcclient.NewForConfigOrDie(config) + ctx.kubeclient = kubernetes.NewForConfigOrDie(config) - _, err = cxt.kubeclient.CoreV1().Namespaces().Create(&v1.Namespace{ + _, err = ctx.kubeclient.CoreV1().Namespaces().Create(&v1.Namespace{ ObjectMeta: metav1.ObjectMeta{ - Name: cxt.namespace, + Name: ctx.namespace, }, }) Expect(err).NotTo(HaveOccurred()) - createQueues(cxt) + createQueues(ctx) + createPriorityClasses(ctx) - _, err = cxt.kubeclient.SchedulingV1beta1().PriorityClasses().Create(&schedv1.PriorityClass{ - ObjectMeta: metav1.ObjectMeta{ - Name: masterPriority, - }, - Value: 100, - GlobalDefault: false, - }) - Expect(err).NotTo(HaveOccurred()) - - _, err = cxt.kubeclient.SchedulingV1beta1().PriorityClasses().Create(&schedv1.PriorityClass{ - ObjectMeta: metav1.ObjectMeta{ - Name: workerPriority, - }, - Value: 1, - GlobalDefault: false, - }) - Expect(err).NotTo(HaveOccurred()) - - return cxt + return ctx } func namespaceNotExist(ctx *context) wait.ConditionFunc { @@ -181,20 +168,6 @@ func namespaceNotExistWithName(ctx *context, name string) wait.ConditionFunc { } } -func queueNotExist(ctx *context) wait.ConditionFunc { - return func() (bool, error) { - for _, q := range ctx.queues { - var err error - _, err = ctx.vcclient.SchedulingV1alpha2().Queues().Get(q, metav1.GetOptions{}) - if !(err != nil && errors.IsNotFound(err)) { - return false, err - } - } - - return true, nil - } -} - func fileExist(name string) bool { if _, err := os.Stat(name); err != nil { if os.IsNotExist(err) { @@ -204,40 +177,25 @@ func fileExist(name string) bool { return true } -func cleanupTestContext(cxt *context) { +func cleanupTestContext(ctx *context) { foreground := metav1.DeletePropagationForeground - - err := cxt.kubeclient.CoreV1().Namespaces().Delete(cxt.namespace, &metav1.DeleteOptions{ + err := ctx.kubeclient.CoreV1().Namespaces().Delete(ctx.namespace, &metav1.DeleteOptions{ PropagationPolicy: &foreground, }) Expect(err).NotTo(HaveOccurred()) - deleteQueues(cxt) - - err = cxt.kubeclient.SchedulingV1beta1().PriorityClasses().Delete(masterPriority, &metav1.DeleteOptions{ - PropagationPolicy: &foreground, - }) - Expect(err).NotTo(HaveOccurred()) + deleteQueues(ctx) - err = cxt.kubeclient.SchedulingV1beta1().PriorityClasses().Delete(workerPriority, &metav1.DeleteOptions{ - PropagationPolicy: &foreground, - }) - Expect(err).NotTo(HaveOccurred()) + deletePriorityClasses(ctx) // Wait for namespace deleted. - err = wait.Poll(100*time.Millisecond, twoMinute, namespaceNotExist(cxt)) - Expect(err).NotTo(HaveOccurred()) - - // Wait for queues deleted - err = wait.Poll(100*time.Millisecond, twoMinute, queueNotExist(cxt)) + err = wait.Poll(100*time.Millisecond, twoMinute, namespaceNotExist(ctx)) Expect(err).NotTo(HaveOccurred()) } func createQueues(cxt *context) { - var err error - for _, q := range cxt.queues { - _, err = cxt.vcclient.SchedulingV1alpha2().Queues().Create(&schedulingv1alpha2.Queue{ + _, err := cxt.vcclient.SchedulingV1alpha2().Queues().Create(&schedulingv1alpha2.Queue{ ObjectMeta: metav1.ObjectMeta{ Name: q, }, @@ -262,6 +220,26 @@ func deleteQueues(cxt *context) { } } +func createPriorityClasses(cxt *context) { + for _, pc := range cxt.priorityClasses { + _, err := cxt.kubeclient.SchedulingV1beta1().PriorityClasses().Create(&schedv1.PriorityClass{ + ObjectMeta: metav1.ObjectMeta{ + Name: pc, + }, + Value: 100, + GlobalDefault: false, + }) + Expect(err).NotTo(HaveOccurred()) + } +} + +func deletePriorityClasses(cxt *context) { + for _, pc := range cxt.priorityClasses { + err := cxt.kubeclient.SchedulingV1beta1().PriorityClasses().Delete(pc, &metav1.DeleteOptions{}) + Expect(err).NotTo(HaveOccurred()) + } +} + type taskSpec struct { name string min, rep int32 diff --git a/test/e2e/vcctl.go b/test/e2e/vcctl.go index 0e83575d0e..fdfa5a1a63 100644 --- a/test/e2e/vcctl.go +++ b/test/e2e/vcctl.go @@ -106,7 +106,7 @@ Global Flags: Expect(exist).Should(Equal(true)) }) - It("Command: vkctl job suspend -n {$JobName} --help", func() { + It("Command: vcctl job suspend -n {$JobName} --help", func() { kubeConfig := os.Getenv("KUBECONFIG") var output = ` abort a job @@ -131,7 +131,7 @@ Global Flags: Expect(exist).Should(Equal(true)) }) - It("vkctl job resume -n {$JobName} --help", func() { + It("vcctl job resume -n {$JobName} --help", func() { kubeConfig := os.Getenv("KUBECONFIG") var output = ` resume a job @@ -156,7 +156,7 @@ Global Flags: Expect(exist).Should(Equal(true)) }) - It("vkctl job run --help", func() { + It("vcctl job run --help", func() { kubeConfig := os.Getenv("KUBECONFIG") var output = ` run job by parameters from the command line