Skip to content

Commit 09736b7

Browse files
Add provisionedThroughput for hyperdisk
1 parent be08243 commit 09736b7

File tree

8 files changed

+174
-20
lines changed

8 files changed

+174
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ See Github [Issues](https://github.com/kubernetes-sigs/gcp-compute-persistent-di
6565
| disk-encryption-kms-key | Fully qualified resource identifier for the key to use to encrypt new disks. | Empty string. | Encrypt disk using Customer Managed Encryption Key (CMEK). See [GKE Docs](https://cloud.google.com/kubernetes-engine/docs/how-to/using-cmek#create_a_cmek_protected_attached_disk) for details. |
6666
| labels | `key1=value1,key2=value2` | | Labels allow you to assign custom [GCE Disk labels](https://cloud.google.com/compute/docs/labeling-resources). |
6767
| provisioned-iops-on-create | string (int64 format). Values typically between 10,000 and 120,000 | | Indicates how many IOPS to provision for the disk. See the [Extreme persistent disk documentation](https://cloud.google.com/compute/docs/disks/extreme-persistent-disk) for details, including valid ranges for IOPS. |
68-
68+
| provisioned-throughput-on-create | string (int64 format). Values typically between 1 and 7,124 mb per second | | Indicates how much throughput to provision for the disk. See the [hyperdisk documentation](TBD) for details, including valid ranges for throughput. |
6969

7070
### Topology
7171

pkg/common/parameters.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import (
2323

2424
const (
2525
// Parameters for StorageClass
26-
ParameterKeyType = "type"
27-
ParameterKeyReplicationType = "replication-type"
28-
ParameterKeyDiskEncryptionKmsKey = "disk-encryption-kms-key"
29-
ParameterKeyLabels = "labels"
30-
ParameterKeyProvisionedIOPSOnCreate = "provisioned-iops-on-create"
26+
ParameterKeyType = "type"
27+
ParameterKeyReplicationType = "replication-type"
28+
ParameterKeyDiskEncryptionKmsKey = "disk-encryption-kms-key"
29+
ParameterKeyLabels = "labels"
30+
ParameterKeyProvisionedIOPSOnCreate = "provisioned-iops-on-create"
31+
ParameterKeyProvisionedThroughputOnCreate = "provisioned-throughput-on-create"
3132

3233
// Parameters for VolumeSnapshotClass
3334
ParameterKeyStorageLocations = "storage-locations"
@@ -84,6 +85,9 @@ type DiskParameters struct {
8485
// Values: {int64}
8586
// Default: none
8687
ProvisionedIOPSOnCreate int64
88+
// Values: {int64}
89+
// Default: none
90+
ProvisionedThroughputOnCreate int64
8791
}
8892

8993
// SnapshotParameters contains normalized and defaulted parameters for snapshots
@@ -153,6 +157,12 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
153157
return p, fmt.Errorf("parameters contain invalid provisionedIOPSOnCreate parameter: %w", err)
154158
}
155159
p.ProvisionedIOPSOnCreate = paramProvisionedIOPSOnCreate
160+
case ParameterKeyProvisionedThroughputOnCreate:
161+
paramProvisionedThroughputOnCreate, err := ConvertMiBStringToInt64(v)
162+
if err != nil {
163+
return p, fmt.Errorf("parameters contain invalid provisionedThroughputOnCreate parameter: %w", err)
164+
}
165+
p.ProvisionedThroughputOnCreate = paramProvisionedThroughputOnCreate
156166
default:
157167
return p, fmt.Errorf("parameters contains invalid option %q", k)
158168
}

pkg/common/parameters_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ func TestExtractAndDefaultParameters(t *testing.T) {
9090
ProvisionedIOPSOnCreate: 10000,
9191
},
9292
},
93+
{
94+
name: "values from parameters, checking hyperdisk-throughput",
95+
parameters: map[string]string{ParameterKeyType: "hyperdisk-throughput", ParameterKeyReplicationType: "none", ParameterKeyDiskEncryptionKmsKey: "foo/key", ParameterKeyLabels: "key1=value1,key2=value2", ParameterKeyProvisionedThroughputOnCreate: "1000Mi"},
96+
labels: map[string]string{},
97+
expectParams: DiskParameters{
98+
DiskType: "hyperdisk-throughput",
99+
ReplicationType: "none",
100+
DiskEncryptionKMSKey: "foo/key",
101+
Tags: map[string]string{},
102+
Labels: map[string]string{
103+
"key1": "value1",
104+
"key2": "value2",
105+
},
106+
ProvisionedIOPSOnCreate: 1000,
107+
},
108+
},
93109
{
94110
name: "values from parameters, checking balanced pd",
95111
parameters: map[string]string{ParameterKeyType: "pd-balanced", ParameterKeyReplicationType: "regional-pd", ParameterKeyDiskEncryptionKmsKey: "foo/key"},

pkg/common/utils.go

+11
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,14 @@ func ConvertGiBStringToInt64(str string) (int64, error) {
261261
quantity := resource.MustParse(str)
262262
return volumehelpers.RoundUpToGiB(quantity)
263263
}
264+
265+
// ConvertMiBStringToInt64 converts a GiB string to int64
266+
func ConvertMiBStringToInt64(str string) (int64, error) {
267+
// Verify regex before
268+
match, _ := regexp.MatchString("^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$", str)
269+
if !match {
270+
return 0, fmt.Errorf("invalid string %s", str)
271+
}
272+
quantity := resource.MustParse(str)
273+
return volumehelpers.RoundUpToMiB(quantity)
274+
}

pkg/common/utils_test.go

+90
Original file line numberDiff line numberDiff line change
@@ -667,3 +667,93 @@ func TestConvertGiBStringToInt64(t *testing.T) {
667667
})
668668
}
669669
}
670+
671+
func TestConvertMiBStringToInt64(t *testing.T) {
672+
tests := []struct {
673+
desc string
674+
inputStr string
675+
expInt64 int64
676+
expectError bool
677+
}{
678+
{
679+
"valid number string",
680+
"10000",
681+
1,
682+
false,
683+
},
684+
{
685+
"round Ki to MiB",
686+
"1000Ki",
687+
1,
688+
false,
689+
},
690+
{
691+
"round k to MiB",
692+
"1000k",
693+
1,
694+
false,
695+
},
696+
{
697+
"round Mi to MiB",
698+
"1000Mi",
699+
1000,
700+
false,
701+
},
702+
{
703+
"round M to MiB",
704+
"1000M",
705+
954,
706+
false,
707+
},
708+
{
709+
"round G to MiB",
710+
"1000G",
711+
953675,
712+
false,
713+
},
714+
{
715+
"round Gi to MiB",
716+
"10000Gi",
717+
10240000,
718+
false,
719+
},
720+
{
721+
"round decimal to MiB",
722+
"1.2Gi",
723+
1229,
724+
false,
725+
},
726+
{
727+
"round big value to MiB",
728+
"8191Pi",
729+
8795019280384,
730+
false,
731+
},
732+
{
733+
"invalid empty string",
734+
"",
735+
10000,
736+
true,
737+
},
738+
{
739+
"invalid string",
740+
"ew%65",
741+
10000,
742+
true,
743+
},
744+
}
745+
for _, tc := range tests {
746+
t.Run(tc.desc, func(t *testing.T) {
747+
actualInt64, err := ConvertMiBStringToInt64(tc.inputStr)
748+
if err != nil && !tc.expectError {
749+
t.Errorf("Got error %v converting string to int64 %s; expect no error", err, tc.inputStr)
750+
}
751+
if err == nil && tc.expectError {
752+
t.Errorf("Got no error converting string to int64 %s; expect an error", tc.inputStr)
753+
}
754+
if err == nil && actualInt64 != tc.expInt64 {
755+
t.Errorf("Got %d for converting string to int64; expect %d", actualInt64, tc.expInt64)
756+
}
757+
})
758+
}
759+
}

pkg/gce-cloud-provider/compute/fake-gce.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,15 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, project string,
196196
}
197197

198198
computeDisk := &computev1.Disk{
199-
Name: volKey.Name,
200-
SizeGb: common.BytesToGbRoundUp(capBytes),
201-
Description: "Disk created by GCE-PD CSI Driver",
202-
Type: cloud.GetDiskTypeURI(project, volKey, params.DiskType),
203-
SourceDiskId: volumeContentSourceVolumeID,
204-
Status: cloud.mockDiskStatus,
205-
Labels: params.Labels,
206-
ProvisionedIops: params.ProvisionedIOPSOnCreate,
199+
Name: volKey.Name,
200+
SizeGb: common.BytesToGbRoundUp(capBytes),
201+
Description: "Disk created by GCE-PD CSI Driver",
202+
Type: cloud.GetDiskTypeURI(project, volKey, params.DiskType),
203+
SourceDiskId: volumeContentSourceVolumeID,
204+
Status: cloud.mockDiskStatus,
205+
Labels: params.Labels,
206+
ProvisionedIops: params.ProvisionedIOPSOnCreate,
207+
ProvisionedThroughput: params.ProvisionedThroughputOnCreate,
207208
}
208209

209210
if snapshotID != "" {

pkg/gce-cloud-provider/compute/gce-compute.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,13 @@ func (cloud *CloudProvider) insertRegionalDisk(
429429
}
430430

431431
diskToCreate := &computev1.Disk{
432-
Name: volKey.Name,
433-
SizeGb: common.BytesToGbRoundUp(capBytes),
434-
Description: description,
435-
Type: cloud.GetDiskTypeURI(cloud.project, volKey, params.DiskType),
436-
Labels: params.Labels,
437-
ProvisionedIops: params.ProvisionedIOPSOnCreate,
432+
Name: volKey.Name,
433+
SizeGb: common.BytesToGbRoundUp(capBytes),
434+
Description: description,
435+
Type: cloud.GetDiskTypeURI(cloud.project, volKey, params.DiskType),
436+
Labels: params.Labels,
437+
ProvisionedIops: params.ProvisionedIOPSOnCreate,
438+
ProvisionedThroughput: params.ProvisionedThroughputOnCreate,
438439
}
439440
if snapshotID != "" {
440441
_, snapshotType, _, err := common.SnapshotIDToProjectKey(snapshotID)

pkg/gce-pd-csi-driver/controller_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,31 @@ func TestCreateVolumeArguments(t *testing.T) {
817817
},
818818
expErrCode: codes.InvalidArgument,
819819
},
820+
{
821+
name: "success with provisionedThroughput parameter",
822+
req: &csi.CreateVolumeRequest{
823+
Name: name,
824+
CapacityRange: stdCapRange,
825+
VolumeCapabilities: stdVolCaps,
826+
Parameters: map[string]string{"labels": "key1=value1,key2=value2", "provisioned-throughput-on-create": "10000"},
827+
},
828+
expVol: &csi.Volume{
829+
CapacityBytes: common.GbToBytes(20),
830+
VolumeId: testVolumeID,
831+
VolumeContext: nil,
832+
AccessibleTopology: stdTopology,
833+
},
834+
},
835+
{
836+
name: "fail with malformed provisionedThroughput parameter",
837+
req: &csi.CreateVolumeRequest{
838+
Name: name,
839+
CapacityRange: stdCapRange,
840+
VolumeCapabilities: stdVolCaps,
841+
Parameters: map[string]string{"labels": "key1=value1,key2=value2", "provisioned-throughput-on-create": "dsfo3"},
842+
},
843+
expErrCode: codes.InvalidArgument,
844+
},
820845
}
821846

822847
// Run test cases

0 commit comments

Comments
 (0)