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 22, 2019
1 parent 09a18b7 commit f088f2d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
37 changes: 37 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,42 @@ 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 nil, status.Errorf(codes.NotFound, "Could not get volume %s: %v", volID, err)
}

if exVol.VolSize < capacity {
exVol.VolSize = capacity
if err := updateHostpathVolume(volID, exVol); err != nil {
return nil, status.Errorf(codes.Internal, "Could not update volume %s: %v", volID, err)
}
}

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

func convertSnapshot(snap hostPathSnapshot) *csi.ListSnapshotsResponse {
entries := []*csi.ListSnapshotsResponse_Entry{
{
Expand Down
12 changes: 12 additions & 0 deletions pkg/hostpath/hostpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ func createHostpathVolume(volID, name string, cap int64, volAccessType accessTyp
return &hostpathVol, nil
}

// updateVolume updates the existing hostpath volume.
func updateHostpathVolume(volID string, volume hostPathVolume) error {
glog.V(4).Infof("updating hostpath volume: %s", volID)

if _, err := getVolumeByID(volID); err != nil {
return err
}

hostPathVolumes[volID] = volume
return nil
}

// deleteVolume deletes the directory for the hostpath volume.
func deleteHostpathVolume(volID string) error {
glog.V(4).Infof("deleting hostpath volume: %s", volID)
Expand Down
4 changes: 4 additions & 0 deletions pkg/hostpath/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,7 @@ func (ns *nodeServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC
func (ns *nodeServer) NodeGetVolumeStats(ctx context.Context, in *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

0 comments on commit f088f2d

Please sign in to comment.