Skip to content

Commit 7649ee9

Browse files
Add provisionedThroughput for hyperdisk
1 parent 18ebd8a commit 7649ee9

File tree

8 files changed

+174
-20
lines changed

8 files changed

+174
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 15 additions & 5 deletions
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"
@@ -79,6 +80,9 @@ type DiskParameters struct {
7980
// Values: {int64}
8081
// Default: none
8182
ProvisionedIOPSOnCreate int64
83+
// Values: {int64}
84+
// Default: none
85+
ProvisionedThroughputOnCreate int64
8286
}
8387

8488
// SnapshotParameters contains normalized and defaulted parameters for snapshots
@@ -145,6 +149,12 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
145149
return p, fmt.Errorf("parameters contain invalid provisionedIOPSOnCreate parameter: %w", err)
146150
}
147151
p.ProvisionedIOPSOnCreate = paramProvisionedIOPSOnCreate
152+
case ParameterKeyProvisionedThroughputOnCreate:
153+
paramProvisionedThroughputOnCreate, err := ConvertMiBStringToInt64(v)
154+
if err != nil {
155+
return p, fmt.Errorf("parameters contain invalid provisionedThroughputOnCreate parameter: %w", err)
156+
}
157+
p.ProvisionedThroughputOnCreate = paramProvisionedThroughputOnCreate
148158
default:
149159
return p, fmt.Errorf("parameters contains invalid option %q", k)
150160
}

pkg/common/parameters_test.go

Lines changed: 16 additions & 0 deletions
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+
ProvisionedThroughputOnCreate: 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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,14 @@ func ConvertGiBStringToInt64(str string) (int64, error) {
281281
quantity := resource.MustParse(str)
282282
return volumehelpers.RoundUpToGiB(quantity)
283283
}
284+
285+
// ConvertMiBStringToInt64 converts a GiB string to int64
286+
func ConvertMiBStringToInt64(str string) (int64, error) {
287+
// Verify regex before
288+
match, _ := regexp.MatchString("^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$", str)
289+
if !match {
290+
return 0, fmt.Errorf("invalid string %s", str)
291+
}
292+
quantity := resource.MustParse(str)
293+
return volumehelpers.RoundUpToMiB(quantity)
294+
}

pkg/common/utils_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,93 @@ func TestConvertGiBStringToInt64(t *testing.T) {
721721
})
722722
}
723723
}
724+
725+
func TestConvertMiBStringToInt64(t *testing.T) {
726+
tests := []struct {
727+
desc string
728+
inputStr string
729+
expInt64 int64
730+
expectError bool
731+
}{
732+
{
733+
"valid number string",
734+
"10000",
735+
1,
736+
false,
737+
},
738+
{
739+
"round Ki to MiB",
740+
"1000Ki",
741+
1,
742+
false,
743+
},
744+
{
745+
"round k to MiB",
746+
"1000k",
747+
1,
748+
false,
749+
},
750+
{
751+
"round Mi to MiB",
752+
"1000Mi",
753+
1000,
754+
false,
755+
},
756+
{
757+
"round M to MiB",
758+
"1000M",
759+
954,
760+
false,
761+
},
762+
{
763+
"round G to MiB",
764+
"1000G",
765+
953675,
766+
false,
767+
},
768+
{
769+
"round Gi to MiB",
770+
"10000Gi",
771+
10240000,
772+
false,
773+
},
774+
{
775+
"round decimal to MiB",
776+
"1.2Gi",
777+
1229,
778+
false,
779+
},
780+
{
781+
"round big value to MiB",
782+
"8191Pi",
783+
8795019280384,
784+
false,
785+
},
786+
{
787+
"invalid empty string",
788+
"",
789+
10000,
790+
true,
791+
},
792+
{
793+
"invalid string",
794+
"ew%65",
795+
10000,
796+
true,
797+
},
798+
}
799+
for _, tc := range tests {
800+
t.Run(tc.desc, func(t *testing.T) {
801+
actualInt64, err := ConvertMiBStringToInt64(tc.inputStr)
802+
if err != nil && !tc.expectError {
803+
t.Errorf("Got error %v converting string to int64 %s; expect no error", err, tc.inputStr)
804+
}
805+
if err == nil && tc.expectError {
806+
t.Errorf("Got no error converting string to int64 %s; expect an error", tc.inputStr)
807+
}
808+
if err == nil && actualInt64 != tc.expInt64 {
809+
t.Errorf("Got %d for converting string to int64; expect %d", actualInt64, tc.expInt64)
810+
}
811+
})
812+
}
813+
}

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

Lines changed: 9 additions & 8 deletions
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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,13 @@ func (cloud *CloudProvider) insertRegionalDisk(
443443
}
444444

445445
diskToCreate := &computev1.Disk{
446-
Name: volKey.Name,
447-
SizeGb: common.BytesToGbRoundUp(capBytes),
448-
Description: description,
449-
Type: cloud.GetDiskTypeURI(cloud.project, volKey, params.DiskType),
450-
Labels: params.Labels,
451-
ProvisionedIops: params.ProvisionedIOPSOnCreate,
446+
Name: volKey.Name,
447+
SizeGb: common.BytesToGbRoundUp(capBytes),
448+
Description: description,
449+
Type: cloud.GetDiskTypeURI(cloud.project, volKey, params.DiskType),
450+
Labels: params.Labels,
451+
ProvisionedIops: params.ProvisionedIOPSOnCreate,
452+
ProvisionedThroughput: params.ProvisionedThroughputOnCreate,
452453
}
453454
if snapshotID != "" {
454455
_, snapshotType, _, err := common.SnapshotIDToProjectKey(snapshotID)

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

Lines changed: 25 additions & 0 deletions
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)