Skip to content

Commit

Permalink
fix: quota is not calculated correctly (#161)
Browse files Browse the repository at this point in the history
* Update helper_hostpath.go

Signed-off-by: 张铭 <zhang.ming@cestc.cn>

* Update helper_hostpath.go

Signed-off-by: 张铭 <zhang.ming@cestc.cn>

* Update helper_test.go

Signed-off-by: 张铭 <zhang.ming@cestc.cn>

* add comments

Signed-off-by: 张铭 <zhangming860612@gmail.com>
Signed-off-by: 张铭 <zhang.ming@cestc.cn>

---------

Signed-off-by: 张铭 <zhang.ming@cestc.cn>
Signed-off-by: 张铭 <zhangming860612@gmail.com>
Co-authored-by: 张铭 <zhang.ming@cestc.cn>
  • Loading branch information
MingZhang-YBPS and MingZhang-YBPS committed Sep 6, 2023
1 parent 177962f commit a4a9273
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
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

0 comments on commit a4a9273

Please sign in to comment.