From 5abef0f53c1d77d804fee3658b2bc8298b4e792a Mon Sep 17 00:00:00 2001 From: karthik-us Date: Tue, 10 Oct 2023 16:39:37 +0530 Subject: [PATCH 1/2] cephfs: Fix cephfs PVC sizing Issue: The RoundOffCephFSVolSize() function omits the fractional part when calculating the size for cephfs volumes, leading to the created volume capacity to be lesser than the requested volume capacity. Fix: Consider the fractional part during the size calculation so the rounded off volume size will be greater than or equal to the requested volume size. Signed-off-by: karthik-us Fixes: #4179 --- internal/util/util.go | 4 ++-- internal/util/util_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/util/util.go b/internal/util/util.go index 659b4032080..2f927b5abe9 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -67,9 +67,9 @@ func RoundOffCephFSVolSize(bytes int64) int64 { return 4 * helpers.MiB } - bytes /= helpers.MiB + floatbytes := float64(bytes) / helpers.MiB - bytes = int64(math.Ceil(float64(bytes)/4) * 4) + bytes = int64(math.Ceil(floatbytes/4) * 4) return RoundOffBytes(bytes * helpers.MiB) } diff --git a/internal/util/util_test.go b/internal/util/util_test.go index d8ff374509e..aaacbda0f27 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -375,6 +375,16 @@ func TestRoundOffCephFSVolSize(t *testing.T) { 1677722, 4194304, // 4 MiB }, + { + "101MB conversion", + 101000000, + 104857600, // 100MiB + }, + { + "500MB conversion", + 500000000, + 503316480, // 480MiB + }, { "1023MiB conversion", 1072693248, From 0e1d5de7a7e4318596aed9e55e767b8c04c0447e Mon Sep 17 00:00:00 2001 From: karthik-us Date: Wed, 11 Oct 2023 21:30:47 +0530 Subject: [PATCH 2/2] e2e: To test 500MB PVC creation Adding e2e test to check for successful PVC creation of 500MB. Signed-off-by: karthik-us --- e2e/cephfs.go | 21 +++++++++++++++++++++ internal/util/util.go | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/e2e/cephfs.go b/e2e/cephfs.go index 7e596c1c94a..f4366c1d231 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -25,6 +25,7 @@ import ( snapapi "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1" . "github.com/onsi/ginkgo/v2" //nolint:golint // e2e uses By() and other Ginkgo functions v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/test/e2e/framework" @@ -2426,6 +2427,26 @@ var _ = Describe(cephfsType, func() { validateOmapCount(f, 0, cephfsType, metadataPool, volumesType) }) + By("Test 500MB PVC creation and check for PV and PVC binding", func() { + size := "500M" + pvc, err := loadPVC(pvcPath) + if err != nil { + framework.Failf("failed to load PVC: %v", err) + } + pvc.Namespace = f.UniqueName + pvc.Spec.Resources.Requests[v1.ResourceStorage] = resource.MustParse(size) + + err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout) + if err != nil { + framework.Failf("failed to create PVC: %v", err) + } + + err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout) + if err != nil { + framework.Failf("failed to delete PVC: %v", err) + } + }) + // FIXME: in case NFS testing is done, prevent deletion // of the CephFS filesystem and related pool. This can // probably be addressed in a nicer way, making sure diff --git a/internal/util/util.go b/internal/util/util.go index 2f927b5abe9..fa9aa40ea70 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -67,9 +67,9 @@ func RoundOffCephFSVolSize(bytes int64) int64 { return 4 * helpers.MiB } - floatbytes := float64(bytes) / helpers.MiB + bytesInFloat := float64(bytes) / helpers.MiB - bytes = int64(math.Ceil(floatbytes/4) * 4) + bytes = int64(math.Ceil(bytesInFloat/4) * 4) return RoundOffBytes(bytes * helpers.MiB) }