Skip to content

Commit

Permalink
fix(provisioning): remove Gi unit conversion for pv capacity (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: Yashpal Choudhary <yashpal.c1995@gmail.com>
  • Loading branch information
iyashu authored Sep 6, 2021
1 parent d4b4e4d commit d46f7e0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 2 additions & 10 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,6 @@ var SupportedVolumeCapabilityAccessModes = []*csi.VolumeCapability_AccessMode{

// getRoundedCapacity rounds the capacity on 1024 base
func getRoundedCapacity(size int64) int64 {

/*
* volblocksize and recordsize must be power of 2 from 512B to 1M
* so keeping the size in the form of Gi or Mi should be
* sufficient to make volsize multiple of volblocksize/recordsize.
*/
if size > Gi {
return ((size + Gi - 1) / Gi) * Gi
}

// Keeping minimum allocatable size as 1Mi (1024 * 1024)
return ((size + Mi - 1) / Mi) * Mi
}
Expand Down Expand Up @@ -569,6 +559,8 @@ func (cs *controller) GetCapacity(
}
}

// round off the available capacity to indicate allocatable vol size correctly.
availableCapacity = (availableCapacity / Mi) * Mi
return &csi.GetCapacityResponse{
AvailableCapacity: availableCapacity,
}, nil
Expand Down
4 changes: 1 addition & 3 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ func TestRoundOff(t *testing.T) {
"Minimum allocatable is 1Mi": {input: 1, expected: Mi},
"roundOff to same Mi size": {input: Mi, expected: Mi},
"roundOff to nearest Mi": {input: Mi + 1, expected: Mi * 2},
"roundOff to same Gi size": {input: Gi, expected: Gi},
"roundOff to nearest Gi": {input: Gi + 1, expected: Gi * 2},
"roundOff MB size": {input: 5 * MB, expected: 5 * Mi},
"roundOff GB size": {input: 5 * GB, expected: 5 * Gi},
"roundOff Gi size": {input: Gi + 512, expected: Gi + Mi},
}

for name, test := range tests {
Expand Down

0 comments on commit d46f7e0

Please sign in to comment.