diff --git a/cmd/provisioner-localpv/app/helper_hostpath.go b/cmd/provisioner-localpv/app/helper_hostpath.go index a30acbf9..0287a6c0 100644 --- a/cmd/provisioner-localpv/app/helper_hostpath.go +++ b/cmd/provisioner-localpv/app/helper_hostpath.go @@ -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 @@ -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) diff --git a/cmd/provisioner-localpv/app/helper_test.go b/cmd/provisioner-localpv/app/helper_test.go index 2469621a..111ac920 100644 --- a/cmd/provisioner-localpv/app/helper_test.go +++ b/cmd/provisioner-localpv/app/helper_test.go @@ -55,7 +55,7 @@ func TestConvertToK(t *testing.T) { limit: "200%", pvcStorage: 5000000, }, - want: "10000k", + want: "9766k", wantErr: false, }, "Present limit grace with decimal%": { @@ -63,7 +63,7 @@ func TestConvertToK(t *testing.T) { 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": {