volcano.sh/volcano@v1.9.0/test/e2e/jobp/job_controlled_resource.go (about) 1 /* 2 Copyright 2021 The Volcano Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package jobp 18 19 import ( 20 "context" 21 22 . "github.com/onsi/ginkgo/v2" 23 . "github.com/onsi/gomega" 24 v12 "k8s.io/api/core/v1" 25 "k8s.io/apimachinery/pkg/api/resource" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 28 "volcano.sh/apis/pkg/apis/batch/v1alpha1" 29 30 e2eutil "volcano.sh/volcano/test/e2e/util" 31 ) 32 33 var _ = Describe("Job E2E Test: Test Job PVCs", func() { 34 It("use exisisting PVC in job", func() { 35 // PVC related e2e verification fails probabilistically, See issue: #3102 36 Skip("PVC related e2e verification fails probabilistically, See issue: #3102") 37 jobName := "job-pvc-name-exist" 38 taskName := "pvctask" 39 pvName := "job-pv-name" 40 pvcName := "job-pvc-name-exist" 41 ctx := e2eutil.InitTestContext(e2eutil.Options{}) 42 defer e2eutil.CleanupTestContext(ctx) 43 44 var tt v12.HostPathType = "DirectoryOrCreate" 45 46 storageClsName := "standard" 47 48 // create pv 49 pv := v12.PersistentVolume{ 50 ObjectMeta: metav1.ObjectMeta{ 51 Name: pvName, 52 }, 53 Spec: v12.PersistentVolumeSpec{ 54 StorageClassName: storageClsName, 55 Capacity: v12.ResourceList{ 56 v12.ResourceName(v12.ResourceStorage): resource.MustParse("1Gi"), 57 }, 58 PersistentVolumeSource: v12.PersistentVolumeSource{ 59 HostPath: &v12.HostPathVolumeSource{ 60 Path: "/tmp/pvtest", 61 Type: &tt, 62 }}, 63 AccessModes: []v12.PersistentVolumeAccessMode{ 64 v12.ReadWriteOnce, 65 }, 66 }, 67 } 68 _, err := ctx.Kubeclient.CoreV1().PersistentVolumes().Create(context.TODO(), &pv, metav1.CreateOptions{}) 69 Expect(err).NotTo(HaveOccurred(), "pv creation ") 70 // create pvc 71 pvc := v12.PersistentVolumeClaim{ 72 ObjectMeta: metav1.ObjectMeta{ 73 Namespace: ctx.Namespace, 74 Name: pvcName, 75 }, 76 Spec: v12.PersistentVolumeClaimSpec{ 77 StorageClassName: &storageClsName, 78 VolumeName: pvName, 79 Resources: v12.VolumeResourceRequirements{ 80 Requests: v12.ResourceList{ 81 v12.ResourceName(v12.ResourceStorage): resource.MustParse("1Gi"), 82 }, 83 }, 84 AccessModes: []v12.PersistentVolumeAccessMode{ 85 v12.ReadWriteOnce, 86 }, 87 }, 88 } 89 _, err1 := ctx.Kubeclient.CoreV1().PersistentVolumeClaims(ctx.Namespace).Create(context.TODO(), &pvc, metav1.CreateOptions{}) 90 Expect(err1).NotTo(HaveOccurred(), "pvc creation") 91 92 pvSpec := &v12.PersistentVolumeClaimSpec{ 93 Resources: v12.VolumeResourceRequirements{ 94 Requests: v12.ResourceList{ 95 v12.ResourceName(v12.ResourceStorage): resource.MustParse("1Gi"), 96 }, 97 }, 98 AccessModes: []v12.PersistentVolumeAccessMode{ 99 v12.ReadWriteOnce, 100 }, 101 } 102 job := e2eutil.CreateJob(ctx, &e2eutil.JobSpec{ 103 Namespace: ctx.Namespace, 104 Name: jobName, 105 Tasks: []e2eutil.TaskSpec{ 106 { 107 Img: e2eutil.DefaultNginxImage, 108 Req: e2eutil.HalfCPU, 109 Min: 1, 110 Rep: 1, 111 Name: taskName, 112 }, 113 }, 114 Volumes: []v1alpha1.VolumeSpec{ 115 { 116 MountPath: "/mountone", 117 VolumeClaimName: pvcName, 118 }, 119 { 120 MountPath: "/mounttwo", 121 VolumeClaim: pvSpec, 122 }, 123 }, 124 }) 125 126 err = e2eutil.WaitJobReady(ctx, job) 127 Expect(err).NotTo(HaveOccurred()) 128 129 job, err = ctx.Vcclient.BatchV1alpha1().Jobs(ctx.Namespace).Get(context.TODO(), jobName, metav1.GetOptions{}) 130 Expect(err).NotTo(HaveOccurred()) 131 132 Expect(len(job.Spec.Volumes)).To(Equal(2), 133 " volume should be created") 134 Expect(job.Spec.Volumes[0].VolumeClaimName).Should(Equal(pvcName), 135 "volume 1 PVC name should not be generated .") 136 Expect(job.Spec.Volumes[1].VolumeClaimName).Should(Not(Equal("")), 137 "volume 0 PVC name should be generated.") 138 }) 139 140 It("Generate PodGroup and valid minResource when creating job", func() { 141 jobName := "job-name-podgroup" 142 ctx := e2eutil.InitTestContext(e2eutil.Options{}) 143 defer e2eutil.CleanupTestContext(ctx) 144 145 resource := v12.ResourceList{ 146 "cpu": resource.MustParse("1000m"), 147 "memory": resource.MustParse("1000Mi"), 148 "nvidia.com/gpu": resource.MustParse("1"), 149 } 150 151 job := e2eutil.CreateJob(ctx, &e2eutil.JobSpec{ 152 Namespace: ctx.Namespace, 153 Name: jobName, 154 Tasks: []e2eutil.TaskSpec{ 155 { 156 Img: e2eutil.DefaultNginxImage, 157 Min: 1, 158 Rep: 1, 159 Name: "task-1", 160 Req: resource, 161 Limit: resource, 162 }, 163 { 164 Img: e2eutil.DefaultNginxImage, 165 Min: 1, 166 Rep: 1, 167 Name: "task-2", 168 Req: resource, 169 Limit: resource, 170 }, 171 }, 172 }) 173 174 expected := map[string]int64{ 175 "count/pods": 2, 176 "cpu": 2, 177 "memory": 1024 * 1024 * 2000, 178 "nvidia.com/gpu": 2, 179 "limits.cpu": 2, 180 "limits.memory": 1024 * 1024 * 2000, 181 "requests.memory": 1024 * 1024 * 2000, 182 "requests.nvidia.com/gpu": 2, 183 "pods": 2, 184 "requests.cpu": 2, 185 } 186 187 err := e2eutil.WaitJobStatePending(ctx, job) 188 Expect(err).NotTo(HaveOccurred()) 189 190 pgName := jobName + "-" + string(job.UID) 191 pGroup, err := ctx.Vcclient.SchedulingV1beta1().PodGroups(ctx.Namespace).Get(context.TODO(), pgName, metav1.GetOptions{}) 192 Expect(err).NotTo(HaveOccurred()) 193 194 minReq := *pGroup.Spec.MinResources 195 for name, q := range expected { 196 value, ok := minReq[v12.ResourceName(name)] 197 Expect(ok).To(Equal(true), "Resource %s should exists in PodGroup", name) 198 Expect(q).To(Equal(value.Value()), "Resource %s 's value should equal to %d", name, value) 199 } 200 }) 201 })