Skip to content

Commit

Permalink
Merge pull request #1728 from andyzhangx/second-resize-failure
Browse files Browse the repository at this point in the history
fix: second expand volume failure on Ubuntu 22.04
  • Loading branch information
andyzhangx committed Feb 16, 2023
2 parents d9cbdc6 + 095ccb0 commit 9690bc4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pkg/azuredisk/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,10 @@ func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolume
}
}

var retErr error
if err := resizeVolume(devicePath, volumePath, d.mounter); err != nil {
return nil, status.Errorf(codes.Internal, "could not resize volume %q (%q): %v", volumeID, devicePath, err)
retErr = status.Errorf(codes.Internal, "could not resize volume %q (%q): %v", volumeID, devicePath, err)
klog.Errorf("%v, will continue checking whether the volume has been resized", retErr)
}

gotBlockSizeBytes, err := getBlockSizeBytes(devicePath, d.mounter)
Expand All @@ -491,9 +493,13 @@ func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolume
}
gotBlockGiB := volumehelper.RoundUpGiB(gotBlockSizeBytes)
if gotBlockGiB < requestGiB {
if retErr != nil {
return nil, retErr
}
// Because size was rounded up, getting more size than requested will be a success.
return nil, status.Errorf(codes.Internal, "resize requested for %v, but after resizing volume size was %v", requestGiB, gotBlockGiB)
}

klog.V(2).Infof("NodeExpandVolume succeeded on resizing volume %v to %v", volumeID, gotBlockSizeBytes)

return &csi.NodeExpandVolumeResponse{
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ func TestNodeExpandVolume(t *testing.T) {
},
expectedErr: resizeErr,
skipOnDarwin: true, // ResizeFs not supported on Darwin
outputScripts: []testingexec.FakeAction{findmntAction, blkidAction, resize2fsFailedAction},
outputScripts: []testingexec.FakeAction{findmntAction, blkidAction, resize2fsFailedAction, blockdevSizeTooSmallAction},
},
{
desc: "Resize too small failure",
Expand Down
7 changes: 6 additions & 1 deletion pkg/azuredisk/nodeserver_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ func (d *DriverV2) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolu
}
}

var retErr error
if err := resizeVolume(devicePath, volumePath, d.mounter); err != nil {
return nil, status.Errorf(codes.Internal, "could not resize volume %q (%q): %v", volumeID, devicePath, err)
retErr = status.Errorf(codes.Internal, "could not resize volume %q (%q): %v", volumeID, devicePath, err)
klog.Errorf("%v, will continue checking whether the volume has been resized", retErr)
}

gotBlockSizeBytes, err := getBlockSizeBytes(devicePath, d.mounter)
Expand All @@ -476,6 +478,9 @@ func (d *DriverV2) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolu
}
gotBlockGiB := volumehelper.RoundUpGiB(gotBlockSizeBytes)
if gotBlockGiB < requestGiB {
if retErr != nil {
return nil, retErr
}
// Because size was rounded up, getting more size than requested will be a success.
return nil, status.Errorf(codes.Internal, "resize requested for %v, but after resizing volume size was %v", requestGiB, gotBlockGiB)
}
Expand Down

0 comments on commit 9690bc4

Please sign in to comment.