Skip to content

Commit f6c8112

Browse files
Merge pull request #374 from thandayuthapani/e2e
Add E2E for scheduling v1.Job using volcano scheduler
2 parents 00d9a2a + 686d19a commit f6c8112

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

test/e2e/job_scheduling.go

+101
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121

2222
. "github.com/onsi/ginkgo"
2323
. "github.com/onsi/gomega"
24+
25+
batchv1 "k8s.io/api/batch/v1"
26+
"k8s.io/api/core/v1"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2428
)
2529

2630
var _ = Describe("Job E2E Test", func() {
@@ -286,4 +290,101 @@ var _ = Describe("Job E2E Test", func() {
286290
Expect(err).NotTo(HaveOccurred())
287291
Expect(evicted).NotTo(BeTrue())
288292
})
293+
294+
It("Schedule v1.Job type using Volcano scheduler", func() {
295+
context := initTestContext()
296+
defer cleanupTestContext(context)
297+
namespace := "test"
298+
parallel := int32(2)
299+
300+
job := &batchv1.Job{
301+
ObjectMeta: metav1.ObjectMeta{
302+
Name: "job1",
303+
Namespace: namespace,
304+
},
305+
Spec: batchv1.JobSpec{
306+
Parallelism: &parallel,
307+
Template: v1.PodTemplateSpec{
308+
Spec: v1.PodSpec{
309+
RestartPolicy: v1.RestartPolicyNever,
310+
SchedulerName: schedulerName,
311+
Containers: []v1.Container{
312+
{
313+
Name: "test-container",
314+
Image: "nginx",
315+
},
316+
},
317+
},
318+
},
319+
},
320+
}
321+
322+
//create job
323+
job, err := context.kubeclient.BatchV1().Jobs(namespace).Create(job)
324+
Expect(err).NotTo(HaveOccurred())
325+
326+
err = waitJobPhaseReady(context, job)
327+
Expect(err).NotTo(HaveOccurred())
328+
})
329+
330+
It("Schedule v1.Job type using Volcano scheduler with error case", func() {
331+
context := initTestContext()
332+
defer cleanupTestContext(context)
333+
namespace := "test"
334+
parallel := int32(2)
335+
336+
errorJob := &batchv1.Job{
337+
ObjectMeta: metav1.ObjectMeta{
338+
Name: "job1",
339+
Namespace: namespace,
340+
},
341+
Spec: batchv1.JobSpec{
342+
Parallelism: &parallel,
343+
Template: v1.PodTemplateSpec{
344+
Spec: v1.PodSpec{
345+
SchedulerName: schedulerName,
346+
Containers: []v1.Container{
347+
{
348+
Name: "test-container",
349+
Image: "nginx",
350+
},
351+
},
352+
},
353+
},
354+
},
355+
}
356+
357+
job := &batchv1.Job{
358+
ObjectMeta: metav1.ObjectMeta{
359+
Name: "job1",
360+
Namespace: namespace,
361+
},
362+
Spec: batchv1.JobSpec{
363+
Parallelism: &parallel,
364+
Template: v1.PodTemplateSpec{
365+
Spec: v1.PodSpec{
366+
RestartPolicy: v1.RestartPolicyNever,
367+
SchedulerName: schedulerName,
368+
Containers: []v1.Container{
369+
{
370+
Name: "test-container",
371+
Image: "nginx",
372+
},
373+
},
374+
},
375+
},
376+
},
377+
}
378+
379+
//create error job
380+
errorJob, err := context.kubeclient.BatchV1().Jobs(namespace).Create(errorJob)
381+
Expect(err).To(HaveOccurred())
382+
383+
//create job
384+
job, err = context.kubeclient.BatchV1().Jobs(namespace).Create(job)
385+
Expect(err).NotTo(HaveOccurred())
386+
387+
err = waitJobPhaseReady(context, job)
388+
Expect(err).NotTo(HaveOccurred())
389+
})
289390
})

test/e2e/util.go

+22
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
. "github.com/onsi/gomega"
2828

2929
appv1 "k8s.io/api/apps/v1"
30+
batchv1 "k8s.io/api/batch/v1"
3031
"k8s.io/api/core/v1"
3132
schedv1 "k8s.io/api/scheduling/v1beta1"
3233
"k8s.io/apimachinery/pkg/api/errors"
@@ -63,6 +64,7 @@ const (
6364
nodeFieldSelectorKeyNodeName = api.ObjectNameField
6465
defaultBusyBoxImage = "busybox:1.24"
6566
defaultMPIImage = "volcanosh/example-mpi:0.0.1"
67+
schedulerName = "volcano"
6668

6769
defaultNamespace = "test"
6870
defaultQueue1 = "q1"
@@ -659,6 +661,26 @@ func waitJobPhaseExpect(ctx *context, job *vkv1.Job, state vkv1.JobPhase) error
659661
return err
660662
}
661663

664+
func waitJobPhaseReady(ctx *context, job *batchv1.Job) error {
665+
var additionalError error
666+
667+
err := wait.Poll(100*time.Millisecond, oneMinute, func() (bool, error) {
668+
job, err := ctx.kubeclient.BatchV1().Jobs(job.Namespace).Get(job.Name, metav1.GetOptions{})
669+
Expect(err).NotTo(HaveOccurred())
670+
expected := job.Status.Active > 0
671+
if !expected {
672+
additionalError = fmt.Errorf("expected job '%s' active pod to be greater than 0, actual got %d", job.Name, job.Status.Active)
673+
}
674+
return expected, nil
675+
})
676+
677+
if err != nil && strings.Contains(err.Error(), timeOutMessage) {
678+
return fmt.Errorf("[Wait time out]: %s", additionalError)
679+
}
680+
681+
return err
682+
}
683+
662684
func waitJobUnschedulable(ctx *context, job *vkv1.Job) error {
663685
now := time.Now()
664686
return jobUnschedulable(ctx, job, now)

0 commit comments

Comments
 (0)