Skip to content

Commit

Permalink
Add volume expansion support
Browse files Browse the repository at this point in the history
  • Loading branch information
bertinatto committed Aug 19, 2019
1 parent c7721b7 commit b120f58
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/hostpath/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewControllerServer(ephemeral bool) *controllerServer {
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS,
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
}),
}
}
Expand Down Expand Up @@ -457,6 +458,39 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
}, nil
}

func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {

volID := req.GetVolumeId()
if len(volID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}

capRange := req.GetCapacityRange()
if capRange == nil {
return nil, status.Error(codes.InvalidArgument, "Capacity range not provided")
}

capacity := int64(capRange.GetRequiredBytes())
if capacity >= maxStorageCapacity {
return nil, status.Errorf(codes.OutOfRange, "Requested capacity %d exceeds maximum allowed %d", capacity, maxStorageCapacity)
}

exVol, err := getVolumeByID(volID)
if err != nil {
// Assume not found error
return &csi.ControllerExpandVolumeResponse{}, status.Errorf(codes.NotFound, "Could not get volume %s: %v", volID, err)
}

if exVol.VolSize < capacity {
exVol.VolSize = capacity
}

return &csi.ControllerExpandVolumeResponse{
CapacityBytes: exVol.VolSize,
NodeExpansionRequired: false,
}, nil
}

func convertSnapshot(snap hostPathSnapshot) *csi.ListSnapshotsResponse {
entries := []*csi.ListSnapshotsResponse_Entry{
{
Expand Down

0 comments on commit b120f58

Please sign in to comment.