Use utilexec.Interface instead of SafeFormatAndMount as filed of ResizeFs

This commit is contained in:
drfish 2021-02-20 22:28:43 +08:00
parent a04ab9debf
commit eb0b61912f
4 changed files with 21 additions and 18 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -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)

View File

@ -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