mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #81204 from codenrhoden/rename-hu-pathexists
Rename HostUtils.ExistsPath to PathExists
This commit is contained in:
commit
76e19a1619
@ -32,7 +32,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
@ -195,7 +195,7 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
|
|||||||
volumePath := hostPath
|
volumePath := hostPath
|
||||||
hostPath = filepath.Join(volumePath, subPath)
|
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)
|
klog.Errorf("Could not determine if subPath %s exists; will not attempt to change its permissions", hostPath)
|
||||||
} else if !subPathExists {
|
} else if !subPathExists {
|
||||||
// Create the sub path now because if it's auto-created later when referenced, it may have an
|
// Create the sub path now because if it's auto-created later when referenced, it may have an
|
||||||
|
@ -247,8 +247,8 @@ func (hu *FakeHostUtil) MakeFile(pathname string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExistsPath checks if pathname exists.
|
// PathExists checks if pathname exists.
|
||||||
func (hu *FakeHostUtil) ExistsPath(pathname string) (bool, error) {
|
func (hu *FakeHostUtil) PathExists(pathname string) (bool, error) {
|
||||||
if _, ok := hu.Filesystem[pathname]; ok {
|
if _, ok := hu.Filesystem[pathname]; ok {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,9 @@ type HostUtils interface {
|
|||||||
MakeFile(pathname string) error
|
MakeFile(pathname string) error
|
||||||
// MakeDir creates a new directory.
|
// MakeDir creates a new directory.
|
||||||
MakeDir(pathname string) error
|
MakeDir(pathname string) error
|
||||||
|
// PathExists tests if the given path already exists
|
||||||
// Error is returned on any other error than "file not found".
|
// 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 returns the path name after evaluating symlinks.
|
||||||
EvalHostSymlinks(pathname string) (string, error)
|
EvalHostSymlinks(pathname string) (string, error)
|
||||||
// GetOwner returns the integer ID for the user and group of the given path
|
// GetOwner returns the integer ID for the user and group of the given path
|
||||||
|
@ -28,8 +28,6 @@ import (
|
|||||||
// called instead of IsLikelyNotMountPoint. IsNotMountPoint is more expensive
|
// called instead of IsLikelyNotMountPoint. IsNotMountPoint is more expensive
|
||||||
// but properly handles bind mounts within the same fs.
|
// but properly handles bind mounts within the same fs.
|
||||||
func CleanupMountPoint(mountPath string, mounter Interface, extensiveMountPointCheck bool) error {
|
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)
|
pathExists, pathErr := PathExists(mountPath)
|
||||||
if !pathExists {
|
if !pathExists {
|
||||||
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", mountPath)
|
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", mountPath)
|
||||||
|
@ -582,7 +582,7 @@ func (hu *hostUtil) MakeFile(pathname string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hu *hostUtil) ExistsPath(pathname string) (bool, error) {
|
func (hu *hostUtil) PathExists(pathname string) (bool, error) {
|
||||||
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)
|
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ func (hu *hostUtil) MakeDir(pathname string) error {
|
|||||||
return errUnsupported
|
return errUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hu *hostUtil) ExistsPath(pathname string) (bool, error) {
|
func (hu *hostUtil) PathExists(pathname string) (bool, error) {
|
||||||
return true, errUnsupported
|
return true, errUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
|||||||
return true, fmt.Errorf("readlink error: %v", err)
|
return true, fmt.Errorf("readlink error: %v", err)
|
||||||
}
|
}
|
||||||
hu := NewHostUtil()
|
hu := NewHostUtil()
|
||||||
exists, err := hu.ExistsPath(target)
|
exists, err := hu.PathExists(target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
@ -393,8 +393,8 @@ func (hu *hostUtil) MakeFile(pathname string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExistsPath checks whether the path exists
|
// PathExists checks whether the path exists
|
||||||
func (hu *hostUtil) ExistsPath(pathname string) (bool, error) {
|
func (hu *hostUtil) PathExists(pathname string) (bool, error) {
|
||||||
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)
|
return utilpath.Exists(utilpath.CheckFollowSymlink, pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/uuid"
|
"k8s.io/apimachinery/pkg/util/uuid"
|
||||||
@ -365,7 +365,7 @@ type fileTypeChecker struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ftc *fileTypeChecker) Exists() bool {
|
func (ftc *fileTypeChecker) Exists() bool {
|
||||||
exists, err := ftc.hu.ExistsPath(ftc.path)
|
exists, err := ftc.hu.PathExists(ftc.path)
|
||||||
return exists && err == nil
|
return exists && err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,9 +316,9 @@ func (hu *hostUtil) MakeFile(pathname string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExistsPath checks if pathname exists.
|
// PathExists checks if pathname exists.
|
||||||
// Error is returned on any other error than "file not found".
|
// 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
|
// Resolve the symlinks but allow the target not to exist. EvalSymlinks
|
||||||
// would return an generic error when the target does not exist.
|
// would return an generic error when the target does not exist.
|
||||||
hostPath, err := hu.ne.EvalSymlinks(pathname, false /* mustExist */)
|
hostPath, err := hu.ne.EvalSymlinks(pathname, false /* mustExist */)
|
||||||
|
@ -170,8 +170,8 @@ func TestNsenterExistsFile(t *testing.T) {
|
|||||||
|
|
||||||
return path, nil
|
return path, nil
|
||||||
},
|
},
|
||||||
expectedOutput: isRoot, // ExistsPath success when running as root
|
expectedOutput: isRoot, // PathExists success when running as root
|
||||||
expectError: !isRoot, // ExistsPath must fail when running as not-root
|
expectError: !isRoot, // PathExists must fail when running as not-root
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative symlink to existing file",
|
name: "relative symlink to existing file",
|
||||||
@ -278,7 +278,7 @@ func TestNsenterExistsFile(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := hu.ExistsPath(path)
|
out, err := hu.PathExists(path)
|
||||||
if err != nil && !test.expectError {
|
if err != nil && !test.expectError {
|
||||||
t.Errorf("Test %q: unexpected error: %s", test.name, err)
|
t.Errorf("Test %q: unexpected error: %s", test.name, err)
|
||||||
}
|
}
|
||||||
|
@ -122,9 +122,9 @@ func (*hostUtil) MakeFile(pathname string) error {
|
|||||||
return nil
|
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
|
// platforms
|
||||||
func (*hostUtil) ExistsPath(pathname string) (bool, error) {
|
func (*hostUtil) PathExists(pathname string) (bool, error) {
|
||||||
return true, errors.New("not implemented")
|
return true, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user