mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Move ExecMount to pkg/volume/util/exec
This patch moves the ExecMounter found in pkg/util/mount to pkg/volume/util/exec. This is done in preparation for pkg/util/mount to move out of tree. This specific implemention of mount.Interface is only used internally to K8s and does not need to move out of tree.
This commit is contained in:
parent
ca55432599
commit
f38d4938be
@ -110,6 +110,7 @@ go_library(
|
|||||||
"//pkg/volume:go_default_library",
|
"//pkg/volume:go_default_library",
|
||||||
"//pkg/volume/csi:go_default_library",
|
"//pkg/volume/csi:go_default_library",
|
||||||
"//pkg/volume/util:go_default_library",
|
"//pkg/volume/util:go_default_library",
|
||||||
|
"//pkg/volume/util/exec:go_default_library",
|
||||||
"//pkg/volume/util/subpath:go_default_library",
|
"//pkg/volume/util/subpath:go_default_library",
|
||||||
"//pkg/volume/util/types:go_default_library",
|
"//pkg/volume/util/types:go_default_library",
|
||||||
"//pkg/volume/util/volumepathhandler:go_default_library",
|
"//pkg/volume/util/volumepathhandler:go_default_library",
|
||||||
|
@ -43,6 +43,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
"k8s.io/kubernetes/pkg/volume/util"
|
"k8s.io/kubernetes/pkg/volume/util"
|
||||||
|
execmnt "k8s.io/kubernetes/pkg/volume/util/exec"
|
||||||
"k8s.io/kubernetes/pkg/volume/util/subpath"
|
"k8s.io/kubernetes/pkg/volume/util/subpath"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -230,7 +231,7 @@ func (kvh *kubeletVolumeHost) GetMounter(pluginName string) mount.Interface {
|
|||||||
if exec == nil {
|
if exec == nil {
|
||||||
return kvh.kubelet.mounter
|
return kvh.kubelet.mounter
|
||||||
}
|
}
|
||||||
return mount.NewExecMounter(exec, kvh.kubelet.mounter)
|
return execmnt.NewExecMounter(exec, kvh.kubelet.mounter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kvh *kubeletVolumeHost) GetHostName() string {
|
func (kvh *kubeletVolumeHost) GetHostName() string {
|
||||||
|
@ -5,8 +5,6 @@ go_library(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"doc.go",
|
"doc.go",
|
||||||
"exec.go",
|
"exec.go",
|
||||||
"exec_mount.go",
|
|
||||||
"exec_mount_unsupported.go",
|
|
||||||
"fake.go",
|
"fake.go",
|
||||||
"mount.go",
|
"mount.go",
|
||||||
"mount_helper_common.go",
|
"mount_helper_common.go",
|
||||||
@ -38,7 +36,6 @@ go_library(
|
|||||||
go_test(
|
go_test(
|
||||||
name = "go_default_test",
|
name = "go_default_test",
|
||||||
srcs = [
|
srcs = [
|
||||||
"exec_mount_test.go",
|
|
||||||
"mount_helper_test.go",
|
"mount_helper_test.go",
|
||||||
"mount_linux_test.go",
|
"mount_linux_test.go",
|
||||||
"mount_test.go",
|
"mount_test.go",
|
||||||
|
@ -84,6 +84,7 @@ filegroup(
|
|||||||
name = "all-srcs",
|
name = "all-srcs",
|
||||||
srcs = [
|
srcs = [
|
||||||
":package-srcs",
|
":package-srcs",
|
||||||
|
"//pkg/volume/util/exec:all-srcs",
|
||||||
"//pkg/volume/util/fs:all-srcs",
|
"//pkg/volume/util/fs:all-srcs",
|
||||||
"//pkg/volume/util/nestedpendingoperations:all-srcs",
|
"//pkg/volume/util/nestedpendingoperations:all-srcs",
|
||||||
"//pkg/volume/util/nsenter:all-srcs",
|
"//pkg/volume/util/nsenter:all-srcs",
|
||||||
|
74
pkg/volume/util/exec/BUILD
Normal file
74
pkg/volume/util/exec/BUILD
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = [
|
||||||
|
"exec_mount.go",
|
||||||
|
"exec_mount_unsupported.go",
|
||||||
|
],
|
||||||
|
importpath = "k8s.io/kubernetes/pkg/volume/util/exec",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = select({
|
||||||
|
"@io_bazel_rules_go//go/platform:android": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:darwin": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:dragonfly": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:freebsd": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:linux": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:nacl": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:netbsd": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:openbsd": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:plan9": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:solaris": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:windows": [
|
||||||
|
"//pkg/util/mount:go_default_library",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "go_default_test",
|
||||||
|
srcs = ["exec_mount_test.go"],
|
||||||
|
embed = [":go_default_library"],
|
||||||
|
deps = select({
|
||||||
|
"@io_bazel_rules_go//go/platform:linux": [
|
||||||
|
"//pkg/util/mount: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"],
|
||||||
|
)
|
@ -16,23 +16,25 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mount
|
package exec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExecMounter is a mounter that uses provided Exec interface to mount and
|
// ExecMounter is a mounter that uses provided Exec interface to mount and
|
||||||
// unmount a filesystem. For all other calls it uses a wrapped mounter.
|
// unmount a filesystem. For all other calls it uses a wrapped mounter.
|
||||||
type execMounter struct {
|
type execMounter struct {
|
||||||
wrappedMounter Interface
|
wrappedMounter mount.Interface
|
||||||
exec Exec
|
exec mount.Exec
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExecMounter(exec Exec, wrapped Interface) Interface {
|
func NewExecMounter(exec mount.Exec, wrapped mount.Interface) mount.Interface {
|
||||||
return &execMounter{
|
return &execMounter{
|
||||||
wrappedMounter: wrapped,
|
wrappedMounter: wrapped,
|
||||||
exec: exec,
|
exec: exec,
|
||||||
@ -40,11 +42,11 @@ func NewExecMounter(exec Exec, wrapped Interface) Interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// execMounter implements mount.Interface
|
// execMounter implements mount.Interface
|
||||||
var _ Interface = &execMounter{}
|
var _ mount.Interface = &execMounter{}
|
||||||
|
|
||||||
// Mount runs mount(8) using given exec interface.
|
// Mount runs mount(8) using given exec interface.
|
||||||
func (m *execMounter) Mount(source string, target string, fstype string, options []string) error {
|
func (m *execMounter) Mount(source string, target string, fstype string, options []string) error {
|
||||||
bind, bindOpts, bindRemountOpts := IsBind(options)
|
bind, bindOpts, bindRemountOpts := mount.IsBind(options)
|
||||||
|
|
||||||
if bind {
|
if bind {
|
||||||
err := m.doExecMount(source, target, fstype, bindOpts)
|
err := m.doExecMount(source, target, fstype, bindOpts)
|
||||||
@ -60,7 +62,7 @@ func (m *execMounter) Mount(source string, target string, fstype string, options
|
|||||||
// doExecMount calls exec(mount <what> <where>) using given exec interface.
|
// doExecMount calls exec(mount <what> <where>) using given exec interface.
|
||||||
func (m *execMounter) doExecMount(source, target, fstype string, options []string) error {
|
func (m *execMounter) doExecMount(source, target, fstype string, options []string) error {
|
||||||
klog.V(5).Infof("Exec Mounting %s %s %s %v", source, target, fstype, options)
|
klog.V(5).Infof("Exec Mounting %s %s %s %v", source, target, fstype, options)
|
||||||
mountArgs := MakeMountArgs(source, target, fstype, options)
|
mountArgs := mount.MakeMountArgs(source, target, fstype, options)
|
||||||
output, err := m.exec.Run("mount", mountArgs...)
|
output, err := m.exec.Run("mount", mountArgs...)
|
||||||
klog.V(5).Infof("Exec mounted %v: %v: %s", mountArgs, err, string(output))
|
klog.V(5).Infof("Exec mounted %v: %v: %s", mountArgs, err, string(output))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -84,7 +86,7 @@ func (m *execMounter) Unmount(target string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List returns a list of all mounted filesystems.
|
// List returns a list of all mounted filesystems.
|
||||||
func (m *execMounter) List() ([]MountPoint, error) {
|
func (m *execMounter) List() ([]mount.MountPoint, error) {
|
||||||
return m.wrappedMounter.List()
|
return m.wrappedMounter.List()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +114,7 @@ func (m *execMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (strin
|
|||||||
return m.wrappedMounter.GetDeviceNameFromMount(mountPath, pluginDir)
|
return m.wrappedMounter.GetDeviceNameFromMount(mountPath, pluginDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *execMounter) IsMountPointMatch(mp MountPoint, dir string) bool {
|
func (m *execMounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
|
||||||
return m.wrappedMounter.IsMountPointMatch(mp, dir)
|
return m.wrappedMounter.IsMountPointMatch(mp, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +122,7 @@ func (m *execMounter) MakeRShared(path string) error {
|
|||||||
return m.wrappedMounter.MakeRShared(path)
|
return m.wrappedMounter.MakeRShared(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *execMounter) GetFileType(pathname string) (FileType, error) {
|
func (m *execMounter) GetFileType(pathname string) (mount.FileType, error) {
|
||||||
return m.wrappedMounter.GetFileType(pathname)
|
return m.wrappedMounter.GetFileType(pathname)
|
||||||
}
|
}
|
||||||
|
|
@ -16,13 +16,15 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mount
|
package exec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -33,7 +35,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMount(t *testing.T) {
|
func TestMount(t *testing.T) {
|
||||||
exec := NewFakeExec(func(cmd string, args ...string) ([]byte, error) {
|
exec := mount.NewFakeExec(func(cmd string, args ...string) ([]byte, error) {
|
||||||
if cmd != "mount" {
|
if cmd != "mount" {
|
||||||
t.Errorf("expected mount command, got %q", cmd)
|
t.Errorf("expected mount command, got %q", cmd)
|
||||||
}
|
}
|
||||||
@ -45,7 +47,7 @@ func TestMount(t *testing.T) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
wrappedMounter := &fakeMounter{FakeMounter: &FakeMounter{}, t: t}
|
wrappedMounter := &fakeMounter{FakeMounter: &mount.FakeMounter{}, t: t}
|
||||||
mounter := NewExecMounter(exec, wrappedMounter)
|
mounter := NewExecMounter(exec, wrappedMounter)
|
||||||
|
|
||||||
mounter.Mount(sourcePath, destinationPath, fsType, mountOptions)
|
mounter.Mount(sourcePath, destinationPath, fsType, mountOptions)
|
||||||
@ -53,7 +55,7 @@ func TestMount(t *testing.T) {
|
|||||||
|
|
||||||
func TestBindMount(t *testing.T) {
|
func TestBindMount(t *testing.T) {
|
||||||
cmdCount := 0
|
cmdCount := 0
|
||||||
exec := NewFakeExec(func(cmd string, args ...string) ([]byte, error) {
|
exec := mount.NewFakeExec(func(cmd string, args ...string) ([]byte, error) {
|
||||||
cmdCount++
|
cmdCount++
|
||||||
if cmd != "mount" {
|
if cmd != "mount" {
|
||||||
t.Errorf("expected mount command, got %q", cmd)
|
t.Errorf("expected mount command, got %q", cmd)
|
||||||
@ -73,14 +75,14 @@ func TestBindMount(t *testing.T) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
wrappedMounter := &fakeMounter{FakeMounter: &FakeMounter{}, t: t}
|
wrappedMounter := &fakeMounter{FakeMounter: &mount.FakeMounter{}, t: t}
|
||||||
mounter := NewExecMounter(exec, wrappedMounter)
|
mounter := NewExecMounter(exec, wrappedMounter)
|
||||||
bindOptions := append(mountOptions, "bind")
|
bindOptions := append(mountOptions, "bind")
|
||||||
mounter.Mount(sourcePath, destinationPath, fsType, bindOptions)
|
mounter.Mount(sourcePath, destinationPath, fsType, bindOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmount(t *testing.T) {
|
func TestUnmount(t *testing.T) {
|
||||||
exec := NewFakeExec(func(cmd string, args ...string) ([]byte, error) {
|
exec := mount.NewFakeExec(func(cmd string, args ...string) ([]byte, error) {
|
||||||
if cmd != "umount" {
|
if cmd != "umount" {
|
||||||
t.Errorf("expected unmount command, got %q", cmd)
|
t.Errorf("expected unmount command, got %q", cmd)
|
||||||
}
|
}
|
||||||
@ -92,7 +94,7 @@ func TestUnmount(t *testing.T) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
wrappedMounter := &fakeMounter{&FakeMounter{}, t}
|
wrappedMounter := &fakeMounter{&mount.FakeMounter{}, t}
|
||||||
mounter := NewExecMounter(exec, wrappedMounter)
|
mounter := NewExecMounter(exec, wrappedMounter)
|
||||||
|
|
||||||
mounter.Unmount(destinationPath)
|
mounter.Unmount(destinationPath)
|
||||||
@ -100,7 +102,7 @@ func TestUnmount(t *testing.T) {
|
|||||||
|
|
||||||
/* Fake wrapped mounter */
|
/* Fake wrapped mounter */
|
||||||
type fakeMounter struct {
|
type fakeMounter struct {
|
||||||
*FakeMounter
|
*mount.FakeMounter
|
||||||
t *testing.T
|
t *testing.T
|
||||||
}
|
}
|
||||||
|
|
@ -16,18 +16,20 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mount
|
package exec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
)
|
)
|
||||||
|
|
||||||
type execMounter struct{}
|
type execMounter struct{}
|
||||||
|
|
||||||
// ExecMounter is a mounter that uses provided Exec interface to mount and
|
// ExecMounter is a mounter that uses provided Exec interface to mount and
|
||||||
// unmount a filesystem. For all other calls it uses a wrapped mounter.
|
// unmount a filesystem. For all other calls it uses a wrapped mounter.
|
||||||
func NewExecMounter(exec Exec, wrapped Interface) Interface {
|
func NewExecMounter(exec mount.Exec, wrapped mount.Interface) mount.Interface {
|
||||||
return &execMounter{}
|
return &execMounter{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,11 +41,11 @@ func (mounter *execMounter) Unmount(target string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mounter *execMounter) List() ([]MountPoint, error) {
|
func (mounter *execMounter) List() ([]mount.MountPoint, error) {
|
||||||
return []MountPoint{}, nil
|
return []mount.MountPoint{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mounter *execMounter) IsMountPointMatch(mp MountPoint, dir string) bool {
|
func (mounter *execMounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
|
||||||
return (mp.Path == dir)
|
return (mp.Path == dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,8 +69,8 @@ func (mounter *execMounter) MakeRShared(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mounter *execMounter) GetFileType(pathname string) (FileType, error) {
|
func (mounter *execMounter) GetFileType(pathname string) (mount.FileType, error) {
|
||||||
return FileType("fake"), errors.New("not implemented")
|
return mount.FileType("fake"), errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mounter *execMounter) MakeDir(pathname string) error {
|
func (mounter *execMounter) MakeDir(pathname string) error {
|
Loading…
Reference in New Issue
Block a user