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

Storage: move filesystem resize code to kubernetes/mount-utils #99088

Merged
merged 2 commits into from Feb 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/util/BUILD
Expand Up @@ -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",
Expand Down
75 changes: 0 additions & 75 deletions pkg/util/resizefs/BUILD

This file was deleted.

1 change: 0 additions & 1 deletion pkg/volume/util/BUILD
Expand Up @@ -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",
Expand Down
11 changes: 2 additions & 9 deletions pkg/volume/util/resize_util.go
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions staging/src/k8s.io/mount-utils/BUILD
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions staging/src/k8s.io/mount-utils/mount_linux.go
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
@@ -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.
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
@@ -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.
Expand All @@ -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
Expand Down