Skip to content

Commit

Permalink
Merge pull request #186 from SrinivasChilveri/OptimizeE2ETcs
Browse files Browse the repository at this point in the history
Optimizing E2E test cases
  • Loading branch information
volcano-sh-bot authored May 20, 2019
2 parents 5fc5713 + ef9e41f commit 9ba08a3
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 153 deletions.
23 changes: 21 additions & 2 deletions test/e2e/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package e2e
import (
"bytes"
"fmt"
v1 "k8s.io/api/core/v1"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -153,14 +154,25 @@ 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"
context := initTestContext()
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,
Expand All @@ -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)
Expand Down
80 changes: 68 additions & 12 deletions test/e2e/job_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,42 @@ 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"
foundVolume := false
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,
Expand All @@ -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,
},
},
})
Expand All @@ -68,16 +92,39 @@ 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"
foundVolume := false
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,
Expand All @@ -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,
},
},
})
Expand All @@ -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))
}
})
})
139 changes: 0 additions & 139 deletions test/e2e/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
})

})

0 comments on commit 9ba08a3

Please sign in to comment.