Skip to content

Commit

Permalink
resize fs in NodeStageVolume
Browse files Browse the repository at this point in the history
While restoring from a snapshot to larger size PVC the volume needs to
be resized. We can use ResizeFs resizer (like extend already uses) in
NodeStageVolume to improve user experience and remove manual
intervention that is currently required after restoring to larger size.
  • Loading branch information
RomanBednar committed Nov 1, 2022
1 parent ea128ab commit d05d445
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/ibmcsidriver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package ibmcsidriver

import (
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -308,6 +310,10 @@ func (csiNS *CSINodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeSt
return nil, commonError.GetCSIError(ctxLogger, commonError.FormatAndMountFailed, requestID, err, source, stagingTargetPath)
}

if _, err := mountmgr.Resize(csiNS.SafeFormatAndMount, devicePath, stagingTargetPath); err != nil {
return nil, commonError.GetCSIError(ctxLogger, commonError.FileSystemResizeFailed, requestID, err)
}

nodeStageVolumeResponse := &csi.NodeStageVolumeResponse{}
return nodeStageVolumeResponse, err
}
Expand Down
55 changes: 54 additions & 1 deletion pkg/ibmcsidriver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,60 @@ func TestNodeStageVolume(t *testing.T) {
},
}

icDriver := initIBMCSIDriver(t)
actionList := []testingexec.FakeCommandAction{
makeFakeCmd(
&testingexec.FakeCmd{
CombinedOutputScript: []testingexec.FakeAction{
func() ([]byte, []byte, error) {
return []byte("DEVNAME=/dev/sdb\nTYPE=ext4"), nil, nil
},
},
},
"blkid",
),
makeFakeCmd(
&testingexec.FakeCmd{
CombinedOutputScript: []testingexec.FakeAction{
func() ([]byte, []byte, error) {
return []byte("1"), nil, nil
},
},
},
"mkfs.ext2",
),
makeFakeCmd(
&testingexec.FakeCmd{
CombinedOutputScript: []testingexec.FakeAction{
func() ([]byte, []byte, error) {
return []byte("1"), nil, nil
},
},
},
"blockdev",
),
makeFakeCmd(
&testingexec.FakeCmd{
CombinedOutputScript: []testingexec.FakeAction{
func() ([]byte, []byte, error) {
return []byte("DEVNAME=/dev/sdb\nTYPE=ext4"), nil, nil
},
},
},
"blkid",
),
makeFakeCmd(
&testingexec.FakeCmd{
CombinedOutputScript: []testingexec.FakeAction{
func() ([]byte, []byte, error) {
return []byte("block size: 1\nblock count: 1"), nil, nil
},
},
},
"dumpe2fs",
),
}

icDriver := initIBMCSIDriver(t, actionList...)
for _, tc := range testCases {
t.Logf("Test case: %s", tc.name)
_, err := icDriver.ns.NodeStageVolume(context.Background(), tc.req)
Expand Down

0 comments on commit d05d445

Please sign in to comment.