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

fix: quota is not calculated correctly #161

Merged
merged 4 commits into from
Sep 6, 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
4 changes: 2 additions & 2 deletions cmd/provisioner-localpv/app/helper_hostpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (pOpts *HelperPodOptions) validateLimits() error {
pOpts.hardLimitGrace == "0k" {
// Hack: using convertToK() style converstion
// TODO: Refactor this section of the code
pvcStorageInK := math.Ceil(float64(pOpts.pvcStorage) / 1000)
pvcStorageInK := math.Ceil(float64(pOpts.pvcStorage) / 1024)
pvcStorageInKString := strconv.FormatFloat(pvcStorageInK, 'f', -1, 64) + "k"
pOpts.softLimitGrace, pOpts.hardLimitGrace = pvcStorageInKString, pvcStorageInKString
return nil
Expand Down Expand Up @@ -153,7 +153,7 @@ func convertToK(limit string, pvcStorage int64) (string, error) {
value *= float64(pvcStorage)
value /= 100
value += float64(pvcStorage)
value /= 1000
value /= 1024

value = math.Ceil(value)
valueString = strconv.FormatFloat(value, 'f', -1, 64)
Expand Down
4 changes: 2 additions & 2 deletions cmd/provisioner-localpv/app/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ func TestConvertToK(t *testing.T) {
limit: "200%",
pvcStorage: 5000000,
},
want: "10000k",
want: "9766k",
wantErr: false,
},
"Present limit grace with decimal%": {
args: args{
limit: ".5%",
pvcStorage: 1000,
},
want: "2k",
want: "1k", // the final result of limit can't be a float
wantErr: false,
},
"Present limit grace with invalid pattern": {
Expand Down