From eb0b61912ffd37d4d3c44fd2dec44ceb7ff299df Mon Sep 17 00:00:00 2001 From: drfish Date: Sat, 20 Feb 2021 22:28:43 +0800 Subject: [PATCH] Use utilexec.Interface instead of SafeFormatAndMount as filed of ResizeFs --- pkg/volume/util/resize_util.go | 7 +------ staging/src/k8s.io/mount-utils/mount_linux.go | 10 +++++++--- staging/src/k8s.io/mount-utils/resizefs_linux.go | 14 ++++++++------ .../src/k8s.io/mount-utils/resizefs_unsupported.go | 8 +++++--- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/pkg/volume/util/resize_util.go b/pkg/volume/util/resize_util.go index 853a4f33706..9249380dc94 100644 --- a/pkg/volume/util/resize_util.go +++ b/pkg/volume/util/resize_util.go @@ -264,11 +264,6 @@ func MergeResizeConditionOnPVC( // GenericResizeFS : call generic filesystem resizer for plugins that don't have any special filesystem resize requirements func GenericResizeFS(host volume.VolumeHost, pluginName, devicePath, deviceMountPath string) (bool, error) { - mounter := host.GetMounter(pluginName) - diskFormatter := &mount.SafeFormatAndMount{ - Interface: mounter, - Exec: host.GetExec(pluginName), - } - resizer := mount.NewResizeFs(diskFormatter) + resizer := mount.NewResizeFs(host.GetExec(pluginName)) return resizer.Resize(devicePath, deviceMountPath) } diff --git a/staging/src/k8s.io/mount-utils/mount_linux.go b/staging/src/k8s.io/mount-utils/mount_linux.go index f4a45adf244..10a1c3f0106 100644 --- a/staging/src/k8s.io/mount-utils/mount_linux.go +++ b/staging/src/k8s.io/mount-utils/mount_linux.go @@ -441,11 +441,10 @@ func (mounter *SafeFormatAndMount) formatAndMountSensitive(source string, target return nil } -// GetDiskFormat uses 'blkid' to see if the given disk is unformatted -func (mounter *SafeFormatAndMount) GetDiskFormat(disk string) (string, error) { +func getDiskFormat(exec utilexec.Interface, disk string) (string, error) { args := []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", disk} klog.V(4).Infof("Attempting to determine if disk %q is formatted using blkid with args: (%v)", disk, args) - dataOut, err := mounter.Exec.Command("blkid", args...).CombinedOutput() + dataOut, err := exec.Command("blkid", args...).CombinedOutput() output := string(dataOut) klog.V(4).Infof("Output: %q", output) @@ -494,6 +493,11 @@ func (mounter *SafeFormatAndMount) GetDiskFormat(disk string) (string, error) { return fstype, nil } +// GetDiskFormat uses 'blkid' to see if the given disk is unformatted +func (mounter *SafeFormatAndMount) GetDiskFormat(disk string) (string, error) { + return getDiskFormat(mounter.Exec, disk) +} + // ListProcMounts is shared with NsEnterMounter func ListProcMounts(mountFilePath string) ([]MountPoint, error) { content, err := utilio.ConsistentRead(mountFilePath, maxListTries) diff --git a/staging/src/k8s.io/mount-utils/resizefs_linux.go b/staging/src/k8s.io/mount-utils/resizefs_linux.go index 19eba6c8781..e2bfe441727 100644 --- a/staging/src/k8s.io/mount-utils/resizefs_linux.go +++ b/staging/src/k8s.io/mount-utils/resizefs_linux.go @@ -20,22 +20,24 @@ package mount import ( "fmt" + "k8s.io/klog/v2" + utilexec "k8s.io/utils/exec" ) // ResizeFs Provides support for resizing file systems type ResizeFs struct { - mounter *SafeFormatAndMount + exec utilexec.Interface } // NewResizeFs returns new instance of resizer -func NewResizeFs(mounter *SafeFormatAndMount) *ResizeFs { - return &ResizeFs{mounter: mounter} +func NewResizeFs(exec utilexec.Interface) *ResizeFs { + return &ResizeFs{exec: exec} } // Resize perform resize of file system func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (bool, error) { - format, err := resizefs.mounter.GetDiskFormat(devicePath) + format, err := getDiskFormat(resizefs.exec, devicePath) if err != nil { formatErr := fmt.Errorf("ResizeFS.Resize - error checking format for device %s: %v", devicePath, err) @@ -59,7 +61,7 @@ func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (boo } func (resizefs *ResizeFs) extResize(devicePath string) (bool, error) { - output, err := resizefs.mounter.Exec.Command("resize2fs", devicePath).CombinedOutput() + output, err := resizefs.exec.Command("resize2fs", devicePath).CombinedOutput() if err == nil { klog.V(2).Infof("Device %s resized successfully", devicePath) return true, nil @@ -72,7 +74,7 @@ func (resizefs *ResizeFs) extResize(devicePath string) (bool, error) { func (resizefs *ResizeFs) xfsResize(deviceMountPath string) (bool, error) { args := []string{"-d", deviceMountPath} - output, err := resizefs.mounter.Exec.Command("xfs_growfs", args...).CombinedOutput() + output, err := resizefs.exec.Command("xfs_growfs", args...).CombinedOutput() if err == nil { klog.V(2).Infof("Device %s resized successfully", deviceMountPath) diff --git a/staging/src/k8s.io/mount-utils/resizefs_unsupported.go b/staging/src/k8s.io/mount-utils/resizefs_unsupported.go index 9b5fc70afe5..9cf11090c7c 100644 --- a/staging/src/k8s.io/mount-utils/resizefs_unsupported.go +++ b/staging/src/k8s.io/mount-utils/resizefs_unsupported.go @@ -20,16 +20,18 @@ package mount import ( "fmt" + + utilexec "k8s.io/utils/exec" ) // ResizeFs Provides support for resizing file systems type ResizeFs struct { - mounter *SafeFormatAndMount + exec utilexec.Interface } // NewResizeFs returns new instance of resizer -func NewResizeFs(mounter *SafeFormatAndMount) *ResizeFs { - return &ResizeFs{mounter: mounter} +func NewResizeFs(exec utilexec.Interface) *ResizeFs { + return &ResizeFs{exec: exec} } // Resize perform resize of file system