Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cephfs: Fix cephfs PVC sizing #4180

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions e2e/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func RoundOffCephFSVolSize(bytes int64) int64 {
return 4 * helpers.MiB
}

bytes /= helpers.MiB
bytesInFloat := float64(bytes) / helpers.MiB

bytes = int64(math.Ceil(float64(bytes)/4) * 4)
bytes = int64(math.Ceil(bytesInFloat/4) * 4)

return RoundOffBytes(bytes * helpers.MiB)
}
Expand Down
10 changes: 10 additions & 0 deletions internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down