Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ func (d *NodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
return nil, status.Error(codes.InvalidArgument, "volume path must be provided")
}

if ok := d.inFlight.Insert(volumeID); !ok {
return nil, status.Errorf(codes.Aborted, VolumeOperationAlreadyExists, volumeID)
}
defer func() {
klog.V(4).InfoS("NodeExpandVolume: volume operation finished", "volumeId", volumeID)
d.inFlight.Delete(volumeID)
}()

volumeCapability := req.GetVolumeCapability()
// VolumeCapability is optional, if specified, use that as source of truth
if volumeCapability != nil {
Expand Down Expand Up @@ -389,7 +397,6 @@ func (d *NodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
return nil, status.Errorf(codes.NotFound, "failed to find device path for device name %s for mount %s: %v", deviceName, req.GetVolumePath(), err)
}

// TODO: lock per volume ID to have some idempotency
if _, err = d.mounter.Resize(devicePath, volumePath); err != nil {
return nil, status.Errorf(codes.Internal, "Could not resize volume %q (%q): %v", volumeID, devicePath, err)
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,7 @@ func TestNodeExpandVolume(t *testing.T) {
metadataMock func(ctrl *gomock.Controller) *metadata.MockMetadataService
expectedResp *csi.NodeExpandVolumeResponse
expectedErr error
inflight bool
}{
{
name: "success",
Expand Down Expand Up @@ -2312,6 +2313,15 @@ func TestNodeExpandVolume(t *testing.T) {
expectedResp: nil,
expectedErr: status.Error(codes.Internal, "failed to get block capacity on path /volume/path: failed to get block size"),
},
{
name: "operation_already_exists",
req: &csi.NodeExpandVolumeRequest{
VolumeId: "vol-test",
VolumePath: "/staging/path",
},
expectedErr: status.Error(codes.Aborted, "An operation with the given volume=\"vol-test\" is already in progress"),
inflight: true,
},
}

for _, tc := range testCases {
Expand All @@ -2332,6 +2342,11 @@ func TestNodeExpandVolume(t *testing.T) {
driver := &NodeService{
mounter: mounter,
metadata: metadata,
inFlight: internal.NewInFlight(),
}

if tc.inflight {
driver.inFlight.Insert("vol-test")
}

resp, err := driver.NodeExpandVolume(t.Context(), tc.req)
Expand Down