Skip to content

Commit

Permalink
Fix Hyperdisk ControllerExpandVolume Edge Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylovestiramisu committed Jan 3, 2025
1 parent c29a4ee commit 93de915
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pkg/common/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ type ParameterProcessor struct {
type ModifyVolumeParameters struct {
IOPS *int64
Throughput *int64
// Only set SizeGb for ControllerVolumeExpand
SizeGb *int64
}

// ExtractAndDefaultParameters will take the relevant parameters from a map and
Expand Down
4 changes: 4 additions & 0 deletions pkg/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ var (
regexValue = regexp.MustCompile(`^[a-zA-Z0-9]([0-9A-Za-z_.@%=+:,*#&()\[\]{}\-\s]{0,61}[a-zA-Z0-9])?$`)

csiRetryableErrorCodes = []codes.Code{codes.Canceled, codes.DeadlineExceeded, codes.Unavailable, codes.Aborted, codes.ResourceExhausted}

// Minimum Iops for Hyperdisk >= 6 Gi
MinHyperdiskIops int64 = 3000
Hyperdisk5GbIops int64 = 2500
)

func BytesToGbRoundDown(bytes int64) int64 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/gce-cloud-provider/compute/fake-gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ func (cloud *FakeCloudProvider) UpdateDisk(ctx context.Context, project string,
}
specifiedIops := params.IOPS != nil && *params.IOPS != 0
specifiedThroughput := params.Throughput != nil && *params.Throughput != 0
if !specifiedIops && !specifiedThroughput {
specifiedSizeGb := params.SizeGb != nil && *params.SizeGb != 0
if !specifiedIops && !specifiedThroughput && !specifiedSizeGb {
return fmt.Errorf("no IOPS or Throughput specified for disk %v", existingDisk.GetSelfLink())
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/gce-cloud-provider/compute/gce-compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ func (cloud *CloudProvider) UpdateDisk(ctx context.Context, project string, volK
func (cloud *CloudProvider) updateZonalDisk(ctx context.Context, project string, volKey *meta.Key, existingDisk *CloudDisk, params common.ModifyVolumeParameters) error {
specifiedIops := params.IOPS != nil && *params.IOPS != 0
specifiedThroughput := params.Throughput != nil && *params.Throughput != 0
if !specifiedIops && !specifiedThroughput {
specifiedSizeGb := params.SizeGb != nil && *params.SizeGb != 0
if !specifiedIops && !specifiedThroughput && !specifiedSizeGb {
return fmt.Errorf("no IOPS or Throughput specified for disk %v", existingDisk.GetSelfLink())
}
updatedDisk := &computev1.Disk{
Expand Down
22 changes: 19 additions & 3 deletions pkg/gce-pd-csi-driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1882,16 +1882,32 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
}

sourceDisk, err := gceCS.CloudProvider.GetDisk(ctx, project, volKey, gce.GCEAPIVersionV1)

metrics.UpdateRequestMetadataFromDisk(ctx, sourceDisk)
resizedGb, err := gceCS.CloudProvider.ResizeDisk(ctx, project, volKey, reqBytes)

updatedVolumeParams := common.ModifyVolumeParameters{}
updatedSizeGb := int64(reqBytes / 1024 / 1024 / 1024)
updatedVolumeParams.SizeGb = &updatedSizeGb

if gceCS.diskSupportsIopsChange(sourceDisk.GetPDType()) {
// Resize hyperdisk-balanced to 5 Gi requires minimum of 2500 iops
if updatedSizeGb == 5 {
updatedVolumeParams.IOPS = &common.Hyperdisk5GbIops
} else if sourceDisk.GetSizeGb() < 6 && updatedSizeGb >= 6 {
// if old sizeGb is less than 6Gi and the updated value is more or equal than 6Gi, still set iops to 3000
updatedVolumeParams.IOPS = &common.MinHyperdiskIops
}
}

err = gceCS.CloudProvider.UpdateDisk(ctx, project, volKey, sourceDisk, updatedVolumeParams)

if err != nil {
return nil, common.LoggedError("ControllerExpandVolume failed to resize disk: ", err)
}

klog.V(4).Infof("ControllerExpandVolume succeeded for disk %v to size %v", volKey, resizedGb)
klog.V(4).Infof("ControllerExpandVolume succeeded for disk %v to size %v", volKey, updatedSizeGb)
return &csi.ControllerExpandVolumeResponse{
CapacityBytes: common.GbToBytes(resizedGb),
CapacityBytes: common.GbToBytes(updatedSizeGb),
NodeExpansionRequired: true,
}, nil
}
Expand Down

0 comments on commit 93de915

Please sign in to comment.