Skip to content

Commit fd1908c

Browse files
karkunpavandfajmon
authored andcommitted
UPSTREAM: <carry>: Changes to support hyperdisk multi-writer mode
Upstream PR: kubernetes-sigs#1919 Added fixes for test key handling. Multiwriter Test Update (openshift#3) * Changes update the tests to use two contexts, one for multiwriter and one for the existing tests. This was deemed necessary as only some disks can support multi-writer, and only some VM shapes can support said disks. Update parameters.go Fixing a linting issue. Karkunpavan (openshift#4) * Removing alpha disk from tests. * Changes setup the test to run with hyperdisk extreme. * Updates the disk type back to balanced, as HDX doesn't support multi writer. * Moving over to m1 megamem as thats the only type of machine that can support all needed disk types. * Changes update the tests to use two contexts, one for multiwriter and one for the existing tests. This was deemed necessary as only some disks can support multi-writer, and only some VM shapes can support said disks. * Changes update the tests to use two contexts, one for multiwriter and one for the existing tests. This was deemed necessary as only some disks can support multi-writer, and only some VM shapes can support said disks. * Fixing some git oddness * Fixing some formatting. * More formatting fixes. * Hopefully last changes for formatting. * Fixing linting issue. * Cleaning up un-used / un-needed GetMultiWriter test function. Completley removing the multiwriter check from fake-gce. Changes remove the API version concept from GetDisk and InsertDisk, now just defaults to using the Beta API. Cleaning up un-used variables. pkg/gce-cloud-provider/compute/fake-gce.go Addressing comments around GetMultiWriter checks. Removing multi-writer as a disk paramter. Fixing rebasing issues. Merge branch 'master' into followup Merge branch 'kubernetes-sigs:master' into hd-mw Merge branch 'kubernetes-sigs:master' into hd-mw Merge pull request openshift#1 from karkunpavan/karkunpavan Added fixes for test key handling.
1 parent 14fa4d9 commit fd1908c

26 files changed

+731
-280
lines changed

cmd/gce-pd-csi-driver/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var (
7272
formatAndMountTimeout = flag.Duration("format-and-mount-timeout", 1*time.Minute, "The maximum duration of a format and mount operation before another such operation will be started. Used only if --serialize-format-and-mount")
7373
fallbackRequisiteZonesFlag = flag.String("fallback-requisite-zones", "", "Comma separated list of requisite zones that will be used if there are not sufficient zones present in requisite topologies when provisioning a disk")
7474
enableStoragePoolsFlag = flag.Bool("enable-storage-pools", false, "If set to true, the CSI Driver will allow volumes to be provisioned in Storage Pools")
75+
enableHdHAFlag = flag.Bool("allow-hdha-provisioning", false, "If set to true, will allow the driver to provision Hyperdisk-balanced High Availability disks")
7576

7677
multiZoneVolumeHandleDiskTypesFlag = flag.String("multi-zone-volume-handle-disk-types", "", "Comma separated list of allowed disk types that can use the multi-zone volumeHandle. Used only if --multi-zone-volume-handle-enable")
7778
multiZoneVolumeHandleEnableFlag = flag.Bool("multi-zone-volume-handle-enable", false, "If set to true, the multi-zone volumeHandle feature will be enabled")
@@ -220,7 +221,7 @@ func handle() {
220221
}
221222
initialBackoffDuration := time.Duration(*errorBackoffInitialDurationMs) * time.Millisecond
222223
maxBackoffDuration := time.Duration(*errorBackoffMaxDurationMs) * time.Millisecond
223-
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, multiZoneVolumeHandleConfig, listVolumesConfig, provisionableDisksConfig)
224+
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, multiZoneVolumeHandleConfig, listVolumesConfig, provisionableDisksConfig, *enableHdHAFlag)
224225
} else if *cloudConfigFilePath != "" {
225226
klog.Warningf("controller service is disabled but cloud config given - it has no effect")
226227
}

deploy/kubernetes/images/prow-stable-sidecar-rc-master/image.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ metadata:
4848
imageTag:
4949
name: registry.k8s.io/cloud-provider-gcp/gcp-compute-persistent-disk-csi-driver
5050
newName: gcr.io/k8s-staging-cloud-provider-gcp/gcp-compute-persistent-disk-csi-driver
51-
newTag: "v1.14.2-rc1"
51+
newTag: "v1.15.4-rc1"
5252
---
5353

pkg/common/parameters.go

+22
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
)
2323

2424
const (
25+
// Disk Params
26+
ParameterAccessMode = "access-mode"
27+
2528
// Parameters for StorageClass
2629
ParameterKeyType = "type"
2730
ParameterKeyReplicationType = "replication-type"
@@ -34,6 +37,7 @@ const (
3437
ParameterKeyStoragePools = "storage-pools"
3538
ParameterKeyResourceTags = "resource-tags"
3639
ParameterKeyEnableMultiZoneProvisioning = "enable-multi-zone-provisioning"
40+
ParameterHdHADiskType = "hyperdisk-balanced-high-availability"
3741

3842
// Parameters for VolumeSnapshotClass
3943
ParameterKeyStorageLocations = "storage-locations"
@@ -106,6 +110,13 @@ type DiskParameters struct {
106110
// Values: {bool}
107111
// Default: false
108112
MultiZoneProvisioning bool
113+
// Values: READ_WRITE_SINGLE, READ_ONLY_MANY, READ_WRITE_MANY
114+
// Default: READ_WRITE_SINGLE
115+
AccessMode string
116+
}
117+
118+
func (dp *DiskParameters) IsRegional() bool {
119+
return dp.ReplicationType == "regional-pd" || dp.DiskType == ParameterHdHADiskType
109120
}
110121

111122
// SnapshotParameters contains normalized and defaulted parameters for snapshots
@@ -129,6 +140,7 @@ type ParameterProcessor struct {
129140
DriverName string
130141
EnableStoragePools bool
131142
EnableMultiZone bool
143+
EnableHdHA bool
132144
}
133145

134146
type ModifyVolumeParameters struct {
@@ -167,6 +179,9 @@ func (pp *ParameterProcessor) ExtractAndDefaultParameters(parameters map[string]
167179
case ParameterKeyType:
168180
if v != "" {
169181
p.DiskType = strings.ToLower(v)
182+
if !pp.EnableHdHA && p.DiskType == ParameterHdHADiskType {
183+
return p, fmt.Errorf("parameters contain invalid disk type %s", ParameterHdHADiskType)
184+
}
170185
}
171186
case ParameterKeyReplicationType:
172187
if v != "" {
@@ -201,6 +216,9 @@ func (pp *ParameterProcessor) ExtractAndDefaultParameters(parameters map[string]
201216
if err != nil {
202217
return p, fmt.Errorf("parameters contain invalid provisionedThroughputOnCreate parameter: %w", err)
203218
}
219+
if paramProvisionedThroughputOnCreate < 0 {
220+
return p, fmt.Errorf("parameter provisionedThroughputOnCreate cannot be negative")
221+
}
204222
p.ProvisionedThroughputOnCreate = paramProvisionedThroughputOnCreate
205223
case ParameterAvailabilityClass:
206224
paramAvailabilityClass, err := ConvertStringToAvailabilityClass(v)
@@ -250,6 +268,10 @@ func (pp *ParameterProcessor) ExtractAndDefaultParameters(parameters map[string]
250268
if paramEnableMultiZoneProvisioning {
251269
p.Labels[MultiZoneLabel] = "true"
252270
}
271+
case ParameterAccessMode:
272+
if v != "" {
273+
p.AccessMode = v
274+
}
253275
default:
254276
return p, fmt.Errorf("parameters contains invalid option %q", k)
255277
}

pkg/common/parameters_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestExtractAndDefaultParameters(t *testing.T) {
3030
labels map[string]string
3131
enableStoragePools bool
3232
enableMultiZone bool
33+
enableHdHA bool
3334
extraTags map[string]string
3435
expectParams DiskParameters
3536
expectErr bool
@@ -344,6 +345,13 @@ func TestExtractAndDefaultParameters(t *testing.T) {
344345
labels: map[string]string{},
345346
expectErr: true,
346347
},
348+
{
349+
name: "invalid storage pool parameters, negative ProvisionedThroughputOnCreate",
350+
enableStoragePools: true,
351+
parameters: map[string]string{ParameterKeyType: "hyperdisk-throughput", ParameterKeyReplicationType: "none", ParameterKeyDiskEncryptionKmsKey: "foo/key", ParameterKeyLabels: "key1=value1,key2=value2", ParameterKeyResourceTags: "parent1/key1/value1,parent2/key2/value2", ParameterKeyProvisionedThroughputOnCreate: "-50Mi"},
352+
labels: map[string]string{},
353+
expectErr: true,
354+
},
347355
{
348356
name: "storage pool parameters, enableStoragePools is false",
349357
enableStoragePools: false,
@@ -388,6 +396,23 @@ func TestExtractAndDefaultParameters(t *testing.T) {
388396
parameters: map[string]string{ParameterKeyType: "hyperdisk-ml", ParameterKeyEnableMultiZoneProvisioning: "true"},
389397
expectErr: true,
390398
},
399+
{
400+
name: "disk parameters, hdha disabled",
401+
parameters: map[string]string{ParameterKeyType: "hyperdisk-balanced-high-availability"},
402+
expectErr: true,
403+
},
404+
{
405+
name: "disk parameters, hdha enabled",
406+
parameters: map[string]string{ParameterKeyType: "hyperdisk-balanced-high-availability"},
407+
enableHdHA: true,
408+
expectParams: DiskParameters{
409+
DiskType: "hyperdisk-balanced-high-availability",
410+
ReplicationType: "none",
411+
Tags: map[string]string{},
412+
ResourceTags: map[string]string{},
413+
Labels: map[string]string{},
414+
},
415+
},
391416
}
392417

393418
for _, tc := range tests {
@@ -396,6 +421,7 @@ func TestExtractAndDefaultParameters(t *testing.T) {
396421
DriverName: "testDriver",
397422
EnableStoragePools: tc.enableStoragePools,
398423
EnableMultiZone: tc.enableMultiZone,
424+
EnableHdHA: tc.enableHdHA,
399425
}
400426
p, err := pp.ExtractAndDefaultParameters(tc.parameters, tc.labels, tc.extraTags)
401427
if gotErr := err != nil; gotErr != tc.expectErr {

pkg/common/utils_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ func TestIsUserMultiAttachError(t *testing.T) {
14091409
},
14101410
}
14111411
for _, test := range cases {
1412-
code, err := isUserMultiAttachError(fmt.Errorf(test.errorString))
1412+
code, err := isUserMultiAttachError(fmt.Errorf("%v", test.errorString))
14131413
if test.expectCode {
14141414
if err != nil || code != test.expectedCode {
14151415
t.Errorf("Failed with non-nil error %v or bad code %v: %s", err, code, test.errorString)

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

+11
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ func (d *CloudDisk) GetZone() string {
166166
}
167167
}
168168

169+
func (d *CloudDisk) GetRegion() string {
170+
switch {
171+
case d.disk != nil:
172+
return d.disk.Region
173+
case d.betaDisk != nil:
174+
return d.betaDisk.Region
175+
default:
176+
return ""
177+
}
178+
}
179+
169180
func (d *CloudDisk) GetSnapshotId() string {
170181
switch {
171182
case d.disk != nil:

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func CreateFakeCloudProvider(project, zone string, cloudDisks []*CloudDisk) (*Fa
7979
mockDiskStatus: "READY",
8080
}
8181
for _, d := range cloudDisks {
82+
if d.LocationType() == meta.Regional {
83+
fcp.disks[meta.RegionalKey(d.GetName(), d.GetRegion()).String()] = d
84+
continue
85+
}
8286
diskZone := d.GetZone()
8387
if diskZone == "" {
8488
diskZone = zone
@@ -184,7 +188,7 @@ func (cloud *FakeCloudProvider) ListSnapshots(ctx context.Context, filter string
184188
}
185189

186190
// Disk Methods
187-
func (cloud *FakeCloudProvider) GetDisk(ctx context.Context, project string, volKey *meta.Key, api GCEAPIVersion) (*CloudDisk, error) {
191+
func (cloud *FakeCloudProvider) GetDisk(ctx context.Context, project string, volKey *meta.Key) (*CloudDisk, error) {
188192
disk, ok := cloud.disks[volKey.String()]
189193
if !ok {
190194
return nil, notFoundError()
@@ -216,7 +220,6 @@ func (cloud *FakeCloudProvider) ValidateExistingDisk(ctx context.Context, resp *
216220
if multiWriter && !resp.GetMultiWriter() {
217221
return fmt.Errorf("disk already exists with incompatible capability. Need MultiWriter. Got non-MultiWriter")
218222
}
219-
220223
klog.V(4).Infof("Compatible disk already exists")
221224
return ValidateDiskParameters(resp, params)
222225
}

0 commit comments

Comments
 (0)