Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added e2e test case with exist pvc in job #379

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 96 additions & 3 deletions test/e2e/job_controlled_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
. "github.com/onsi/gomega"
v12 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ var _ = Describe("Job E2E Test: Test Job PVCs", func() {
err := waitJobReady(context, job)
Expect(err).NotTo(HaveOccurred())

job, err = context.vkclient.BatchV1alpha1().Jobs(namespace).Get(jobName, v1.GetOptions{})
job, err = context.vkclient.BatchV1alpha1().Jobs(namespace).Get(jobName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

Expect(len(job.Spec.Volumes)).To(Equal(1),
Expand All @@ -67,6 +67,99 @@ var _ = Describe("Job E2E Test: Test Job PVCs", func() {
}
})

It("use exisisting PVC in job", func() {
jobName := "job-pvc-name-exist"
namespace := "test"
taskName := "pvctask"
pvName := "job-pv-name"
pvcName := "job-pvc-name-exist"
context := initTestContext()
defer cleanupTestContext(context)

var tt v12.HostPathType
tt = "DirectoryOrCreate"

storageClsName := "standard"

pv := v12.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: pvName,
},
Spec: v12.PersistentVolumeSpec{
StorageClassName: storageClsName,
Capacity: v12.ResourceList{
v12.ResourceName(v12.ResourceStorage): resource.MustParse("1Gi"),
},
PersistentVolumeSource: v12.PersistentVolumeSource{
HostPath: &v12.HostPathVolumeSource{
Path: "/tmp/pvtest",
Type: &tt,
}},
AccessModes: []v12.PersistentVolumeAccessMode{
v12.ReadWriteOnce,
},
},
}
_, err := context.kubeclient.CoreV1().PersistentVolumes().Create(&pv)
Expect(err).NotTo(HaveOccurred(), "pv creation ")
//create pvc
pvc := v12.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: pvcName,
},
Spec: v12.PersistentVolumeClaimSpec{
StorageClassName: &storageClsName,
VolumeName: pvName,
Resources: v12.ResourceRequirements{
Requests: v12.ResourceList{
v12.ResourceName(v12.ResourceStorage): resource.MustParse("1Gi"),
},
},
AccessModes: []v12.PersistentVolumeAccessMode{
v12.ReadWriteOnce,
},
},
}

_, err1 := context.kubeclient.CoreV1().PersistentVolumeClaims(namespace).Create(&pvc)
Expect(err1).NotTo(HaveOccurred(), "pvc creation")
job := createJob(context, &jobSpec{
namespace: namespace,
name: jobName,
tasks: []taskSpec{
{
img: defaultNginxImage,
req: oneCPU,
min: 1,
rep: 1,
name: taskName,
},
},
volumes: []v1alpha1.VolumeSpec{
{
MountPath: "/mounttwo",
VolumeClaimName: pvcName,
VolumeClaim: &pvc.Spec,
},
},
})

err = waitJobReady(context, job)
Expect(err).NotTo(HaveOccurred())

job, err = context.vkclient.BatchV1alpha1().Jobs(namespace).Get(jobName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

Expect(len(job.Spec.Volumes)).To(Equal(1),
" volume should be created")
for _, volume := range job.Spec.Volumes {
Expect(volume.VolumeClaimName).Should((Equal(pvcName)),
"PVC name should not be generated .")
}
})

It("Generate PodGroup and valid minResource when creating job", func() {
jobName := "job-name-podgroup"
namespace := "test"
Expand Down Expand Up @@ -111,7 +204,7 @@ var _ = Describe("Job E2E Test: Test Job PVCs", func() {
err := waitJobStatePending(context, job)
Expect(err).NotTo(HaveOccurred())

pGroup, err := context.kbclient.SchedulingV1alpha1().PodGroups(namespace).Get(jobName, v1.GetOptions{})
pGroup, err := context.kbclient.SchedulingV1alpha1().PodGroups(namespace).Get(jobName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

for name, q := range *pGroup.Spec.MinResources {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func getNS(context *context, job *jobSpec) string {
func createJob(context *context, jobSpec *jobSpec) *vkv1.Job {

job, err := createJobInner(context, jobSpec)
Expect(err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "create job")

return job
}
Expand Down