sigs.k8s.io/blob-csi-driver@v1.24.1/test/e2e/testsuites/dynamically_provisioned_resize_volume_tester.go (about) 1 /* 2 Copyright 2020 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 "fmt" 22 "strings" 23 "time" 24 25 "github.com/onsi/ginkgo/v2" 26 "sigs.k8s.io/blob-csi-driver/pkg/util" 27 "sigs.k8s.io/blob-csi-driver/test/e2e/driver" 28 29 v1 "k8s.io/api/core/v1" 30 "k8s.io/apimachinery/pkg/api/resource" 31 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 32 clientset "k8s.io/client-go/kubernetes" 33 "k8s.io/kubernetes/test/e2e/framework" 34 ) 35 36 // DynamicallyProvisionedResizeVolumeTest will provision required StorageClass(es), PVC(s) and Pod(s) 37 // Waiting for the PV provisioner to resize the PV 38 // Testing if the PV is resized successfully. 39 type DynamicallyProvisionedResizeVolumeTest struct { 40 CSIDriver driver.DynamicPVTestDriver 41 Pods []PodDetails 42 StorageClassParameters map[string]string 43 } 44 45 func (t *DynamicallyProvisionedResizeVolumeTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) { 46 for _, pod := range t.Pods { 47 tpod, cleanup := pod.SetupWithDynamicVolumes(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters) 48 // defer must be called here for resources not get removed before using them 49 for i := range cleanup { 50 defer cleanup[i](ctx) 51 } 52 53 ginkgo.By("deploying the pod") 54 tpod.Create(ctx) 55 defer tpod.Cleanup(ctx) 56 ginkgo.By("checking that the pods command exits with no error") 57 tpod.WaitForSuccess(ctx) 58 59 pvcName := tpod.pod.Spec.Volumes[0].VolumeSource.PersistentVolumeClaim.ClaimName 60 pvc, err := client.CoreV1().PersistentVolumeClaims(namespace.Name).Get(ctx, pvcName, metav1.GetOptions{}) 61 if err != nil { 62 framework.ExpectNoError(err, fmt.Sprintf("fail to get original pvc(%s): %v", pvcName, err)) 63 } 64 65 originalSize := pvc.Spec.Resources.Requests["storage"] 66 delta := resource.Quantity{} 67 delta.Set(util.GiBToBytes(1)) 68 originalSize.Add(delta) 69 pvc.Spec.Resources.Requests["storage"] = originalSize 70 71 ginkgo.By("resizing the pvc") 72 updatedPvc, err := client.CoreV1().PersistentVolumeClaims(namespace.Name).Update(ctx, pvc, metav1.UpdateOptions{}) 73 if err != nil { 74 framework.ExpectNoError(err, fmt.Sprintf("fail to resize pvc(%s): %v", pvcName, err)) 75 } 76 updatedSize := updatedPvc.Spec.Resources.Requests["storage"] 77 78 ginkgo.By("sleep 30s waiting for resize complete") 79 time.Sleep(30 * time.Second) 80 81 ginkgo.By("checking the resizing result") 82 newPvc, err := client.CoreV1().PersistentVolumeClaims(namespace.Name).Get(ctx, tpod.pod.Spec.Volumes[0].VolumeSource.PersistentVolumeClaim.ClaimName, metav1.GetOptions{}) 83 if err != nil { 84 framework.ExpectNoError(err, fmt.Sprintf("fail to get new pvc(%s): %v", pvcName, err)) 85 } 86 newSize := newPvc.Spec.Resources.Requests["storage"] 87 if !newSize.Equal(updatedSize) { 88 framework.Failf("newSize(%+v) is not equal to updatedSize(%+v)", newSize, updatedSize) 89 } 90 91 ginkgo.By("checking the resizing PV result") 92 newPv, _ := client.CoreV1().PersistentVolumes().Get(ctx, updatedPvc.Spec.VolumeName, metav1.GetOptions{}) 93 newPvSize := newPv.Spec.Capacity["storage"] 94 newPvSizeStr := newPvSize.String() + "Gi" 95 96 if !strings.Contains(newPvSizeStr, newSize.String()) { 97 framework.Failf("newPVCSize(%+v) is not equal to newPVSize(%+v)", newSize.String(), newPvSizeStr) 98 } 99 } 100 }