Skip to content

Commit

Permalink
cephfs: Fix cephfs PVC sizing
Browse files Browse the repository at this point in the history
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 <[email protected]>
Fixes: #4179
  • Loading branch information
karthik-us authored and mergify[bot] committed Oct 12, 2023
1 parent e79b963 commit 5a0eeb8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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
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)
}
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

0 comments on commit 5a0eeb8

Please sign in to comment.