Skip to content

Add support for HdHA disk provisioning #1915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/gce-pd-csi-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var (
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")
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")
enableStoragePoolsFlag = flag.Bool("enable-storage-pools", false, "If set to true, the CSI Driver will allow volumes to be provisioned in Storage Pools")
enableHdHAFlag = flag.Bool("allow-hdha-provisioning", false, "If set to true, will allow the driver to provision Hyperdisk-balanced High Availability disks")

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")
multiZoneVolumeHandleEnableFlag = flag.Bool("multi-zone-volume-handle-enable", false, "If set to true, the multi-zone volumeHandle feature will be enabled")
Expand Down Expand Up @@ -222,7 +223,7 @@ func handle() {
}
initialBackoffDuration := time.Duration(*errorBackoffInitialDurationMs) * time.Millisecond
maxBackoffDuration := time.Duration(*errorBackoffMaxDurationMs) * time.Millisecond
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, multiZoneVolumeHandleConfig, listVolumesConfig, provisionableDisksConfig)
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, multiZoneVolumeHandleConfig, listVolumesConfig, provisionableDisksConfig, *enableHdHAFlag)
} else if *cloudConfigFilePath != "" {
klog.Warningf("controller service is disabled but cloud config given - it has no effect")
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/common/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
ParameterKeyStoragePools = "storage-pools"
ParameterKeyResourceTags = "resource-tags"
ParameterKeyEnableMultiZoneProvisioning = "enable-multi-zone-provisioning"
ParameterHdHADiskType = "hyperdisk-balanced-high-availability"

// Parameters for VolumeSnapshotClass
ParameterKeyStorageLocations = "storage-locations"
Expand Down Expand Up @@ -108,6 +109,10 @@ type DiskParameters struct {
MultiZoneProvisioning bool
}

func (dp *DiskParameters) IsRegional() bool {
return dp.ReplicationType == "regional-pd" || dp.DiskType == ParameterHdHADiskType
}

// SnapshotParameters contains normalized and defaulted parameters for snapshots
type SnapshotParameters struct {
StorageLocations []string
Expand All @@ -129,6 +134,7 @@ type ParameterProcessor struct {
DriverName string
EnableStoragePools bool
EnableMultiZone bool
EnableHdHA bool
}

type ModifyVolumeParameters struct {
Expand Down Expand Up @@ -167,6 +173,9 @@ func (pp *ParameterProcessor) ExtractAndDefaultParameters(parameters map[string]
case ParameterKeyType:
if v != "" {
p.DiskType = strings.ToLower(v)
if !pp.EnableHdHA && p.DiskType == ParameterHdHADiskType {
return p, fmt.Errorf("parameters contain invalid disk type %s", ParameterHdHADiskType)
}
}
case ParameterKeyReplicationType:
if v != "" {
Expand Down
19 changes: 19 additions & 0 deletions pkg/common/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestExtractAndDefaultParameters(t *testing.T) {
labels map[string]string
enableStoragePools bool
enableMultiZone bool
enableHdHA bool
extraTags map[string]string
expectParams DiskParameters
expectErr bool
Expand Down Expand Up @@ -395,6 +396,23 @@ func TestExtractAndDefaultParameters(t *testing.T) {
parameters: map[string]string{ParameterKeyType: "hyperdisk-ml", ParameterKeyEnableMultiZoneProvisioning: "true"},
expectErr: true,
},
{
name: "disk parameters, hdha disabled",
parameters: map[string]string{ParameterKeyType: "hyperdisk-balanced-high-availability"},
expectErr: true,
},
{
name: "disk parameters, hdha enabled",
parameters: map[string]string{ParameterKeyType: "hyperdisk-balanced-high-availability"},
enableHdHA: true,
expectParams: DiskParameters{
DiskType: "hyperdisk-balanced-high-availability",
ReplicationType: "none",
Tags: map[string]string{},
ResourceTags: map[string]string{},
Labels: map[string]string{},
},
},
}

for _, tc := range tests {
Expand All @@ -403,6 +421,7 @@ func TestExtractAndDefaultParameters(t *testing.T) {
DriverName: "testDriver",
EnableStoragePools: tc.enableStoragePools,
EnableMultiZone: tc.enableMultiZone,
EnableHdHA: tc.enableHdHA,
}
p, err := pp.ExtractAndDefaultParameters(tc.parameters, tc.labels, tc.extraTags)
if gotErr := err != nil; gotErr != tc.expectErr {
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ func TestIsUserMultiAttachError(t *testing.T) {
},
}
for _, test := range cases {
code, err := isUserMultiAttachError(fmt.Errorf(test.errorString))
code, err := isUserMultiAttachError(fmt.Errorf("%v", test.errorString))
if test.expectCode {
if err != nil || code != test.expectedCode {
t.Errorf("Failed with non-nil error %v or bad code %v: %s", err, code, test.errorString)
Expand Down
11 changes: 11 additions & 0 deletions pkg/gce-cloud-provider/compute/cloud-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ func (d *CloudDisk) GetZone() string {
}
}

func (d *CloudDisk) GetRegion() string {
switch {
case d.disk != nil:
return d.disk.Region
case d.betaDisk != nil:
return d.betaDisk.Region
default:
return ""
}
}

func (d *CloudDisk) GetSnapshotId() string {
switch {
case d.disk != nil:
Expand Down
4 changes: 4 additions & 0 deletions pkg/gce-cloud-provider/compute/fake-gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func CreateFakeCloudProvider(project, zone string, cloudDisks []*CloudDisk) (*Fa
mockDiskStatus: "READY",
}
for _, d := range cloudDisks {
if d.LocationType() == meta.Regional {
fcp.disks[meta.RegionalKey(d.GetName(), d.GetRegion()).String()] = d
continue
}
diskZone := d.GetZone()
if diskZone == "" {
diskZone = zone
Expand Down
4 changes: 2 additions & 2 deletions pkg/gce-cloud-provider/compute/gce-compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ func ValidateDiskParameters(disk *CloudDisk, params common.DiskParameters) error
}

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

if !KmsKeyEqual(
Expand Down
2 changes: 2 additions & 0 deletions pkg/gce-cloud-provider/compute/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ type CloudProvider struct {
tagsRateLimiter *rate.Limiter

listInstancesConfig ListInstancesConfig

enableHdHA bool
}

var _ GCECompute = &CloudProvider{}
Expand Down
Loading