Skip to content

Commit

Permalink
feat: support VolumeExpansion in OFFLINE scenario
Browse files Browse the repository at this point in the history
Signed-off-by: ZeroMagic <[email protected]>
  • Loading branch information
ZeroMagic committed Sep 30, 2019
1 parent daea671 commit e8aa11a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 25 additions & 1 deletion pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e8aa11a

Please sign in to comment.