From e8aa11a74ca1d7d3735a7a59685a9f41680ea85c Mon Sep 17 00:00:00 2001 From: ZeroMagic Date: Sat, 28 Sep 2019 06:52:29 +0000 Subject: [PATCH] feat: support VolumeExpansion in OFFLINE scenario Signed-off-by: ZeroMagic --- pkg/azurefile/azurefile.go | 1 + pkg/azurefile/controllerserver.go | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go index 3ec3f3a281..93ce76f621 100644 --- a/pkg/azurefile/azurefile.go +++ b/pkg/azurefile/azurefile.go @@ -100,6 +100,7 @@ func (d *Driver) Run(endpoint string) { csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME, csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT, //csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS, + csi.ControllerServiceCapability_RPC_EXPAND_VOLUME, }) d.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{ csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, diff --git a/pkg/azurefile/controllerserver.go b/pkg/azurefile/controllerserver.go index 16e58f5095..6829354eb4 100644 --- a/pkg/azurefile/controllerserver.go +++ b/pkg/azurefile/controllerserver.go @@ -321,7 +321,31 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques // ControllerExpandVolume controller expand volume func (d *Driver) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "ControllerExpandVolume is not yet implemented") + if len(req.GetVolumeId()) == 0 { + return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request") + } + if err := d.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_EXPAND_VOLUME); err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid expand volume request: %v", req) + } + + capacityBytes := req.GetCapacityRange().GetRequiredBytes() + if capacityBytes == 0 { + return nil, status.Error(codes.InvalidArgument, "volume capacity range missing in request") + } + volSizeBytes := int64(capacityBytes) + requestGiB := int32(volumehelper.RoundUpGiB(volSizeBytes)) + + volumeID := req.VolumeId + shareURL, err := d.getShareUrl(volumeID) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get share url with (%s): %v, returning with success", volumeID, err) + } + + if _, err = shareURL.SetQuota(ctx, requestGiB); err != nil { + return nil, status.Errorf(codes.Internal, "expand volume error: %v", err) + } + + return &csi.ControllerExpandVolumeResponse{}, nil } // getShareUrl: sourceVolumeID is the id of source file share, returns a ShareURL of source file share.