Skip to content

Commit 5dc9383

Browse files
committed
Add volume expansion support
1 parent c7721b7 commit 5dc9383

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pkg/hostpath/controllerserver.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func NewControllerServer(ephemeral bool) *controllerServer {
6363
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
6464
csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS,
6565
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
66+
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
6667
}),
6768
}
6869
}
@@ -457,6 +458,39 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
457458
}, nil
458459
}
459460

461+
func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
462+
463+
volID := req.GetVolumeId()
464+
if len(volID) == 0 {
465+
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
466+
}
467+
468+
capRange := req.GetCapacityRange()
469+
if capRange == nil {
470+
return nil, status.Error(codes.InvalidArgument, "Capacity range not provided")
471+
}
472+
473+
capacity := int64(capRange.GetRequiredBytes())
474+
if capacity >= maxStorageCapacity {
475+
return nil, status.Errorf(codes.OutOfRange, "Requested capacity %d exceeds maximum allowed %d", capacity, maxStorageCapacity)
476+
}
477+
478+
exVol, err := getVolumeByID(volID)
479+
if err != nil {
480+
// Assume not found error
481+
return &csi.ControllerExpandVolumeResponse{}, status.Errorf(codes.NotFound, "Could not get volume %s: %v", volID, err)
482+
}
483+
484+
if exVol.VolSize < capacity {
485+
exVol.VolSize = capacity
486+
}
487+
488+
return &csi.ControllerExpandVolumeResponse{
489+
CapacityBytes: exVol.VolSize,
490+
NodeExpansionRequired: false,
491+
}, nil
492+
}
493+
460494
func convertSnapshot(snap hostPathSnapshot) *csi.ListSnapshotsResponse {
461495
entries := []*csi.ListSnapshotsResponse_Entry{
462496
{

pkg/hostpath/nodeserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,7 @@ func (ns *nodeServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC
284284
func (ns *nodeServer) NodeGetVolumeStats(ctx context.Context, in *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
285285
return nil, status.Error(codes.Unimplemented, "")
286286
}
287+
288+
func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
289+
return nil, status.Error(codes.Unimplemented, "")
290+
}

0 commit comments

Comments
 (0)