Skip to content

Commit 6ecdd9b

Browse files
committed
Support provisioing of HdHA disks and add E2E tests.
1 parent 9090993 commit 6ecdd9b

20 files changed

+571
-115
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")
@@ -222,7 +223,7 @@ func handle() {
222223
}
223224
initialBackoffDuration := time.Duration(*errorBackoffInitialDurationMs) * time.Millisecond
224225
maxBackoffDuration := time.Duration(*errorBackoffMaxDurationMs) * time.Millisecond
225-
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, multiZoneVolumeHandleConfig, listVolumesConfig, provisionableDisksConfig)
226+
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, multiZoneVolumeHandleConfig, listVolumesConfig, provisionableDisksConfig, *enableHdHAFlag)
226227
} else if *cloudConfigFilePath != "" {
227228
klog.Warningf("controller service is disabled but cloud config given - it has no effect")
228229
}

pkg/common/parameters.go

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const (
3434
ParameterKeyStoragePools = "storage-pools"
3535
ParameterKeyResourceTags = "resource-tags"
3636
ParameterKeyEnableMultiZoneProvisioning = "enable-multi-zone-provisioning"
37+
ParameterHdHADiskType = "hyperdisk-balanced-high-availability"
3738

3839
// Parameters for VolumeSnapshotClass
3940
ParameterKeyStorageLocations = "storage-locations"
@@ -108,6 +109,10 @@ type DiskParameters struct {
108109
MultiZoneProvisioning bool
109110
}
110111

112+
func (dp *DiskParameters) IsRegional() bool {
113+
return dp.ReplicationType == "regional-pd" || dp.DiskType == ParameterHdHADiskType
114+
}
115+
111116
// SnapshotParameters contains normalized and defaulted parameters for snapshots
112117
type SnapshotParameters struct {
113118
StorageLocations []string
@@ -129,6 +134,7 @@ type ParameterProcessor struct {
129134
DriverName string
130135
EnableStoragePools bool
131136
EnableMultiZone bool
137+
EnableHdHA bool
132138
}
133139

134140
type ModifyVolumeParameters struct {
@@ -167,6 +173,9 @@ func (pp *ParameterProcessor) ExtractAndDefaultParameters(parameters map[string]
167173
case ParameterKeyType:
168174
if v != "" {
169175
p.DiskType = strings.ToLower(v)
176+
if !pp.EnableHdHA && p.DiskType == ParameterHdHADiskType {
177+
return p, fmt.Errorf("parameters contain invalid disk type %s", ParameterHdHADiskType)
178+
}
170179
}
171180
case ParameterKeyReplicationType:
172181
if v != "" {

pkg/common/parameters_test.go

+19
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
@@ -395,6 +396,23 @@ func TestExtractAndDefaultParameters(t *testing.T) {
395396
parameters: map[string]string{ParameterKeyType: "hyperdisk-ml", ParameterKeyEnableMultiZoneProvisioning: "true"},
396397
expectErr: true,
397398
},
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+
},
398416
}
399417

400418
for _, tc := range tests {
@@ -403,6 +421,7 @@ func TestExtractAndDefaultParameters(t *testing.T) {
403421
DriverName: "testDriver",
404422
EnableStoragePools: tc.enableStoragePools,
405423
EnableMultiZone: tc.enableMultiZone,
424+
EnableHdHA: tc.enableHdHA,
406425
}
407426
p, err := pp.ExtractAndDefaultParameters(tc.parameters, tc.labels, tc.extraTags)
408427
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

+4
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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ func ValidateDiskParameters(disk *CloudDisk, params common.DiskParameters) error
423423
}
424424

425425
locationType := disk.LocationType()
426-
if (params.ReplicationType == "none" && locationType != meta.Zonal) || (params.ReplicationType == "regional-pd" && locationType != meta.Regional) {
427-
return fmt.Errorf("actual disk replication type %v did not match expected param %s", locationType, params.ReplicationType)
426+
if (params.ReplicationType == "none" && locationType != meta.Zonal) || (params.IsRegional() && locationType != meta.Regional) {
427+
return fmt.Errorf("actual replication type %v did not match expected param %s and %s", locationType, params.ReplicationType, params.DiskType)
428428
}
429429

430430
if !KmsKeyEqual(

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

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ type CloudProvider struct {
101101
tagsRateLimiter *rate.Limiter
102102

103103
listInstancesConfig ListInstancesConfig
104+
105+
enableHdHA bool
104106
}
105107

106108
var _ GCECompute = &CloudProvider{}

0 commit comments

Comments
 (0)