From 14e25b7c04235b2cdc38f5c8d533a8b7a8254fe4 Mon Sep 17 00:00:00 2001 From: Travis Rhoden Date: Thu, 8 Aug 2019 17:34:30 -0600 Subject: [PATCH] Rename HostUtils.ExistsPath to PathExists --- pkg/kubelet/kubelet_pods.go | 4 ++-- pkg/util/mount/fake.go | 4 ++-- pkg/util/mount/mount.go | 3 ++- pkg/util/mount/mount_helper_common.go | 2 -- pkg/util/mount/mount_linux.go | 2 +- pkg/util/mount/mount_unsupported.go | 2 +- pkg/util/mount/mount_windows.go | 6 +++--- pkg/volume/hostpath/host_path.go | 4 ++-- pkg/volume/util/nsenter/nsenter_mount.go | 4 ++-- pkg/volume/util/nsenter/nsenter_mount_test.go | 6 +++--- pkg/volume/util/nsenter/nsenter_mount_unsupported.go | 4 ++-- 11 files changed, 20 insertions(+), 21 deletions(-) diff --git a/pkg/kubelet/kubelet_pods.go b/pkg/kubelet/kubelet_pods.go index e12f1e3eb76..2741a8e2144 100644 --- a/pkg/kubelet/kubelet_pods.go +++ b/pkg/kubelet/kubelet_pods.go @@ -32,7 +32,7 @@ import ( "strings" "sync" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -195,7 +195,7 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h volumePath := hostPath hostPath = filepath.Join(volumePath, subPath) - if subPathExists, err := hu.ExistsPath(hostPath); err != nil { + if subPathExists, err := hu.PathExists(hostPath); err != nil { klog.Errorf("Could not determine if subPath %s exists; will not attempt to change its permissions", hostPath) } else if !subPathExists { // Create the sub path now because if it's auto-created later when referenced, it may have an diff --git a/pkg/util/mount/fake.go b/pkg/util/mount/fake.go index 6e1fd4ec875..c8680e59582 100644 --- a/pkg/util/mount/fake.go +++ b/pkg/util/mount/fake.go @@ -247,8 +247,8 @@ func (hu *FakeHostUtil) MakeFile(pathname string) error { return nil } -// ExistsPath checks if pathname exists. -func (hu *FakeHostUtil) ExistsPath(pathname string) (bool, error) { +// PathExists checks if pathname exists. +func (hu *FakeHostUtil) PathExists(pathname string) (bool, error) { if _, ok := hu.Filesystem[pathname]; ok { return true, nil } diff --git a/pkg/util/mount/mount.go b/pkg/util/mount/mount.go index f7dfac49cf8..cbbbaaf8b90 100644 --- a/pkg/util/mount/mount.go +++ b/pkg/util/mount/mount.go @@ -91,8 +91,9 @@ type HostUtils interface { MakeFile(pathname string) error // MakeDir creates a new directory. MakeDir(pathname string) error + // PathExists tests if the given path already exists // Error is returned on any other error than "file not found". - ExistsPath(pathname string) (bool, error) + PathExists(pathname string) (bool, error) // EvalHostSymlinks returns the path name after evaluating symlinks. EvalHostSymlinks(pathname string) (string, error) // GetFSGroup returns FSGroup of the path. diff --git a/pkg/util/mount/mount_helper_common.go b/pkg/util/mount/mount_helper_common.go index 22f7c5fbc2c..81f91a8be8d 100644 --- a/pkg/util/mount/mount_helper_common.go +++ b/pkg/util/mount/mount_helper_common.go @@ -28,8 +28,6 @@ import ( // called instead of IsLikelyNotMountPoint. IsNotMountPoint is more expensive // but properly handles bind mounts within the same fs. func CleanupMountPoint(mountPath string, mounter Interface, extensiveMountPointCheck bool) error { - // mounter.ExistsPath cannot be used because for containerized kubelet, we need to check - // the path in the kubelet container, not on the host. pathExists, pathErr := PathExists(mountPath) if !pathExists { klog.Warningf("Warning: Unmount skipped because path does not exist: %v", mountPath) diff --git a/pkg/util/mount/mount_linux.go b/pkg/util/mount/mount_linux.go index 19cd42da89b..5d1d93f2e89 100644 --- a/pkg/util/mount/mount_linux.go +++ b/pkg/util/mount/mount_linux.go @@ -582,7 +582,7 @@ func (hu *hostUtil) MakeFile(pathname string) error { return nil } -func (hu *hostUtil) ExistsPath(pathname string) (bool, error) { +func (hu *hostUtil) PathExists(pathname string) (bool, error) { return utilpath.Exists(utilpath.CheckFollowSymlink, pathname) } diff --git a/pkg/util/mount/mount_unsupported.go b/pkg/util/mount/mount_unsupported.go index 1ae29b3bfa1..031f2acab7f 100644 --- a/pkg/util/mount/mount_unsupported.go +++ b/pkg/util/mount/mount_unsupported.go @@ -121,7 +121,7 @@ func (hu *hostUtil) MakeDir(pathname string) error { return errUnsupported } -func (hu *hostUtil) ExistsPath(pathname string) (bool, error) { +func (hu *hostUtil) PathExists(pathname string) (bool, error) { return true, errUnsupported } diff --git a/pkg/util/mount/mount_windows.go b/pkg/util/mount/mount_windows.go index 30f86c0cd53..db3ba10eb6a 100644 --- a/pkg/util/mount/mount_windows.go +++ b/pkg/util/mount/mount_windows.go @@ -186,7 +186,7 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) { return true, fmt.Errorf("readlink error: %v", err) } hu := NewHostUtil() - exists, err := hu.ExistsPath(target) + exists, err := hu.PathExists(target) if err != nil { return true, err } @@ -393,8 +393,8 @@ func (hu *hostUtil) MakeFile(pathname string) error { return nil } -// ExistsPath checks whether the path exists -func (hu *hostUtil) ExistsPath(pathname string) (bool, error) { +// PathExists checks whether the path exists +func (hu *hostUtil) PathExists(pathname string) (bool, error) { return utilpath.Exists(utilpath.CheckFollowSymlink, pathname) } diff --git a/pkg/volume/hostpath/host_path.go b/pkg/volume/hostpath/host_path.go index 2868b90b704..86af8e5d1d8 100644 --- a/pkg/volume/hostpath/host_path.go +++ b/pkg/volume/hostpath/host_path.go @@ -21,7 +21,7 @@ import ( "os" "regexp" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/uuid" @@ -364,7 +364,7 @@ type fileTypeChecker struct { } func (ftc *fileTypeChecker) Exists() bool { - exists, err := ftc.hu.ExistsPath(ftc.path) + exists, err := ftc.hu.PathExists(ftc.path) return exists && err == nil } diff --git a/pkg/volume/util/nsenter/nsenter_mount.go b/pkg/volume/util/nsenter/nsenter_mount.go index 001be408e7d..434152dd333 100644 --- a/pkg/volume/util/nsenter/nsenter_mount.go +++ b/pkg/volume/util/nsenter/nsenter_mount.go @@ -316,9 +316,9 @@ func (hu *hostUtil) MakeFile(pathname string) error { return nil } -// ExistsPath checks if pathname exists. +// PathExists checks if pathname exists. // Error is returned on any other error than "file not found". -func (hu *hostUtil) ExistsPath(pathname string) (bool, error) { +func (hu *hostUtil) PathExists(pathname string) (bool, error) { // Resolve the symlinks but allow the target not to exist. EvalSymlinks // would return an generic error when the target does not exist. hostPath, err := hu.ne.EvalSymlinks(pathname, false /* mustExist */) diff --git a/pkg/volume/util/nsenter/nsenter_mount_test.go b/pkg/volume/util/nsenter/nsenter_mount_test.go index 634f417f8d6..2df7c6d1cb2 100644 --- a/pkg/volume/util/nsenter/nsenter_mount_test.go +++ b/pkg/volume/util/nsenter/nsenter_mount_test.go @@ -170,8 +170,8 @@ func TestNsenterExistsFile(t *testing.T) { return path, nil }, - expectedOutput: isRoot, // ExistsPath success when running as root - expectError: !isRoot, // ExistsPath must fail when running as not-root + expectedOutput: isRoot, // PathExists success when running as root + expectError: !isRoot, // PathExists must fail when running as not-root }, { name: "relative symlink to existing file", @@ -278,7 +278,7 @@ func TestNsenterExistsFile(t *testing.T) { continue } - out, err := hu.ExistsPath(path) + out, err := hu.PathExists(path) if err != nil && !test.expectError { t.Errorf("Test %q: unexpected error: %s", test.name, err) } diff --git a/pkg/volume/util/nsenter/nsenter_mount_unsupported.go b/pkg/volume/util/nsenter/nsenter_mount_unsupported.go index e76a0667672..5f487346fbc 100644 --- a/pkg/volume/util/nsenter/nsenter_mount_unsupported.go +++ b/pkg/volume/util/nsenter/nsenter_mount_unsupported.go @@ -122,9 +122,9 @@ func (*hostUtil) MakeFile(pathname string) error { return nil } -// ExistsPath checks if pathname exists. Always returns an error on unsupported +// PathExists checks if pathname exists. Always returns an error on unsupported // platforms -func (*hostUtil) ExistsPath(pathname string) (bool, error) { +func (*hostUtil) PathExists(pathname string) (bool, error) { return true, errors.New("not implemented") }