Skip to content
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
6 changes: 3 additions & 3 deletions pkg/gce-pd-csi-driver/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,11 @@ func isCachingSetup(mainLvName string) (error, bool) {
return nil, false
}

// cacheSize is always in GiB
func fetchChunkSizeKiB(cacheSize string) (string, error) {
var chunkSize float64

cacheSize = strings.TrimSuffix(cacheSize, "GiB")
cacheSizeInt, err := strconv.ParseInt(cacheSize, 10, 64)
if err != nil {
return "0", err
Expand Down Expand Up @@ -691,10 +693,8 @@ func addRaidedLSSDToVg(vgName, lssdPath string) error {

func fetchPvSizeGiB() (string, error) {
args := []string{
"--select",
"-o",
"-o", "pv_name,pv_size",
"--noheadings",
"pv_size",
"--units=b",
}
// RAIDed device is always registered with its /dev/md127 equivalent in VG so cannot check it directly based on the RAIDed LSSD path which could be /dev/md/csi-driver-data-cache
Expand Down
13 changes: 9 additions & 4 deletions pkg/gce-pd-csi-driver/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,29 @@ func TestFetchChunkSizeKiB(t *testing.T) {
}{
{
name: "chunk size is in the allowed range",
cacheSize: "500",
cacheSize: "500GiB",
expChunkSize: "512KiB", //range defined in fetchChunkSizeKiB
},
{
name: "chunk size is set to the range ceil",
cacheSize: "30000000",
cacheSize: "30000000GiB",
expChunkSize: "1048576KiB", //range defined in fetchChunkSizeKiB - max 1GiB
},
{
name: "chunk size is set to the allowed range floor",
cacheSize: "100",
cacheSize: "100GiB",
expChunkSize: "160KiB", //range defined in fetchChunkSizeKiB - min 160 KiB
},
{
name: "cacheSize set to KiB also sets the chunk size to range floor",
cacheSize: "1",
cacheSize: "1GiB",
expChunkSize: "160KiB", //range defined in fetchChunkSizeKiB - min 160 KiB
},
{
name: "chunk size with GiB string parses correctly",
cacheSize: "375GiB",
expChunkSize: "384KiB",
},
{
name: "invalid cacheSize",
cacheSize: "fdfsdKi",
Expand Down