Skip to content

Commit 1afd9ed

Browse files
Change iops params directly convert string to int64
1 parent 831d1ea commit 1afd9ed

File tree

6 files changed

+59
-41
lines changed

6 files changed

+59
-41
lines changed

pkg/common/parameters.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
152152
p.Labels[labelKey] = labelValue
153153
}
154154
case ParameterKeyProvisionedIOPSOnCreate:
155-
paramProvisionedIOPSOnCreate, err := ConvertGiBStringToInt64(v)
155+
paramProvisionedIOPSOnCreate, err := ConvertStringToInt64(v)
156156
if err != nil {
157157
return p, fmt.Errorf("parameters contain invalid provisionedIOPSOnCreate parameter: %w", err)
158158
}

pkg/common/parameters_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestExtractAndDefaultParameters(t *testing.T) {
7676
},
7777
{
7878
name: "values from parameters, checking pd-extreme",
79-
parameters: map[string]string{ParameterKeyType: "pd-extreme", ParameterKeyReplicationType: "none", ParameterKeyDiskEncryptionKmsKey: "foo/key", ParameterKeyLabels: "key1=value1,key2=value2", ParameterKeyProvisionedIOPSOnCreate: "10000Gi"},
79+
parameters: map[string]string{ParameterKeyType: "pd-extreme", ParameterKeyReplicationType: "none", ParameterKeyDiskEncryptionKmsKey: "foo/key", ParameterKeyLabels: "key1=value1,key2=value2", ParameterKeyProvisionedIOPSOnCreate: "10k"},
8080
labels: map[string]string{},
8181
expectParams: DiskParameters{
8282
DiskType: "pd-extreme",

pkg/common/utils.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,15 @@ func ValidateSnapshotType(snapshotType string) error {
251251
}
252252
}
253253

254-
// ConvertGiBStringToInt64 converts a GiB string to int64
255-
func ConvertGiBStringToInt64(str string) (int64, error) {
254+
// ConvertStringToInt64 converts a string to int64
255+
func ConvertStringToInt64(str string) (int64, error) {
256256
// Verify regex before
257257
match, _ := regexp.MatchString("^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$", str)
258258
if !match {
259259
return 0, fmt.Errorf("invalid string %s", str)
260260
}
261261
quantity := resource.MustParse(str)
262-
return volumehelpers.RoundUpToGiB(quantity)
262+
return volumehelpers.RoundUpToB(quantity)
263263
}
264264

265265
// ConvertMiBStringToInt64 converts a GiB string to int64

pkg/common/utils_test.go

+52-34
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ func TestSnapshotStorageLocations(t *testing.T) {
578578
}
579579
}
580580

581-
func TestConvertGiBStringToInt64(t *testing.T) {
581+
func TestConvertStringToInt64(t *testing.T) {
582582
tests := []struct {
583583
desc string
584584
inputStr string
@@ -588,73 +588,91 @@ func TestConvertGiBStringToInt64(t *testing.T) {
588588
{
589589
"valid number string",
590590
"10000",
591-
1,
591+
10000,
592592
false,
593593
},
594594
{
595-
"round Ki to GiB",
596-
"1000Ki",
597-
1,
595+
"round M to number",
596+
"1M",
597+
1000000,
598598
false,
599599
},
600600
{
601-
"round k to GiB",
602-
"1000k",
601+
"round m to number",
602+
"1m",
603603
1,
604604
false,
605605
},
606606
{
607-
"round Mi to GiB",
608-
"1000Mi",
609-
1,
607+
"round k to number",
608+
"1k",
609+
1000,
610610
false,
611611
},
612612
{
613-
"round M to GiB",
614-
"1000M",
615-
1,
616-
false,
613+
"invalid empty string",
614+
"",
615+
10000,
616+
true,
617617
},
618618
{
619-
"round G to GiB",
620-
"1000G",
621-
932,
619+
"invalid string",
620+
"ew%65",
621+
10000,
622+
true,
623+
},
624+
{
625+
"round Ki to number",
626+
"1Ki",
627+
1024,
622628
false,
623629
},
624630
{
625-
"round Gi to GiB",
626-
"10000Gi",
631+
"round k to number",
632+
"10k",
627633
10000,
628634
false,
629635
},
630636
{
631-
"round decimal to GiB",
632-
"1.2Gi",
633-
2,
637+
"round Mi to number",
638+
"10Mi",
639+
10485760,
634640
false,
635641
},
636642
{
637-
"round big value to GiB",
638-
"8191Pi",
639-
8588886016,
643+
"round M to number",
644+
"10M",
645+
10000000,
640646
false,
641647
},
642648
{
643-
"invalid empty string",
644-
"",
645-
10000,
646-
true,
649+
"round G to number",
650+
"10G",
651+
10000000000,
652+
false,
647653
},
648654
{
649-
"invalid string",
650-
"ew%65",
651-
10000,
652-
true,
655+
"round Gi to number",
656+
"100Gi",
657+
107374182400,
658+
false,
659+
},
660+
{
661+
"round decimal to number",
662+
"1.2Gi",
663+
1288490189,
664+
false,
665+
},
666+
{
667+
"round big value to number",
668+
"8191Pi",
669+
9222246136947933184,
670+
false,
653671
},
654672
}
655673
for _, tc := range tests {
656674
t.Run(tc.desc, func(t *testing.T) {
657-
actualInt64, err := ConvertGiBStringToInt64(tc.inputStr)
675+
actualInt64, err := ConvertStringToInt64(tc.inputStr)
658676
if err != nil && !tc.expectError {
659677
t.Errorf("Got error %v converting string to int64 %s; expect no error", err, tc.inputStr)
660678
}

test/e2e/tests/single_zone_e2e_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const (
5151
readyState = "READY"
5252
standardDiskType = "pd-standard"
5353
extremeDiskType = "pd-extreme"
54-
provisionedIOPSOnCreate = "100000Gi"
54+
provisionedIOPSOnCreate = "100000"
5555
provisionedIOPSOnCreateInt = int64(100000)
5656

5757
defaultEpsilon = 500000000 // 500M

test/k8s-integration/config/sc-extreme.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
provisioner: pd.csi.storage.gke.io
66
parameters:
77
type: pd-extreme
8-
provisioned-iops-on-create: '10000Gi'
8+
provisioned-iops-on-create: '10000'
99
# Add labels for testing.
1010
labels: key1=value1,key2=value2
1111
volumeBindingMode: WaitForFirstConsumer

0 commit comments

Comments
 (0)