Skip to content

Commit c2d4dee

Browse files
Add provisionedIops for pd-extreme
1 parent 8def5ed commit c2d4dee

File tree

7 files changed

+111
-24
lines changed

7 files changed

+111
-24
lines changed

README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ See Github [Issues](https://github.com/kubernetes-sigs/gcp-compute-persistent-di
5858

5959
### CreateVolume Parameters
6060

61-
| Parameter | Values | Default | Description |
62-
|------------------|---------------------------|---------------|----------------------------------------------------------------------------------------------------|
63-
| type | Any PD type (see [GCP documentation](https://cloud.google.com/compute/docs/disks#disk-types)), eg `pd-ssd` `pd-balanced` | `pd-standard` | Type allows you to choose between standard Persistent Disks or Solid State Drive Persistent Disks |
64-
| replication-type | `none` OR `regional-pd` | `none` | Replication type allows you to choose between Zonal Persistent Disks or Regional Persistent Disks |
65-
| 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. |
66-
| labels | `key1=value1,key2=value2` | | Labels allow you to assign custom [GCE Disk labels](https://cloud.google.com/compute/docs/labeling-resources). |
61+
| Parameter | Values | Default | Description |
62+
|-----------------------------|---------------------------|---------------|----------------------------------------------------------------------------------------------------|
63+
| type | Any PD type (see [GCP documentation](https://cloud.google.com/compute/docs/disks#disk-types)), eg `pd-ssd` `pd-balanced` | `pd-standard` | Type allows you to choose between standard Persistent Disks or Solid State Drive Persistent Disks |
64+
| replication-type | `none` OR `regional-pd` | `none` | Replication type allows you to choose between Zonal Persistent Disks or Regional Persistent Disks |
65+
| 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. |
66+
| labels | `key1=value1,key2=value2` | | Labels allow you to assign custom [GCE Disk labels](https://cloud.google.com/compute/docs/labeling-resources). |
67+
| 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+
6769

6870
### Topology
6971

pkg/common/parameters.go

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

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

3132
// Parameters for VolumeSnapshotClass
3233
ParameterKeyStorageLocations = "storage-locations"
@@ -80,6 +81,9 @@ type DiskParameters struct {
8081
// Values: {map[string]string}
8182
// Default: ""
8283
Labels map[string]string
84+
// Values: {int64}
85+
// Default: none
86+
ProvisionedIOPSOnCreate int64
8387
}
8488

8589
// SnapshotParameters contains normalized and defaulted parameters for snapshots
@@ -95,7 +99,7 @@ type SnapshotParameters struct {
9599
// put them into a well defined struct making sure to default unspecified fields.
96100
// extraVolumeLabels are added as labels; if there are also labels specified in
97101
// parameters, any matching extraVolumeLabels will be overridden.
98-
func ExtractAndDefaultParameters(parameters map[string]string, driverName string, extraVolumeLabels map[string]string) (DiskParameters, error) {
102+
func ExtractAndDefaultParameters(parameters map[string]interface{}, driverName string, extraVolumeLabels map[string]string) (DiskParameters, error) {
99103
p := DiskParameters{
100104
DiskType: "pd-standard", // Default
101105
ReplicationType: replicationTypeNone, // Default
@@ -143,6 +147,8 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
143147
for labelKey, labelValue := range paramLabels {
144148
p.Labels[labelKey] = labelValue
145149
}
150+
case ParameterKeyProvisionedIOPSOnCreate:
151+
p.ProvisionedIOPSOnCreate = v.(int64)
146152
default:
147153
return p, fmt.Errorf("parameters contains invalid option %q", k)
148154
}

pkg/common/parameters_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestExtractAndDefaultParameters(t *testing.T) {
5555
},
5656
{
5757
name: "random keys",
58-
parameters: map[string]string{ParameterKeyType: "", "foo": "", ParameterKeyDiskEncryptionKmsKey: "", ParameterKeyLabels: ""},
58+
parameters: map[string]string{ParameterKeyType: "", "foo": "", ParameterKeyDiskEncryptionKmsKey: "", ParameterKeyLabels: "", ParameterKeyProvisionedIOPSOnCreate: ""},
5959
labels: map[string]string{},
6060
expectErr: true,
6161
},
@@ -74,6 +74,22 @@ func TestExtractAndDefaultParameters(t *testing.T) {
7474
},
7575
},
7676
},
77+
{
78+
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: "10000"},
80+
labels: map[string]string{},
81+
expectParams: DiskParameters{
82+
DiskType: "pd-extreme",
83+
ReplicationType: "none",
84+
DiskEncryptionKMSKey: "foo/key",
85+
Tags: map[string]string{},
86+
Labels: map[string]string{
87+
"key1": "value1",
88+
"key2": "value2",
89+
},
90+
ProvisionedIOPSOnCreate: 10000,
91+
},
92+
},
7793
{
7894
name: "values from parameters, checking balanced pd",
7995
parameters: map[string]string{ParameterKeyType: "pd-balanced", ParameterKeyReplicationType: "regional-pd", ParameterKeyDiskEncryptionKmsKey: "foo/key"},

pkg/common/utils_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -577,3 +577,39 @@ func TestSnapshotStorageLocations(t *testing.T) {
577577
})
578578
}
579579
}
580+
581+
func TestConvertStringToInt64(t *testing.T) {
582+
tests := []struct {
583+
desc string
584+
inputStr string
585+
expInt64 int64
586+
expectError bool
587+
}{
588+
{
589+
"valid string",
590+
"10000",
591+
10000,
592+
false,
593+
},
594+
{
595+
"invalid string",
596+
"ew%65",
597+
10000,
598+
true,
599+
},
600+
}
601+
for _, tc := range tests {
602+
t.Run(tc.desc, func(t *testing.T) {
603+
actualInt64, err := ConvertStringToInt64(tc.inputStr)
604+
if err != nil && !tc.expectError {
605+
t.Errorf("Got error %v converting string to int64 %s; expect no error", err, tc.inputStr)
606+
}
607+
if err == nil && tc.expectError {
608+
t.Errorf("Got no error converting string to int64 %s; expect an error", tc.inputStr)
609+
}
610+
if err == nil && actualInt64 != tc.expInt64 {
611+
t.Errorf("Got %d for converting string to int64; expect %d", actualInt64, tc.expInt64)
612+
}
613+
})
614+
}
615+
}

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,14 @@ 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,
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,
206207
}
207208

208209
if snapshotID != "" {

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,12 @@ 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,
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,
437438
}
438439
if snapshotID != "" {
439440
_, snapshotType, _, err := common.SnapshotIDToProjectKey(snapshotID)

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

+25
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,31 @@ func TestCreateVolumeArguments(t *testing.T) {
792792
},
793793
expErrCode: codes.InvalidArgument,
794794
},
795+
{
796+
name: "success with provisionedIops parameter",
797+
req: &csi.CreateVolumeRequest{
798+
Name: name,
799+
CapacityRange: stdCapRange,
800+
VolumeCapabilities: stdVolCaps,
801+
Parameters: map[string]string{"labels": "key1=value1,key2=value2", "provisioned-iops-on-create": "10000"},
802+
},
803+
expVol: &csi.Volume{
804+
CapacityBytes: common.GbToBytes(20),
805+
VolumeId: testVolumeID,
806+
VolumeContext: nil,
807+
AccessibleTopology: stdTopology,
808+
},
809+
},
810+
{
811+
name: "fail with malformed provisionedIops parameter",
812+
req: &csi.CreateVolumeRequest{
813+
Name: name,
814+
CapacityRange: stdCapRange,
815+
VolumeCapabilities: stdVolCaps,
816+
Parameters: map[string]string{"labels": "key1=value1,key2=value2", "provisioned-iops-on-create": "dsfo3"},
817+
},
818+
expErrCode: codes.InvalidArgument,
819+
},
795820
}
796821

797822
// Run test cases

0 commit comments

Comments
 (0)