Merge pull request #81204 from codenrhoden/rename-hu-pathexists

Rename HostUtils.ExistsPath to PathExists
This commit is contained in:
Kubernetes Prow Robot 2019-08-12 20:12:12 -07:00 committed by GitHub
commit 76e19a1619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 20 additions and 21 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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)
// GetOwner returns the integer ID for the user and group of the given path

View File

@ -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)

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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"
@ -365,7 +365,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
}

View File

@ -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 */)

View File

@ -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)
}

View File

@ -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")
}