From abfe3ed9cb29c99fb1913032724a51f048778956 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 11 Mar 2021 09:42:02 +0100 Subject: [PATCH] e2e: rework thick-provisioning test case The stripe-size is the most efficient size to write to RBD images. However, not all images are a multiple of stripe-size large. That means thick-provisioning would not allocate the full image, and the process might even fail. This adds a 50 MB PVC to test the process, 100 MB is coincidentally a multiple of the (default 4 MB) stripe-size, 50 MB is not. Signed-off-by: Niels de Vos --- e2e/rbd.go | 59 +++++++++-------------------------------------- e2e/rbd_helper.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 49 deletions(-) diff --git a/e2e/rbd.go b/e2e/rbd.go index 00d931dbc..e4ed528ce 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -1391,60 +1391,23 @@ var _ = Describe("RBD", func() { pvc, err := loadPVC(rawPvcPath) if err != nil { - e2elog.Failf("failed to load PVC with error %v", err) - } - pvc.Namespace = f.UniqueName - - err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout) - if err != nil { - e2elog.Failf("failed to create PVC with error %v", err) - } - validateRBDImageCount(f, 1) - - // nothing has been written, but the image should be allocated - du, err := getRbdDu(f, pvc) - if err != nil { - e2elog.Failf("failed to get allocations of RBD image: %v", err) - } else if du.UsedSize == 0 || du.UsedSize != du.ProvisionedSize { - e2elog.Failf("backing RBD image is not thick-provisioned (%d/%d)", du.UsedSize, du.ProvisionedSize) + e2elog.Failf("failed to load PVC with error: %v", err) } - // expanding the PVC should thick-allocate the expansion - // nolint:mnd // we want 2x the size so that extending is done - newSize := du.ProvisionedSize * 2 - err = expandPVCSize(f.ClientSet, pvc, fmt.Sprintf("%d", newSize), deployTimeout) - if err != nil { - e2elog.Failf("failed to expand PVC: %v", err) + pvcSizes := []string{ + // original value from the yaml file (100MB) + "100Mi", + // half the size (50MB), is not stripe-size roundable + "50Mi", } - // after expansion, the updated 'du' should be larger - du, err = getRbdDu(f, pvc) - if err != nil { - e2elog.Failf("failed to get allocations of RBD image: %v", err) - } else if du.UsedSize != newSize { - e2elog.Failf("backing RBD image is not extended thick-provisioned (%d/%d)", du.UsedSize, newSize) + for _, pvcSize := range pvcSizes { + err = validateThickPVC(f, pvc, pvcSize) + if err != nil { + e2elog.Failf("validating thick-provisioning failed: %v", err) + } } - // thick provisioning allows for sparsifying - err = sparsifyBackingRBDImage(f, pvc) - if err != nil { - e2elog.Failf("failed to sparsify RBD image: %v", err) - } - - // after sparsifying the image should not have any allocations - du, err = getRbdDu(f, pvc) - if err != nil { - e2elog.Failf("backing RBD image is not thick-provisioned: %v", err) - } else if du.UsedSize != 0 { - e2elog.Failf("backing RBD image was not sparsified") - } - - err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout) - if err != nil { - e2elog.Failf("failed to delete PVC with error: %v", err) - } - validateRBDImageCount(f, 0) - err = deleteResource(rbdExamplePath + "storageclass.yaml") if err != nil { e2elog.Failf("failed to delete storageclass with error %v", err) diff --git a/e2e/rbd_helper.go b/e2e/rbd_helper.go index 6fb4d5de6..09c5fc7e7 100644 --- a/e2e/rbd_helper.go +++ b/e2e/rbd_helper.go @@ -9,7 +9,7 @@ import ( v1 "k8s.io/api/core/v1" scv1 "k8s.io/api/storage/v1" - + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/test/e2e/framework" @@ -517,3 +517,60 @@ func deletePVCCSIJournalInPool(f *framework.Framework, pvc *v1.PersistentVolumeC return nil } + +func validateThickPVC(f *framework.Framework, pvc *v1.PersistentVolumeClaim, size string) error { + pvc.Namespace = f.UniqueName + pvc.Spec.Resources.Requests[v1.ResourceStorage] = resource.MustParse(size) + + err := createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout) + if err != nil { + return fmt.Errorf("failed to create PVC with error %w", err) + } + validateRBDImageCount(f, 1) + + // nothing has been written, but the image should be allocated + du, err := getRbdDu(f, pvc) + if err != nil { + return fmt.Errorf("failed to get allocations of RBD image: %w", err) + } else if du.UsedSize == 0 || du.UsedSize != du.ProvisionedSize { + return fmt.Errorf("backing RBD image is not thick-provisioned (%d/%d)", du.UsedSize, du.ProvisionedSize) + } + + // expanding the PVC should thick-allocate the expansion + // nolint:mnd // we want 2x the size so that extending is done + newSize := du.ProvisionedSize * 2 + err = expandPVCSize(f.ClientSet, pvc, fmt.Sprintf("%d", newSize), deployTimeout) + if err != nil { + return fmt.Errorf("failed to expand PVC: %w", err) + } + + // after expansion, the updated 'du' should be larger + du, err = getRbdDu(f, pvc) + if err != nil { + return fmt.Errorf("failed to get allocations of RBD image: %w", err) + } else if du.UsedSize != newSize { + return fmt.Errorf("backing RBD image is not extended thick-provisioned (%d/%d)", du.UsedSize, newSize) + } + + // thick provisioning allows for sparsifying + err = sparsifyBackingRBDImage(f, pvc) + if err != nil { + return fmt.Errorf("failed to sparsify RBD image: %w", err) + } + + // after sparsifying the image should not have any allocations + du, err = getRbdDu(f, pvc) + if err != nil { + return fmt.Errorf("backing RBD image is not thick-provisioned: %w", err) + } else if du.UsedSize != 0 { + return fmt.Errorf("backing RBD image was not sparsified (%d bytes allocated)", du.UsedSize) + } + + err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout) + if err != nil { + return fmt.Errorf("failed to delete PVC with error: %w", err) + } + validateRBDImageCount(f, 0) + + return nil +}