From ef9e41f88dbc8eeada0ec67fb8481296b31479ae Mon Sep 17 00:00:00 2001 From: SrinivasChilveri Date: Sat, 18 May 2019 19:16:26 +0530 Subject: [PATCH] Optimizing E2E test cases --- test/e2e/command.go | 23 ++++++- test/e2e/job_plugins.go | 80 +++++++++++++++++++---- test/e2e/predicates.go | 139 ---------------------------------------- 3 files changed, 89 insertions(+), 153 deletions(-) diff --git a/test/e2e/command.go b/test/e2e/command.go index 9c1654a4f0..8040a9691f 100644 --- a/test/e2e/command.go +++ b/test/e2e/command.go @@ -19,6 +19,7 @@ package e2e import ( "bytes" "fmt" + v1 "k8s.io/api/core/v1" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -153,7 +154,7 @@ var _ = Describe("Job E2E Test: Test Job Command", func() { "Job related pod should be deleted when job aborted.") }) - It("delete a job", func() { + It("delete a job with all nodes taints", func() { jobName := "test-del-job" namespace := "test" @@ -161,6 +162,17 @@ var _ = Describe("Job E2E Test: Test Job Command", func() { defer cleanupTestContext(context) rep := clusterSize(context, oneCPU) + taints := []v1.Taint{ + { + Key: "test-taint-key", + Value: "test-taint-val", + Effect: v1.TaintEffectNoSchedule, + }, + } + + err := taintAllNodes(context, taints) + Expect(err).NotTo(HaveOccurred()) + job := createJob(context, &jobSpec{ namespace: namespace, name: jobName, @@ -173,8 +185,15 @@ var _ = Describe("Job E2E Test: Test Job Command", func() { }, }, }) + + err = waitJobPending(context, job) + Expect(err).NotTo(HaveOccurred()) + + err = removeTaintsFromAllNodes(context, taints) + Expect(err).NotTo(HaveOccurred()) + // Pod is running - err := waitJobReady(context, job) + err = waitJobReady(context, job) Expect(err).NotTo(HaveOccurred()) // Job Status is running err = waitJobStateReady(context, job) diff --git a/test/e2e/job_plugins.go b/test/e2e/job_plugins.go index aba5bef5e2..abad42df4e 100644 --- a/test/e2e/job_plugins.go +++ b/test/e2e/job_plugins.go @@ -20,12 +20,14 @@ import ( "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + cv1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/kubernetes/pkg/scheduler/api" "volcano.sh/volcano/pkg/controllers/job/helpers" ) var _ = Describe("Job E2E Test: Test Job Plugins", func() { - It("SVC Plugin", func() { + It("SVC Plugin with Node Affinity", func() { jobName := "job-with-svc-plugin" namespace := "test" taskName := "task" @@ -33,6 +35,27 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() { context := initTestContext() defer cleanupTestContext(context) + nodeName, rep := computeNode(context, oneCPU) + Expect(rep).NotTo(Equal(0)) + + affinity := &cv1.Affinity{ + NodeAffinity: &cv1.NodeAffinity{ + RequiredDuringSchedulingIgnoredDuringExecution: &cv1.NodeSelector{ + NodeSelectorTerms: []cv1.NodeSelectorTerm{ + { + MatchFields: []cv1.NodeSelectorRequirement{ + { + Key: api.NodeFieldSelectorKeyNodeName, + Operator: cv1.NodeSelectorOpIn, + Values: []string{nodeName}, + }, + }, + }, + }, + }, + }, + } + job := createJob(context, &jobSpec{ namespace: namespace, name: jobName, @@ -41,11 +64,12 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() { }, tasks: []taskSpec{ { - img: defaultNginxImage, - req: oneCPU, - min: 1, - rep: 1, - name: taskName, + img: defaultNginxImage, + req: oneCPU, + min: 1, + rep: 1, + name: taskName, + affinity: affinity, }, }, }) @@ -68,9 +92,14 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() { } } Expect(foundVolume).To(BeTrue()) + + pods := getTasksOfJob(context, job) + for _, pod := range pods { + Expect(pod.Spec.NodeName).To(Equal(nodeName)) + } }) - It("SSh Plugin", func() { + It("SSh Plugin with Pod Affinity", func() { jobName := "job-with-ssh-plugin" namespace := "test" taskName := "task" @@ -78,6 +107,24 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() { context := initTestContext() defer cleanupTestContext(context) + _, rep := computeNode(context, oneCPU) + Expect(rep).NotTo(Equal(0)) + + labels := map[string]string{"foo": "bar"} + + affinity := &cv1.Affinity{ + PodAffinity: &cv1.PodAffinity{ + RequiredDuringSchedulingIgnoredDuringExecution: []cv1.PodAffinityTerm{ + { + LabelSelector: &v1.LabelSelector{ + MatchLabels: labels, + }, + TopologyKey: "kubernetes.io/hostname", + }, + }, + }, + } + job := createJob(context, &jobSpec{ namespace: namespace, name: jobName, @@ -86,11 +133,13 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() { }, tasks: []taskSpec{ { - img: defaultNginxImage, - req: oneCPU, - min: 1, - rep: 1, - name: taskName, + img: defaultNginxImage, + req: oneCPU, + min: rep, + rep: rep, + affinity: affinity, + labels: labels, + name: taskName, }, }, }) @@ -113,5 +162,12 @@ var _ = Describe("Job E2E Test: Test Job Plugins", func() { } } Expect(foundVolume).To(BeTrue()) + + pods := getTasksOfJob(context, job) + // All pods should be scheduled to the same node. + nodeName := pods[0].Spec.NodeName + for _, pod := range pods { + Expect(pod.Spec.NodeName).To(Equal(nodeName)) + } }) }) diff --git a/test/e2e/predicates.go b/test/e2e/predicates.go index 59e76fff52..b94cab41c5 100644 --- a/test/e2e/predicates.go +++ b/test/e2e/predicates.go @@ -19,61 +19,9 @@ package e2e import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - - "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/scheduler/api" ) var _ = Describe("Predicates E2E Test", func() { - It("NodeAffinity", func() { - context := initTestContext() - defer cleanupTestContext(context) - - slot := oneCPU - nodeName, rep := computeNode(context, oneCPU) - Expect(rep).NotTo(Equal(0)) - - affinity := &v1.Affinity{ - NodeAffinity: &v1.NodeAffinity{ - RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{ - NodeSelectorTerms: []v1.NodeSelectorTerm{ - { - MatchFields: []v1.NodeSelectorRequirement{ - { - Key: api.NodeFieldSelectorKeyNodeName, - Operator: v1.NodeSelectorOpIn, - Values: []string{nodeName}, - }, - }, - }, - }, - }, - }, - } - - spec := &jobSpec{ - name: "na-spec", - tasks: []taskSpec{ - { - img: defaultNginxImage, - req: slot, - min: 1, - rep: 1, - affinity: affinity, - }, - }, - } - - job := createJob(context, spec) - err := waitJobReady(context, job) - Expect(err).NotTo(HaveOccurred()) - - pods := getTasksOfJob(context, job) - for _, pod := range pods { - Expect(pod.Spec.NodeName).To(Equal(nodeName)) - } - }) It("Hostport", func() { context := initTestContext() @@ -103,91 +51,4 @@ var _ = Describe("Predicates E2E Test", func() { Expect(err).NotTo(HaveOccurred()) }) - It("Pod Affinity", func() { - context := initTestContext() - defer cleanupTestContext(context) - - slot := oneCPU - _, rep := computeNode(context, oneCPU) - Expect(rep).NotTo(Equal(0)) - - labels := map[string]string{"foo": "bar"} - - affinity := &v1.Affinity{ - PodAffinity: &v1.PodAffinity{ - RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{ - { - LabelSelector: &metav1.LabelSelector{ - MatchLabels: labels, - }, - TopologyKey: "kubernetes.io/hostname", - }, - }, - }, - } - - spec := &jobSpec{ - name: "pa-spec", - tasks: []taskSpec{ - { - img: defaultNginxImage, - req: slot, - min: rep, - rep: rep, - affinity: affinity, - labels: labels, - }, - }, - } - - job := createJob(context, spec) - err := waitJobReady(context, job) - Expect(err).NotTo(HaveOccurred()) - - pods := getTasksOfJob(context, job) - // All pods should be scheduled to the same node. - nodeName := pods[0].Spec.NodeName - for _, pod := range pods { - Expect(pod.Spec.NodeName).To(Equal(nodeName)) - } - }) - - It("Taints/Tolerations", func() { - context := initTestContext() - defer cleanupTestContext(context) - - taints := []v1.Taint{ - { - Key: "test-taint-key", - Value: "test-taint-val", - Effect: v1.TaintEffectNoSchedule, - }, - } - - err := taintAllNodes(context, taints) - Expect(err).NotTo(HaveOccurred()) - - spec := &jobSpec{ - name: "tt-spec", - tasks: []taskSpec{ - { - img: defaultNginxImage, - req: oneCPU, - min: 1, - rep: 1, - }, - }, - } - - job := createJob(context, spec) - err = waitJobPending(context, job) - Expect(err).NotTo(HaveOccurred()) - - err = removeTaintsFromAllNodes(context, taints) - Expect(err).NotTo(HaveOccurred()) - - err = waitJobReady(context, job) - Expect(err).NotTo(HaveOccurred()) - }) - })