diff --git a/pkg/util/BUILD b/pkg/util/BUILD index 53fd073fd98a..2c37ae02be0b 100644 --- a/pkg/util/BUILD +++ b/pkg/util/BUILD @@ -36,7 +36,6 @@ filegroup( "//pkg/util/pod:all-srcs", "//pkg/util/procfs:all-srcs", "//pkg/util/removeall:all-srcs", - "//pkg/util/resizefs:all-srcs", "//pkg/util/rlimit:all-srcs", "//pkg/util/selinux:all-srcs", "//pkg/util/slice:all-srcs", diff --git a/pkg/util/resizefs/BUILD b/pkg/util/resizefs/BUILD deleted file mode 100644 index 19f011b181a6..000000000000 --- a/pkg/util/resizefs/BUILD +++ /dev/null @@ -1,75 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = [ - "resizefs_linux.go", - "resizefs_unsupported.go", - ], - importpath = "k8s.io/kubernetes/pkg/util/resizefs", - visibility = ["//visibility:public"], - deps = select({ - "@io_bazel_rules_go//go/platform:aix": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:android": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - "//vendor/k8s.io/klog/v2:go_default_library", - ], - "@io_bazel_rules_go//go/platform:darwin": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:dragonfly": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:freebsd": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:illumos": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:ios": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:js": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:linux": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - "//vendor/k8s.io/klog/v2:go_default_library", - ], - "@io_bazel_rules_go//go/platform:nacl": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:netbsd": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:openbsd": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:plan9": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:solaris": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "@io_bazel_rules_go//go/platform:windows": [ - "//staging/src/k8s.io/mount-utils:go_default_library", - ], - "//conditions:default": [], - }), -) - -filegroup( - name = "package-srcs", - srcs = glob(["**"]), - tags = ["automanaged"], - visibility = ["//visibility:private"], -) - -filegroup( - name = "all-srcs", - srcs = [":package-srcs"], - tags = ["automanaged"], - visibility = ["//visibility:public"], -) diff --git a/pkg/volume/util/BUILD b/pkg/volume/util/BUILD index 9f0e8621cc0e..cc52359dbcaa 100644 --- a/pkg/volume/util/BUILD +++ b/pkg/volume/util/BUILD @@ -24,7 +24,6 @@ go_library( "//pkg/apis/core/v1/helper:go_default_library", "//pkg/features:go_default_library", "//pkg/securitycontext:go_default_library", - "//pkg/util/resizefs:go_default_library", "//pkg/volume:go_default_library", "//pkg/volume/util/types:go_default_library", "//pkg/volume/util/volumepathhandler:go_default_library", diff --git a/pkg/volume/util/resize_util.go b/pkg/volume/util/resize_util.go index 59d9c2a90c11..9249380dc94f 100644 --- a/pkg/volume/util/resize_util.go +++ b/pkg/volume/util/resize_util.go @@ -21,8 +21,6 @@ import ( "encoding/json" "fmt" - "k8s.io/mount-utils" - "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/resource" @@ -31,9 +29,9 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/strategicpatch" clientset "k8s.io/client-go/kubernetes" - "k8s.io/kubernetes/pkg/util/resizefs" "k8s.io/kubernetes/pkg/volume" volumetypes "k8s.io/kubernetes/pkg/volume/util/types" + "k8s.io/mount-utils" ) var ( @@ -266,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 := resizefs.NewResizeFs(diskFormatter) + resizer := mount.NewResizeFs(host.GetExec(pluginName)) return resizer.Resize(devicePath, deviceMountPath) } diff --git a/staging/src/k8s.io/mount-utils/BUILD b/staging/src/k8s.io/mount-utils/BUILD index d57b710fe825..3fc1fb852966 100644 --- a/staging/src/k8s.io/mount-utils/BUILD +++ b/staging/src/k8s.io/mount-utils/BUILD @@ -12,6 +12,8 @@ go_library( "mount_linux.go", "mount_unsupported.go", "mount_windows.go", + "resizefs_linux.go", + "resizefs_unsupported.go", ], importmap = "k8s.io/kubernetes/vendor/k8s.io/mount-utils", importpath = "k8s.io/mount-utils", diff --git a/staging/src/k8s.io/mount-utils/mount_linux.go b/staging/src/k8s.io/mount-utils/mount_linux.go index f4a45adf2449..10a1c3f01068 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/pkg/util/resizefs/resizefs_linux.go b/staging/src/k8s.io/mount-utils/resizefs_linux.go similarity index 83% rename from pkg/util/resizefs/resizefs_linux.go rename to staging/src/k8s.io/mount-utils/resizefs_linux.go index db47cacaa4aa..e2bfe4417276 100644 --- a/pkg/util/resizefs/resizefs_linux.go +++ b/staging/src/k8s.io/mount-utils/resizefs_linux.go @@ -1,7 +1,7 @@ // +build linux /* -Copyright 2017 The Kubernetes Authors. +Copyright 2021 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,28 +16,28 @@ See the License for the specific language governing permissions and limitations under the License. */ -package resizefs +package mount import ( "fmt" "k8s.io/klog/v2" - "k8s.io/mount-utils" + utilexec "k8s.io/utils/exec" ) // ResizeFs Provides support for resizing file systems type ResizeFs struct { - mounter *mount.SafeFormatAndMount + exec utilexec.Interface } // NewResizeFs returns new instance of resizer -func NewResizeFs(mounter *mount.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) @@ -61,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 @@ -74,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/pkg/util/resizefs/resizefs_unsupported.go b/staging/src/k8s.io/mount-utils/resizefs_unsupported.go similarity index 80% rename from pkg/util/resizefs/resizefs_unsupported.go rename to staging/src/k8s.io/mount-utils/resizefs_unsupported.go index 6fbae9ca477f..9cf11090c7c5 100644 --- a/pkg/util/resizefs/resizefs_unsupported.go +++ b/staging/src/k8s.io/mount-utils/resizefs_unsupported.go @@ -1,7 +1,7 @@ // +build !linux /* -Copyright 2017 The Kubernetes Authors. +Copyright 2021 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,22 +16,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -package resizefs +package mount import ( "fmt" - "k8s.io/mount-utils" + utilexec "k8s.io/utils/exec" ) // ResizeFs Provides support for resizing file systems type ResizeFs struct { - mounter *mount.SafeFormatAndMount + exec utilexec.Interface } // NewResizeFs returns new instance of resizer -func NewResizeFs(mounter *mount.SafeFormatAndMount) *ResizeFs { - return &ResizeFs{mounter: mounter} +func NewResizeFs(exec utilexec.Interface) *ResizeFs { + return &ResizeFs{exec: exec} } // Resize perform resize of file system