Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-1657: use mount-utils to resize fs #2056

Merged
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: 6 additions & 3 deletions cloud/blockstore/tests/csi_driver/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def unstage_volume(self, volume_id: str):
volume_id,
)

def publish_volume(self, pod_id: str, volume_id: str, pod_name: str):
def publish_volume(self, pod_id: str, volume_id: str, pod_name: str, fs_type: str = ""):
return self._node_run(
"publishvolume",
"--pod-id",
Expand All @@ -214,6 +214,8 @@ def publish_volume(self, pod_id: str, volume_id: str, pod_name: str):
volume_id,
"--pod-name",
pod_name,
"--fs-type",
fs_type,
)

def unpublish_volume(self, pod_id: str, volume_id: str):
Expand Down Expand Up @@ -424,7 +426,8 @@ def test_csi_sanity_nbs_backend(mount_path, volume_access_type, vm_mode):
cleanup_after_test(env)


def test_node_volume_expand():
@pytest.mark.parametrize('fs_type', ["ext4", "xfs"])
def test_node_volume_expand(fs_type):
env, run = init()
try:
volume_name = "example-disk"
Expand All @@ -433,7 +436,7 @@ def test_node_volume_expand():
pod_id = "deadbeef"
env.csi.create_volume(name=volume_name, size=volume_size)
env.csi.stage_volume(volume_name)
env.csi.publish_volume(pod_id, volume_name, pod_name)
env.csi.publish_volume(pod_id, volume_name, pod_name, fs_type)

new_volume_size = 2 * volume_size
env.csi.expand_volume(pod_id, volume_name, new_volume_size)
Expand Down
10 changes: 9 additions & 1 deletion cloud/blockstore/tools/csi_driver/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func newNodeStageVolumeCommand(endpoint *string) *cobra.Command {
}

func newPublishVolumeCommand(endpoint *string) *cobra.Command {
var volumeId, podId, stagingTargetPath, podName string
var volumeId, podId, stagingTargetPath, podName, fsType string
var readOnly bool
cmd := cobra.Command{
Use: "publishvolume",
Expand Down Expand Up @@ -283,6 +283,7 @@ func newPublishVolumeCommand(endpoint *string) *cobra.Command {
"csi.storage.k8s.io/pod.name": podName,
"storage.kubernetes.io/csiProvisionerIdentity": "someIdentity",
"instanceId": "example-instance-id",
"fsType": fsType,
}
accessMode := csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER

Expand Down Expand Up @@ -339,6 +340,13 @@ func newPublishVolumeCommand(endpoint *string) *cobra.Command {
false,
"volume is read only",
)
cmd.Flags().StringVar(
&fsType,
"fs-type",
"",
"filesystem type: ext4, xfs",
)

err := cmd.MarkFlagRequired("volume-id")
if err != nil {
log.Fatal(err)
Expand Down
16 changes: 12 additions & 4 deletions cloud/blockstore/tools/csi_driver/internal/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,12 +1176,20 @@ func (s *nodeService) NodeExpandVolume(
}

if s.isMountAccessType(req.VolumePath) {
cmd := exec.Command("resize2fs", nbdDevicePath)
if out, err := cmd.CombinedOutput(); err != nil {
needResize, err := s.mounter.NeedResize(nbdDevicePath, req.VolumePath)
if err != nil {
return nil, s.statusErrorf(
codes.Internal,
"Failed to resize filesystem %v, output %s",
err, out)
"NeedResize failed %v", err)
}

if needResize {
_, err := s.mounter.Resize(nbdDevicePath, req.VolumePath)
if err != nil {
return nil, s.statusErrorf(
codes.Internal,
"Failed to resize filesystem %v", err)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions cloud/blockstore/tools/csi_driver/internal/mounter/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ type Interface interface {

IsFilesystemExisted(device string) (bool, error)
MakeFilesystem(device string, fsType string) ([]byte, error)

NeedResize(devicePath string, deviceMountPath string) (bool, error)
Resize(devicePath, deviceMountPath string) (bool, error)
}
10 changes: 10 additions & 0 deletions cloud/blockstore/tools/csi_driver/internal/mounter/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ func (c *Mock) MakeFilesystem(device string, fsType string) ([]byte, error) {
return args.Get(0).([]byte), args.Error(1)
}

func (c *Mock) NeedResize(devicePath string, deviceMountPath string) (bool, error) {
args := c.Called(devicePath, deviceMountPath)
return args.Get(0).(bool), args.Error(1)
}

func (c *Mock) Resize(devicePath string, deviceMountPath string) (bool, error) {
args := c.Called(devicePath, deviceMountPath)
return args.Get(0).(bool), args.Error(1)
}

////////////////////////////////////////////////////////////////////////////////

func NewMock() *Mock {
Expand Down
15 changes: 13 additions & 2 deletions cloud/blockstore/tools/csi_driver/internal/mounter/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import (
"strings"

"k8s.io/mount-utils"
executils "k8s.io/utils/exec"
)

////////////////////////////////////////////////////////////////////////////////

type mounter struct {
mnt mount.Interface
mnt mount.Interface
exec executils.Interface
}

func NewMounter() Interface {
return &mounter{
mnt: mount.New(""),
mnt: mount.New(""),
exec: executils.New(),
}
}

Expand Down Expand Up @@ -77,3 +80,11 @@ func (m *mounter) MakeFilesystem(device string, fsType string) ([]byte, error) {
options = append(options, device)
return exec.Command("mkfs", options...).CombinedOutput()
}

func (m *mounter) NeedResize(devicePath string, deviceMountPath string) (bool, error) {
return mount.NewResizeFs(m.exec).NeedResize(devicePath, deviceMountPath)
}

func (m *mounter) Resize(devicePath string, deviceMountPath string) (bool, error) {
return mount.NewResizeFs(m.exec).Resize(devicePath, deviceMountPath)
tpashkin marked this conversation as resolved.
Show resolved Hide resolved
}
Loading