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 <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2021-03-11 09:42:02 +01:00 committed by mergify[bot]
parent fe0f169875
commit abfe3ed9cb
2 changed files with 69 additions and 49 deletions

View File

@ -1391,60 +1391,23 @@ var _ = Describe("RBD", func() {
pvc, err := loadPVC(rawPvcPath) pvc, err := loadPVC(rawPvcPath)
if err != nil { if err != nil {
e2elog.Failf("failed to load PVC with error %v", err) 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)
} }
// expanding the PVC should thick-allocate the expansion pvcSizes := []string{
// nolint:mnd // we want 2x the size so that extending is done // original value from the yaml file (100MB)
newSize := du.ProvisionedSize * 2 "100Mi",
err = expandPVCSize(f.ClientSet, pvc, fmt.Sprintf("%d", newSize), deployTimeout) // half the size (50MB), is not stripe-size roundable
if err != nil { "50Mi",
e2elog.Failf("failed to expand PVC: %v", err)
} }
// after expansion, the updated 'du' should be larger for _, pvcSize := range pvcSizes {
du, err = getRbdDu(f, pvc) err = validateThickPVC(f, pvc, pvcSize)
if err != nil { if err != nil {
e2elog.Failf("failed to get allocations of RBD image: %v", err) e2elog.Failf("validating thick-provisioning failed: %v", err)
} else if du.UsedSize != newSize {
e2elog.Failf("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 {
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") err = deleteResource(rbdExamplePath + "storageclass.yaml")
if err != nil { if err != nil {
e2elog.Failf("failed to delete storageclass with error %v", err) e2elog.Failf("failed to delete storageclass with error %v", err)

View File

@ -9,7 +9,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
scv1 "k8s.io/api/storage/v1" scv1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
@ -517,3 +517,60 @@ func deletePVCCSIJournalInPool(f *framework.Framework, pvc *v1.PersistentVolumeC
return nil 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
}