Skip to content

Commit e3b12d4

Browse files
Add provisionedIops for pd-extreme
1 parent cf106c9 commit e3b12d4

File tree

15 files changed

+891
-22
lines changed

15 files changed

+891
-22
lines changed

README.md

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

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
gopkg.in/gcfg.v1 v1.2.3
2222
k8s.io/apimachinery v0.24.1
2323
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
24+
k8s.io/cloud-provider v0.24.1
2425
k8s.io/component-base v0.24.1
2526
k8s.io/klog/v2 v2.60.1
2627
k8s.io/kubernetes v1.24.1

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,7 @@ k8s.io/apiserver v0.24.1/go.mod h1:dQWNMx15S8NqJMp0gpYfssyvhYnkilc1LpExd/dkLh0=
24322432
k8s.io/cli-runtime v0.24.1/go.mod h1:14aVvCTqkA7dNXY51N/6hRY3GUjchyWDOwW84qmR3bs=
24332433
k8s.io/client-go v0.24.1 h1:w1hNdI9PFrzu3OlovVeTnf4oHDt+FJLd9Ndluvnb42E=
24342434
k8s.io/client-go v0.24.1/go.mod h1:f1kIDqcEYmwXS/vTbbhopMUbhKp2JhOeVTfxgaCIlF8=
2435+
k8s.io/cloud-provider v0.24.1 h1:SaQNq2Ax+epdY9wFngwN9GWpOVnM72hUqr2qy20cOvg=
24352436
k8s.io/cloud-provider v0.24.1/go.mod h1:h5m/KIiwiQ76hpUBsgrwm/rxteIfJG9kJQ/+/w1as2M=
24362437
k8s.io/cluster-bootstrap v0.24.1/go.mod h1:uq2PiYfKh8ZLb6DBU/3/2Z1DkMqXkTOHLemalC4tOgE=
24372438
k8s.io/code-generator v0.24.1/go.mod h1:dpVhs00hTuTdTY6jvVxvTFCk6gSMrtfRydbhZwHI15w=

pkg/common/parameters.go

Lines changed: 14 additions & 4 deletions
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"
@@ -75,6 +76,9 @@ type DiskParameters struct {
7576
// Values: {map[string]string}
7677
// Default: ""
7778
Labels map[string]string
79+
// Values: {int64}
80+
// Default: none
81+
ProvisionedIOPSOnCreate int64
7882
}
7983

8084
// SnapshotParameters contains normalized and defaulted parameters for snapshots
@@ -135,6 +139,12 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
135139
for labelKey, labelValue := range paramLabels {
136140
p.Labels[labelKey] = labelValue
137141
}
142+
case ParameterKeyProvisionedIOPSOnCreate:
143+
paramProvisionedIOPSOnCreate, err := ConvertGiBStringToInt64(v)
144+
if err != nil {
145+
return p, fmt.Errorf("parameters contain invalid provisionedIOPSOnCreate parameter: %w", err)
146+
}
147+
p.ProvisionedIOPSOnCreate = paramProvisionedIOPSOnCreate
138148
default:
139149
return p, fmt.Errorf("parameters contains invalid option %q", k)
140150
}

pkg/common/parameters_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: "10000Gi"},
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.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
"strings"
2323

2424
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
25+
"k8s.io/apimachinery/pkg/api/resource"
2526
"k8s.io/apimachinery/pkg/util/sets"
27+
volumehelpers "k8s.io/cloud-provider/volume/helpers"
2628
)
2729

2830
const (
@@ -268,3 +270,14 @@ func ParseMachineType(machineTypeUrl string) (string, error) {
268270
}
269271
return machineType[1], nil
270272
}
273+
274+
// ConvertGiBStringToInt64 converts a GiB string to int64
275+
func ConvertGiBStringToInt64(str string) (int64, error) {
276+
// Verify regex before
277+
match, _ := regexp.MatchString("^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$", str)
278+
if !match {
279+
return 0, fmt.Errorf("invalid string %s", str)
280+
}
281+
quantity := resource.MustParse(str)
282+
return volumehelpers.RoundUpToGiB(quantity)
283+
}

pkg/common/utils_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,93 @@ func TestParseMachineType(t *testing.T) {
631631
})
632632
}
633633
}
634+
635+
func TestConvertGiBStringToInt64(t *testing.T) {
636+
tests := []struct {
637+
desc string
638+
inputStr string
639+
expInt64 int64
640+
expectError bool
641+
}{
642+
{
643+
"valid number string",
644+
"10000",
645+
1,
646+
false,
647+
},
648+
{
649+
"round Ki to GiB",
650+
"1000Ki",
651+
1,
652+
false,
653+
},
654+
{
655+
"round k to GiB",
656+
"1000k",
657+
1,
658+
false,
659+
},
660+
{
661+
"round Mi to GiB",
662+
"1000Mi",
663+
1,
664+
false,
665+
},
666+
{
667+
"round M to GiB",
668+
"1000M",
669+
1,
670+
false,
671+
},
672+
{
673+
"round G to GiB",
674+
"1000G",
675+
932,
676+
false,
677+
},
678+
{
679+
"round Gi to GiB",
680+
"10000Gi",
681+
10000,
682+
false,
683+
},
684+
{
685+
"round decimal to GiB",
686+
"1.2Gi",
687+
2,
688+
false,
689+
},
690+
{
691+
"round big value to GiB",
692+
"8191Pi",
693+
8588886016,
694+
false,
695+
},
696+
{
697+
"invalid empty string",
698+
"",
699+
10000,
700+
true,
701+
},
702+
{
703+
"invalid string",
704+
"ew%65",
705+
10000,
706+
true,
707+
},
708+
}
709+
for _, tc := range tests {
710+
t.Run(tc.desc, func(t *testing.T) {
711+
actualInt64, err := ConvertGiBStringToInt64(tc.inputStr)
712+
if err != nil && !tc.expectError {
713+
t.Errorf("Got error %v converting string to int64 %s; expect no error", err, tc.inputStr)
714+
}
715+
if err == nil && tc.expectError {
716+
t.Errorf("Got no error converting string to int64 %s; expect an error", tc.inputStr)
717+
}
718+
if err == nil && actualInt64 != tc.expInt64 {
719+
t.Errorf("Got %d for converting string to int64; expect %d", actualInt64, tc.expInt64)
720+
}
721+
})
722+
}
723+
}

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

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,12 @@ 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,
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,
451452
}
452453
if snapshotID != "" {
453454
_, 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
@@ -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)