Skip to content

Commit afd7d61

Browse files
authored
Merge pull request #462 from davidz627/fix/flow
Fix Resize call to return size in Gi as expected when disk is already the request size or larger
2 parents e4b7960 + 8baf48d commit afd7d61

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ func (cloud *CloudProvider) CreateSnapshot(ctx context.Context, volKey *meta.Key
620620
}
621621
}
622622

623+
// ResizeDisk takes in the requested disk size in bytes and returns the resized
624+
// size in Gi
625+
// TODO(#461) The whole driver could benefit from standardized usage of the
626+
// k8s.io/apimachinery/quantity package for better size handling
623627
func (cloud *CloudProvider) ResizeDisk(ctx context.Context, volKey *meta.Key, requestBytes int64) (int64, error) {
624628
klog.V(5).Infof("Resizing disk %v to size %v", volKey, requestBytes)
625629
cloudDisk, err := cloud.GetDisk(ctx, volKey)
@@ -630,9 +634,10 @@ func (cloud *CloudProvider) ResizeDisk(ctx context.Context, volKey *meta.Key, re
630634
sizeGb := cloudDisk.GetSizeGb()
631635
requestGb := common.BytesToGb(requestBytes)
632636

633-
// If disk is already of size equal or greater than requested size, we simply return
637+
// If disk is already of size equal or greater than requested size, we
638+
// simply return the found size
634639
if sizeGb >= requestGb {
635-
return requestBytes, nil
640+
return sizeGb, nil
636641
}
637642

638643
switch volKey.Type() {

pkg/gce-pd-csi-driver/node.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -436,45 +436,45 @@ func (ns *GCENodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGe
436436
func (ns *GCENodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
437437
volumeID := req.GetVolumeId()
438438
if len(volumeID) == 0 {
439-
return nil, status.Error(codes.InvalidArgument, "ControllerExpandVolume volume ID must be provided")
439+
return nil, status.Error(codes.InvalidArgument, "volume ID must be provided")
440440
}
441441
capacityRange := req.GetCapacityRange()
442442
reqBytes, err := getRequestCapacity(capacityRange)
443443
if err != nil {
444-
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("ControllerExpandVolume capacity range is invalid: %v", err))
444+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("capacity range is invalid: %v", err))
445445
}
446446

447447
volumePath := req.GetVolumePath()
448448
if len(volumePath) == 0 {
449-
return nil, status.Error(codes.InvalidArgument, "ControllerExpandVolume volume path must be provided")
449+
return nil, status.Error(codes.InvalidArgument, "volume path must be provided")
450450
}
451451

452452
volKey, err := common.VolumeIDToKey(volumeID)
453453
if err != nil {
454-
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("ControllerExpandVolume Volume ID is invalid: %v", err))
454+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("volume ID is invalid: %v", err))
455455
}
456456

457457
devicePath, err := ns.getDevicePath(volumeID, "")
458458
if err != nil {
459-
return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerExpandVolume error when getting device path for %s: %v", volumeID, err))
459+
return nil, status.Error(codes.Internal, fmt.Sprintf("error when getting device path for %s: %v", volumeID, err))
460460
}
461461

462462
// TODO(#328): Use requested size in resize if provided
463463
resizer := resizefs.NewResizeFs(ns.Mounter)
464464
_, err = resizer.Resize(devicePath, volumePath)
465465
if err != nil {
466-
return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerExpandVolume error when resizing volume %s: %v", volKey.String(), err))
466+
return nil, status.Error(codes.Internal, fmt.Sprintf("error when resizing volume %s: %v", volKey.String(), err))
467467

468468
}
469469

470470
// Check the block size
471471
gotBlockSizeBytes, err := ns.getBlockSizeBytes(devicePath)
472472
if err != nil {
473-
return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerExpandVolume error when getting size of block volume at path %s: %v", devicePath, err))
473+
return nil, status.Error(codes.Internal, fmt.Sprintf("error when getting size of block volume at path %s: %v", devicePath, err))
474474
}
475475
if gotBlockSizeBytes < reqBytes {
476476
// It's possible that the somewhere the volume size was rounded up, getting more size than requested is a success :)
477-
return nil, status.Errorf(codes.Internal, "ControllerExpandVolume resize requested for %v but after resize volume was size %v", reqBytes, gotBlockSizeBytes)
477+
return nil, status.Errorf(codes.Internal, "resize requested for %v but after resize volume was size %v", reqBytes, gotBlockSizeBytes)
478478
}
479479

480480
// TODO(dyzz) Some sort of formatted volume could also check the fs size.

0 commit comments

Comments
 (0)