From c23e96a03f13365f493d82a7561fdc2fe0780a5f Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Tue, 3 Jul 2018 11:08:32 -0400 Subject: [PATCH 1/2] UPSTREAM: 64426: Clean up fake mounters. --- .../cm/container_manager_linux_test.go | 110 ++---------------- .../pkg/util/mount/exec_mount_test.go | 73 +----------- .../k8s.io/kubernetes/pkg/util/mount/fake.go | 9 +- .../pkg/util/removeall/removeall_test.go | 87 +------------- .../pkg/volume/host_path/host_path_test.go | 93 +-------------- 5 files changed, 29 insertions(+), 343 deletions(-) diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/cm/container_manager_linux_test.go b/vendor/k8s.io/kubernetes/pkg/kubelet/cm/container_manager_linux_test.go index 127140e751a1..882a3ea7bd49 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubelet/cm/container_manager_linux_test.go +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/cm/container_manager_linux_test.go @@ -19,8 +19,6 @@ limitations under the License. package cm import ( - "errors" - "fmt" "io/ioutil" "os" "path" @@ -32,101 +30,9 @@ import ( "k8s.io/kubernetes/pkg/util/mount" ) -type fakeMountInterface struct { - mountPoints []mount.MountPoint -} - -func (mi *fakeMountInterface) Mount(source string, target string, fstype string, options []string) error { - return fmt.Errorf("unsupported") -} - -func (mi *fakeMountInterface) Unmount(target string) error { - return fmt.Errorf("unsupported") -} - -func (mi *fakeMountInterface) List() ([]mount.MountPoint, error) { - return mi.mountPoints, nil -} - -func (mi *fakeMountInterface) IsMountPointMatch(mp mount.MountPoint, dir string) bool { - return (mp.Path == dir) -} - -func (mi *fakeMountInterface) IsNotMountPoint(dir string) (bool, error) { - return false, fmt.Errorf("unsupported") -} - -func (mi *fakeMountInterface) IsLikelyNotMountPoint(file string) (bool, error) { - return false, fmt.Errorf("unsupported") -} -func (mi *fakeMountInterface) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return "", nil -} - -func (mi *fakeMountInterface) DeviceOpened(pathname string) (bool, error) { - for _, mp := range mi.mountPoints { - if mp.Device == pathname { - return true, nil - } - } - return false, nil -} - -func (mi *fakeMountInterface) PathIsDevice(pathname string) (bool, error) { - return true, nil -} - -func (mi *fakeMountInterface) MakeRShared(path string) error { - return nil -} - -func (mi *fakeMountInterface) GetFileType(pathname string) (mount.FileType, error) { - return mount.FileType("fake"), nil -} - -func (mi *fakeMountInterface) MakeDir(pathname string) error { - return nil -} - -func (mi *fakeMountInterface) MakeFile(pathname string) error { - return nil -} - -func (mi *fakeMountInterface) ExistsPath(pathname string) (bool, error) { - return true, errors.New("not implemented") -} - -func (mi *fakeMountInterface) PrepareSafeSubpath(subPath mount.Subpath) (newHostPath string, cleanupAction func(), err error) { - return "", nil, nil -} - -func (mi *fakeMountInterface) CleanSubPaths(_, _ string) error { - return nil -} - -func (mi *fakeMountInterface) SafeMakeDir(_, _ string, _ os.FileMode) error { - return nil -} - -func (mi *fakeMountInterface) GetMountRefs(pathname string) ([]string, error) { - return nil, errors.New("not implemented") -} - -func (mi *fakeMountInterface) GetFSGroup(pathname string) (int64, error) { - return -1, errors.New("not implemented") -} - -func (mi *fakeMountInterface) GetSELinuxSupport(pathname string) (bool, error) { - return false, errors.New("not implemented") -} - -func (mi *fakeMountInterface) GetMode(pathname string) (os.FileMode, error) { - return 0, errors.New("not implemented") -} - func fakeContainerMgrMountInt() mount.Interface { - return &fakeMountInterface{ - []mount.MountPoint{ + return &mount.FakeMounter{ + MountPoints: []mount.MountPoint{ { Device: "cgroup", Type: "cgroup", @@ -158,8 +64,8 @@ func TestCgroupMountValidationSuccess(t *testing.T) { } func TestCgroupMountValidationMemoryMissing(t *testing.T) { - mountInt := &fakeMountInterface{ - []mount.MountPoint{ + mountInt := &mount.FakeMounter{ + MountPoints: []mount.MountPoint{ { Device: "cgroup", Type: "cgroup", @@ -182,8 +88,8 @@ func TestCgroupMountValidationMemoryMissing(t *testing.T) { } func TestCgroupMountValidationMultipleSubsystem(t *testing.T) { - mountInt := &fakeMountInterface{ - []mount.MountPoint{ + mountInt := &mount.FakeMounter{ + MountPoints: []mount.MountPoint{ { Device: "cgroup", Type: "cgroup", @@ -212,8 +118,8 @@ func TestSoftRequirementsValidationSuccess(t *testing.T) { defer os.RemoveAll(tempDir) req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_period_us"), []byte("0"), os.ModePerm)) req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_quota_us"), []byte("0"), os.ModePerm)) - mountInt := &fakeMountInterface{ - []mount.MountPoint{ + mountInt := &mount.FakeMounter{ + MountPoints: []mount.MountPoint{ { Device: "cgroup", Type: "cgroup", diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount_test.go b/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount_test.go index 9619356f71b5..d6ccd8448950 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount_test.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount_test.go @@ -19,9 +19,7 @@ limitations under the License. package mount import ( - "errors" "fmt" - "os" "reflect" "strings" "testing" @@ -47,7 +45,7 @@ func TestMount(t *testing.T) { return nil, nil }) - wrappedMounter := &fakeMounter{t} + wrappedMounter := &fakeMounter{FakeMounter: &FakeMounter{}, t: t} mounter := NewExecMounter(exec, wrappedMounter) mounter.Mount(sourcePath, destinationPath, fsType, mountOptions) @@ -75,7 +73,7 @@ func TestBindMount(t *testing.T) { return nil, nil }) - wrappedMounter := &fakeMounter{t} + wrappedMounter := &fakeMounter{FakeMounter: &FakeMounter{}, t: t} mounter := NewExecMounter(exec, wrappedMounter) bindOptions := append(mountOptions, "bind") mounter.Mount(sourcePath, destinationPath, fsType, bindOptions) @@ -94,7 +92,7 @@ func TestUnmount(t *testing.T) { return nil, nil }) - wrappedMounter := &fakeMounter{t} + wrappedMounter := &fakeMounter{&FakeMounter{}, t} mounter := NewExecMounter(exec, wrappedMounter) mounter.Unmount(destinationPath) @@ -102,6 +100,7 @@ func TestUnmount(t *testing.T) { /* Fake wrapped mounter */ type fakeMounter struct { + *FakeMounter t *testing.T } @@ -116,67 +115,3 @@ func (fm *fakeMounter) Unmount(target string) error { fm.t.Errorf("Unexpected wrapped mount call") return fmt.Errorf("Unexpected wrapped mount call") } - -func (fm *fakeMounter) List() ([]MountPoint, error) { - return nil, nil -} -func (fm *fakeMounter) IsMountPointMatch(mp MountPoint, dir string) bool { - return false -} -func (fm *fakeMounter) IsNotMountPoint(file string) (bool, error) { - return false, nil -} -func (fm *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) { - return false, nil -} -func (fm *fakeMounter) DeviceOpened(pathname string) (bool, error) { - return false, nil -} -func (fm *fakeMounter) PathIsDevice(pathname string) (bool, error) { - return false, nil -} -func (fm *fakeMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return "", nil -} -func (fm *fakeMounter) MakeRShared(path string) error { - return nil -} -func (fm *fakeMounter) MakeFile(pathname string) error { - return nil -} -func (fm *fakeMounter) MakeDir(pathname string) error { - return nil -} -func (fm *fakeMounter) ExistsPath(pathname string) (bool, error) { - return false, errors.New("not implemented") -} -func (fm *fakeMounter) GetFileType(pathname string) (FileType, error) { - return FileTypeFile, nil -} -func (fm *fakeMounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) { - return subPath.Path, nil, nil -} - -func (fm *fakeMounter) CleanSubPaths(podDir string, volumeName string) error { - return nil -} - -func (fm *fakeMounter) SafeMakeDir(pathname string, base string, perm os.FileMode) error { - return nil -} - -func (fm *fakeMounter) GetMountRefs(pathname string) ([]string, error) { - return nil, errors.New("not implemented") -} - -func (fm *fakeMounter) GetFSGroup(pathname string) (int64, error) { - return -1, errors.New("not implemented") -} - -func (fm *fakeMounter) GetSELinuxSupport(pathname string) (bool, error) { - return false, errors.New("not implemented") -} - -func (fm *fakeMounter) GetMode(pathname string) (os.FileMode, error) { - return 0, errors.New("not implemented") -} diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/fake.go b/vendor/k8s.io/kubernetes/pkg/util/mount/fake.go index 10832fd321b0..55c99c9fe3d1 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/fake.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/fake.go @@ -29,6 +29,7 @@ import ( type FakeMounter struct { MountPoints []MountPoint Log []FakeAction + Filesystem map[string]FileType // Some tests run things in parallel, make sure the mounter does not produce // any golang's DATA RACE warnings. mutex sync.Mutex @@ -190,6 +191,9 @@ func (f *FakeMounter) MakeRShared(path string) error { } func (f *FakeMounter) GetFileType(pathname string) (FileType, error) { + if t, ok := f.Filesystem[pathname]; ok { + return t, nil + } return FileType("fake"), nil } @@ -202,7 +206,10 @@ func (f *FakeMounter) MakeFile(pathname string) error { } func (f *FakeMounter) ExistsPath(pathname string) (bool, error) { - return false, errors.New("not implemented") + if _, ok := f.Filesystem[pathname]; ok { + return true, nil + } + return false, nil } func (f *FakeMounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) { diff --git a/vendor/k8s.io/kubernetes/pkg/util/removeall/removeall_test.go b/vendor/k8s.io/kubernetes/pkg/util/removeall/removeall_test.go index 1b67cc981f89..07db7718ed08 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/removeall/removeall_test.go +++ b/vendor/k8s.io/kubernetes/pkg/util/removeall/removeall_test.go @@ -27,87 +27,12 @@ import ( "k8s.io/kubernetes/pkg/util/mount" ) -type fakeMounter struct{} - -var _ mount.Interface = &fakeMounter{} - -func (mounter *fakeMounter) Mount(source string, target string, fstype string, options []string) error { - return errors.New("not implemented") -} - -func (mounter *fakeMounter) Unmount(target string) error { - return errors.New("not implemented") -} - -func (mounter *fakeMounter) List() ([]mount.MountPoint, error) { - return nil, errors.New("not implemented") -} - -func (mounter fakeMounter) DeviceOpened(pathname string) (bool, error) { - return false, errors.New("not implemented") -} - -func (mounter *fakeMounter) PathIsDevice(pathname string) (bool, error) { - return false, errors.New("not implemented") -} - -func (mounter *fakeMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return "", errors.New("not implemented") -} - -func (mounter *fakeMounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool { - return mp.Path == dir -} - -func (mounter *fakeMounter) IsNotMountPoint(dir string) (bool, error) { - return mount.IsNotMountPoint(mounter, dir) -} - -func (mounter *fakeMounter) GetFileType(pathname string) (mount.FileType, error) { - return mount.FileType("fake"), errors.New("not implemented") -} - -func (mounter *fakeMounter) MakeDir(pathname string) error { - return nil +type fakeMounter struct { + mount.FakeMounter } -func (mounter *fakeMounter) MakeFile(pathname string) error { - return nil -} - -func (mounter *fakeMounter) ExistsPath(pathname string) (bool, error) { - return true, errors.New("not implemented") -} - -func (mounter *fakeMounter) PrepareSafeSubpath(subPath mount.Subpath) (newHostPath string, cleanupAction func(), err error) { - return "", nil, nil -} - -func (mounter *fakeMounter) CleanSubPaths(_, _ string) error { - return nil -} - -func (mounter *fakeMounter) SafeMakeDir(_, _ string, _ os.FileMode) error { - return nil -} - -func (mounter *fakeMounter) GetMountRefs(pathname string) ([]string, error) { - return nil, errors.New("not implemented") -} - -func (mounter *fakeMounter) GetFSGroup(pathname string) (int64, error) { - return -1, errors.New("not implemented") -} - -func (mounter *fakeMounter) GetSELinuxSupport(pathname string) (bool, error) { - return false, errors.New("not implemented") -} - -func (mounter *fakeMounter) GetMode(pathname string) (os.FileMode, error) { - return 0, errors.New("not implemented") -} - -func (mounter *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) { +// IsLikelyNotMountPoint overrides mount.FakeMounter.IsLikelyNotMountPoint for our use. +func (f *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) { name := path.Base(file) if strings.HasPrefix(name, "mount") { return false, nil @@ -118,10 +43,6 @@ func (mounter *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) { return true, nil } -func (mounter *fakeMounter) MakeRShared(path string) error { - return nil -} - func TestRemoveAllOneFilesystem(t *testing.T) { tests := []struct { name string diff --git a/vendor/k8s.io/kubernetes/pkg/volume/host_path/host_path_test.go b/vendor/k8s.io/kubernetes/pkg/volume/host_path/host_path_test.go index 79d4a063f38e..3824acede12f 100644 --- a/vendor/k8s.io/kubernetes/pkg/volume/host_path/host_path_test.go +++ b/vendor/k8s.io/kubernetes/pkg/volume/host_path/host_path_test.go @@ -17,7 +17,6 @@ limitations under the License. package host_path import ( - "errors" "fmt" "os" "testing" @@ -319,92 +318,6 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { } } -type fakeFileTypeChecker struct { - desiredType string -} - -func (fftc *fakeFileTypeChecker) Mount(source string, target string, fstype string, options []string) error { - return nil -} - -func (fftc *fakeFileTypeChecker) Unmount(target string) error { - return nil -} - -func (fftc *fakeFileTypeChecker) List() ([]utilmount.MountPoint, error) { - return nil, nil -} -func (fftc *fakeFileTypeChecker) IsMountPointMatch(mp utilmount.MountPoint, dir string) bool { - return false -} - -func (fftc *fakeFileTypeChecker) IsNotMountPoint(file string) (bool, error) { - return false, nil -} - -func (fftc *fakeFileTypeChecker) IsLikelyNotMountPoint(file string) (bool, error) { - return false, nil -} - -func (fftc *fakeFileTypeChecker) DeviceOpened(pathname string) (bool, error) { - return false, nil -} -func (fftc *fakeFileTypeChecker) PathIsDevice(pathname string) (bool, error) { - return false, nil -} - -func (fftc *fakeFileTypeChecker) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return "fake", nil -} - -func (fftc *fakeFileTypeChecker) MakeRShared(path string) error { - return nil -} - -func (fftc *fakeFileTypeChecker) MakeFile(pathname string) error { - return nil -} - -func (fftc *fakeFileTypeChecker) MakeDir(pathname string) error { - return nil -} - -func (fftc *fakeFileTypeChecker) ExistsPath(pathname string) (bool, error) { - return true, nil -} - -func (fftc *fakeFileTypeChecker) GetFileType(_ string) (utilmount.FileType, error) { - return utilmount.FileType(fftc.desiredType), nil -} - -func (fftc *fakeFileTypeChecker) PrepareSafeSubpath(subPath utilmount.Subpath) (newHostPath string, cleanupAction func(), err error) { - return "", nil, nil -} - -func (fftc *fakeFileTypeChecker) CleanSubPaths(_, _ string) error { - return nil -} - -func (fftc *fakeFileTypeChecker) SafeMakeDir(_, _ string, _ os.FileMode) error { - return nil -} - -func (fftc *fakeFileTypeChecker) GetMountRefs(pathname string) ([]string, error) { - return nil, errors.New("not implemented") -} - -func (fftc *fakeFileTypeChecker) GetFSGroup(pathname string) (int64, error) { - return -1, errors.New("not implemented") -} - -func (fftc *fakeFileTypeChecker) GetSELinuxSupport(pathname string) (bool, error) { - return false, errors.New("not implemented") -} - -func (fftc *fakeFileTypeChecker) GetMode(pathname string) (os.FileMode, error) { - return 0, errors.New("not implemented") -} - func setUp() error { err := os.MkdirAll("/tmp/ExistingFolder", os.FileMode(0755)) if err != nil { @@ -473,7 +386,11 @@ func TestOSFileTypeChecker(t *testing.T) { } for i, tc := range testCases { - fakeFTC := &fakeFileTypeChecker{desiredType: tc.desiredType} + fakeFTC := &utilmount.FakeMounter{ + Filesystem: map[string]utilmount.FileType{ + tc.path: utilmount.FileType(tc.desiredType), + }, + } oftc := newFileTypeChecker(tc.path, fakeFTC) path := oftc.GetPath() From 97205a671af9f4b788455de0a546e82fb85dae78 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Thu, 28 Jun 2018 16:47:50 -0400 Subject: [PATCH 2/2] UPSTREAM: 65447: Resolve potential devicePath symlink when MapVolume --- vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount.go | 4 ++++ .../pkg/util/mount/exec_mount_unsupported.go | 4 ++++ vendor/k8s.io/kubernetes/pkg/util/mount/fake.go | 4 ++++ vendor/k8s.io/kubernetes/pkg/util/mount/mount.go | 3 +++ vendor/k8s.io/kubernetes/pkg/util/mount/mount_linux.go | 4 ++++ .../kubernetes/pkg/util/mount/mount_unsupported.go | 4 ++++ .../k8s.io/kubernetes/pkg/util/mount/mount_windows.go | 5 +++++ .../k8s.io/kubernetes/pkg/util/mount/nsenter_mount.go | 4 ++++ .../pkg/util/mount/nsenter_mount_unsupported.go | 4 ++++ .../util/operationexecutor/operation_generator.go | 10 ++++++++++ 10 files changed, 46 insertions(+) diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount.go b/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount.go index fe7dcbd7ef9d..3c6638328f69 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount.go @@ -140,6 +140,10 @@ func (m *execMounter) ExistsPath(pathname string) (bool, error) { return m.wrappedMounter.ExistsPath(pathname) } +func (m *execMounter) EvalHostSymlinks(pathname string) (string, error) { + return m.wrappedMounter.EvalHostSymlinks(pathname) +} + func (m *execMounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) { return m.wrappedMounter.PrepareSafeSubpath(subPath) } diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount_unsupported.go b/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount_unsupported.go index 6854b32b26c9..d5a1fdc58c6a 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount_unsupported.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/exec_mount_unsupported.go @@ -87,6 +87,10 @@ func (mounter *execMounter) ExistsPath(pathname string) (bool, error) { return true, errors.New("not implemented") } +func (m *execMounter) EvalHostSymlinks(pathname string) (string, error) { + return "", errors.New("not implemented") +} + func (mounter *execMounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) { return subPath.Path, nil, nil } diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/fake.go b/vendor/k8s.io/kubernetes/pkg/util/mount/fake.go index 55c99c9fe3d1..a354ca99fd82 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/fake.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/fake.go @@ -212,6 +212,10 @@ func (f *FakeMounter) ExistsPath(pathname string) (bool, error) { return false, nil } +func (f *FakeMounter) EvalHostSymlinks(pathname string) (string, error) { + return pathname, nil +} + func (f *FakeMounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) { return subPath.Path, nil, nil } diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/mount.go b/vendor/k8s.io/kubernetes/pkg/util/mount/mount.go index f5ce194cac63..ea9cbe1c690a 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/mount.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/mount.go @@ -96,6 +96,9 @@ type Interface interface { // Will operate in the host mount namespace if kubelet is running in a container. // Error is returned on any other error than "file not found". ExistsPath(pathname string) (bool, error) + // EvalHostSymlinks returns the path name after evaluating symlinks. + // Will operate in the host mount namespace if kubelet is running in a container. + EvalHostSymlinks(pathname string) (string, error) // CleanSubPaths removes any bind-mounts created by PrepareSafeSubpath in given // pod volume directory. CleanSubPaths(podDir string, volumeName string) error diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/mount_linux.go b/vendor/k8s.io/kubernetes/pkg/util/mount/mount_linux.go index e80dad590adb..70b85eb6276b 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/mount_linux.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/mount_linux.go @@ -454,6 +454,10 @@ func (mounter *Mounter) ExistsPath(pathname string) (bool, error) { return utilfile.FileExists(pathname) } +func (mounter *Mounter) EvalHostSymlinks(pathname string) (string, error) { + return filepath.EvalSymlinks(pathname) +} + // formatAndMount uses unix utils to format and mount the given disk func (mounter *SafeFormatAndMount) formatAndMount(source string, target string, fstype string, options []string) error { readOnly := false diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/mount_unsupported.go b/vendor/k8s.io/kubernetes/pkg/util/mount/mount_unsupported.go index 6143aec18270..261cd8c25b5f 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/mount_unsupported.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/mount_unsupported.go @@ -112,6 +112,10 @@ func (mounter *Mounter) ExistsPath(pathname string) (bool, error) { return true, errors.New("not implemented") } +func (mounter *Mounter) EvalHostSymlinks(pathname string) (string, error) { + return "", unsupportedErr +} + func (mounter *Mounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) { return subPath.Path, nil, unsupportedErr } diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/mount_windows.go b/vendor/k8s.io/kubernetes/pkg/util/mount/mount_windows.go index 5c57a57d0647..c658d70a948e 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/mount_windows.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/mount_windows.go @@ -242,6 +242,11 @@ func (mounter *Mounter) ExistsPath(pathname string) (bool, error) { return utilfile.FileExists(pathname) } +// EvalHostSymlinks returns the path name after evaluating symlinks +func (mounter *Mounter) EvalHostSymlinks(pathname string) (string, error) { + return filepath.EvalSymlinks(pathname) +} + // check whether hostPath is within volume path // this func will lock all intermediate subpath directories, need to close handle outside of this func after container started func lockAndCheckSubPath(volumePath, hostPath string) ([]uintptr, error) { diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/nsenter_mount.go b/vendor/k8s.io/kubernetes/pkg/util/mount/nsenter_mount.go index a122411cec23..bf2dbf630b12 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/nsenter_mount.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/nsenter_mount.go @@ -287,6 +287,10 @@ func (mounter *NsenterMounter) ExistsPath(pathname string) (bool, error) { return utilfile.FileExists(kubeletpath) } +func (mounter *NsenterMounter) EvalHostSymlinks(pathname string) (string, error) { + return mounter.ne.EvalSymlinks(pathname, true) +} + func (mounter *NsenterMounter) CleanSubPaths(podDir string, volumeName string) error { return doCleanSubPaths(mounter, podDir, volumeName) } diff --git a/vendor/k8s.io/kubernetes/pkg/util/mount/nsenter_mount_unsupported.go b/vendor/k8s.io/kubernetes/pkg/util/mount/nsenter_mount_unsupported.go index f417ba9bc15d..87c2e9ec73d7 100644 --- a/vendor/k8s.io/kubernetes/pkg/util/mount/nsenter_mount_unsupported.go +++ b/vendor/k8s.io/kubernetes/pkg/util/mount/nsenter_mount_unsupported.go @@ -89,6 +89,10 @@ func (*NsenterMounter) ExistsPath(pathname string) (bool, error) { return true, errors.New("not implemented") } +func (*NsenterMounter) EvalHostSymlinks(pathname string) (string, error) { + return "", errors.New("not implemented") +} + func (*NsenterMounter) SafeMakeDir(pathname string, base string, perm os.FileMode) error { return nil } diff --git a/vendor/k8s.io/kubernetes/pkg/volume/util/operationexecutor/operation_generator.go b/vendor/k8s.io/kubernetes/pkg/volume/util/operationexecutor/operation_generator.go index 51f321ae9d45..680851637010 100644 --- a/vendor/k8s.io/kubernetes/pkg/volume/util/operationexecutor/operation_generator.go +++ b/vendor/k8s.io/kubernetes/pkg/volume/util/operationexecutor/operation_generator.go @@ -866,6 +866,16 @@ func (og *operationGenerator) GenerateMapVolumeFunc( return volumeToMount.GenerateError("MapVolume failed", fmt.Errorf("Device path of the volume is empty")) } + // When kubelet is containerized, devicePath may be a symlink at a place unavailable to + // kubelet, so evaluate it on the host and expect that it links to a device in /dev, + // which will be available to containerized kubelet. If still it does not exist, + // AttachFileDevice will fail. If kubelet is not containerized, eval it anyway. + mounter := og.GetVolumePluginMgr().Host.GetMounter(blockVolumePlugin.GetPluginName()) + devicePath, err = mounter.EvalHostSymlinks(devicePath) + if err != nil { + return volumeToMount.GenerateError("MapVolume.EvalHostSymlinks failed", err) + } + // Map device to global and pod device map path volumeMapPath, volName := blockVolumeMapper.GetPodDeviceMapPath() mapErr = blockVolumeMapper.MapDevice(devicePath, globalMapPath, volumeMapPath, volName, volumeToMount.Pod.UID)