sigs.k8s.io/blob-csi-driver@v1.24.1/test/e2e/testsuites/dynamically_provisioned_volume_cloning_tester.go (about) 1 /* 2 Copyright 2019 The Kubernetes 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 testsuites 18 19 import ( 20 "context" 21 "time" 22 23 "github.com/onsi/ginkgo/v2" 24 v1 "k8s.io/api/core/v1" 25 clientset "k8s.io/client-go/kubernetes" 26 "sigs.k8s.io/blob-csi-driver/test/e2e/driver" 27 ) 28 29 // DynamicallyProvisionedVolumeCloningTest will provision required StorageClass(es), PVC(s) and Pod(s) 30 // ClonedVolumeSize optional for when testing for cloned volume with different size to the original volume 31 type DynamicallyProvisionedVolumeCloningTest struct { 32 CSIDriver driver.DynamicPVTestDriver 33 Pod PodDetails 34 PodWithClonedVolume PodDetails 35 ClonedVolumeSize string 36 StorageClassParameters map[string]string 37 } 38 39 func (t *DynamicallyProvisionedVolumeCloningTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) { 40 // create the storageClass 41 tsc, tscCleanup := t.Pod.Volumes[0].CreateStorageClass(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters) 42 defer tscCleanup(ctx) 43 44 // create the pod 45 t.Pod.Volumes[0].StorageClass = tsc.storageClass 46 tpod, cleanups := t.Pod.SetupWithDynamicVolumes(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters) 47 for i := range cleanups { 48 defer cleanups[i](ctx) 49 } 50 51 ginkgo.By("deploying the pod") 52 tpod.Create(ctx) 53 defer tpod.Cleanup(ctx) 54 ginkgo.By("checking that the pod's command exits with no error") 55 tpod.WaitForSuccess(ctx) 56 ginkgo.By("sleep 5s and then clone volume") 57 time.Sleep(5 * time.Second) 58 59 ginkgo.By("cloning existing volume") 60 clonedVolume := t.Pod.Volumes[0] 61 clonedVolume.DataSource = &DataSource{ 62 Name: tpod.pod.Spec.Volumes[0].VolumeSource.PersistentVolumeClaim.ClaimName, 63 Kind: VolumePVCKind, 64 } 65 clonedVolume.StorageClass = tsc.storageClass 66 67 if t.ClonedVolumeSize != "" { 68 clonedVolume.ClaimSize = t.ClonedVolumeSize 69 } 70 71 t.PodWithClonedVolume.Volumes = []VolumeDetails{clonedVolume} 72 tpod, cleanups = t.PodWithClonedVolume.SetupWithDynamicVolumes(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters) 73 for i := range cleanups { 74 defer cleanups[i](ctx) 75 } 76 77 ginkgo.By("deploying a second pod with cloned volume") 78 tpod.Create(ctx) 79 defer tpod.Cleanup(ctx) 80 ginkgo.By("checking that the pod's command exits with no error") 81 tpod.WaitForSuccess(ctx) 82 }