mirror of https://github.com/k3s-io/k3s
Cleanup PathExists callers
parent
d94cd822b7
commit
8092904e3c
|
@ -25,14 +25,14 @@ import (
|
|||
cadvisorapiv1 "github.com/google/cadvisor/info/v1"
|
||||
"k8s.io/klog"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
"k8s.io/kubernetes/pkg/kubelet/config"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
utilfile "k8s.io/kubernetes/pkg/util/file"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
utilnode "k8s.io/kubernetes/pkg/util/node"
|
||||
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
||||
)
|
||||
|
||||
// getRootDir returns the full path to the directory under which kubelet can
|
||||
|
@ -278,7 +278,7 @@ func (kl *Kubelet) getPodVolumePathListFromDisk(podUID types.UID) ([]string, err
|
|||
volumes := []string{}
|
||||
podVolDir := kl.getPodVolumesDir(podUID)
|
||||
|
||||
if pathExists, pathErr := volumeutil.PathExists(podVolDir); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(podVolDir); pathErr != nil {
|
||||
return volumes, fmt.Errorf("Error checking if path %q exists: %v", podVolDir, pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Path %q does not exist", podVolDir)
|
||||
|
@ -327,7 +327,7 @@ func (kl *Kubelet) getMountedVolumePathListFromDisk(podUID types.UID) ([]string,
|
|||
func (kl *Kubelet) podVolumeSubpathsDirExists(podUID types.UID) (bool, error) {
|
||||
podVolDir := kl.getPodVolumeSubpathsDir(podUID)
|
||||
|
||||
if pathExists, pathErr := volumeutil.PathExists(podVolDir); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(podVolDir); pathErr != nil {
|
||||
return true, fmt.Errorf("Error checking if path %q exists: %v", podVolDir, pathErr)
|
||||
} else if !pathExists {
|
||||
return false, nil
|
||||
|
|
|
@ -31,6 +31,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
cloudprovider "k8s.io/cloud-provider"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider/providers/aws"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
||||
)
|
||||
|
@ -187,7 +188,7 @@ func populateVolumeOptions(pluginName, pvcName string, capacityGB resource.Quant
|
|||
// Returns the first path that exists, or empty string if none exist.
|
||||
func verifyDevicePath(devicePaths []string) (string, error) {
|
||||
for _, path := range devicePaths {
|
||||
if pathExists, err := volumeutil.PathExists(path); err != nil {
|
||||
if pathExists, err := mount.PathExists(path); err != nil {
|
||||
return "", fmt.Errorf("Error checking if path exists: %v", err)
|
||||
} else if pathExists {
|
||||
return path, nil
|
||||
|
@ -201,7 +202,7 @@ func verifyDevicePath(devicePaths []string) (string, error) {
|
|||
func verifyAllPathsRemoved(devicePaths []string) (bool, error) {
|
||||
allPathsRemoved := true
|
||||
for _, path := range devicePaths {
|
||||
exists, err := volumeutil.PathExists(path)
|
||||
exists, err := mount.PathExists(path)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Error checking if path exists: %v", err)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
"k8s.io/kubernetes/pkg/volume/util"
|
||||
)
|
||||
|
@ -172,7 +173,7 @@ func (u *azureDiskUnmounter) TearDown() error {
|
|||
}
|
||||
|
||||
func (u *azureDiskUnmounter) TearDownAt(dir string) error {
|
||||
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(dir); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
|
||||
|
|
|
@ -237,7 +237,7 @@ func (attacher *cinderDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath
|
|||
// Using the Cinder volume ID, find the real device path (See Issue #33128)
|
||||
devicePath = attacher.cinderProvider.GetDevicePath(volumeID)
|
||||
}
|
||||
exists, err := volumeutil.PathExists(devicePath)
|
||||
exists, err := mount.PathExists(devicePath)
|
||||
if exists && err == nil {
|
||||
klog.Infof("Successfully found attached Cinder disk %q at %v.", volumeID, devicePath)
|
||||
return devicePath, nil
|
||||
|
|
|
@ -429,7 +429,7 @@ func (c *cinderVolumeUnmounter) TearDown() error {
|
|||
// Unmounts the bind mount, and detaches the disk only if the PD
|
||||
// resource was the last reference to that disk on the kubelet.
|
||||
func (c *cinderVolumeUnmounter) TearDownAt(dir string) error {
|
||||
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(dir); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
|
||||
|
|
|
@ -367,7 +367,7 @@ func (ed *emptyDir) TearDown() error {
|
|||
|
||||
// TearDownAt simply discards everything in the directory.
|
||||
func (ed *emptyDir) TearDownAt(dir string) error {
|
||||
if pathExists, pathErr := volumeutil.PathExists(dir); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(dir); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
||||
)
|
||||
|
@ -375,7 +376,7 @@ func (util *fcUtil) DetachBlockFCDisk(c fcDiskUnmapper, mapPath, devicePath stri
|
|||
}
|
||||
|
||||
func checkPathExists(path string) (bool, error) {
|
||||
if pathExists, pathErr := volumeutil.PathExists(path); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(path); pathErr != nil {
|
||||
return pathExists, fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Warning: Unmap skipped because path does not exist: %v", path)
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
"k8s.io/kubernetes/pkg/volume/util"
|
||||
)
|
||||
|
@ -51,7 +52,7 @@ func (d *flexVolumeDetacher) Detach(volumeName string, hostName types.NodeName)
|
|||
// UnmountDevice is part of the volume.Detacher interface.
|
||||
func (d *flexVolumeDetacher) UnmountDevice(deviceMountPath string) error {
|
||||
|
||||
pathExists, pathErr := util.PathExists(deviceMountPath)
|
||||
pathExists, pathErr := mount.PathExists(deviceMountPath)
|
||||
if !pathExists {
|
||||
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", deviceMountPath)
|
||||
return nil
|
||||
|
@ -85,7 +86,7 @@ func (d *flexVolumeDetacher) UnmountDevice(deviceMountPath string) error {
|
|||
}
|
||||
|
||||
// Flexvolume driver may remove the directory. Ignore if it does.
|
||||
if pathExists, pathErr := util.PathExists(deviceMountPath); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(deviceMountPath); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
return nil
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"os"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
"k8s.io/kubernetes/pkg/volume/util"
|
||||
"k8s.io/utils/exec"
|
||||
|
@ -43,7 +44,7 @@ func (f *flexVolumeUnmounter) TearDown() error {
|
|||
|
||||
func (f *flexVolumeUnmounter) TearDownAt(dir string) error {
|
||||
|
||||
pathExists, pathErr := util.PathExists(dir)
|
||||
pathExists, pathErr := mount.PathExists(dir)
|
||||
if !pathExists {
|
||||
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
|
||||
return nil
|
||||
|
@ -64,7 +65,7 @@ func (f *flexVolumeUnmounter) TearDownAt(dir string) error {
|
|||
}
|
||||
|
||||
// Flexvolume driver may remove the directory. Ignore if it does.
|
||||
if pathExists, pathErr := util.PathExists(dir); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(dir); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
return nil
|
||||
|
|
|
@ -33,6 +33,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/features"
|
||||
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
|
||||
utilfile "k8s.io/kubernetes/pkg/util/file"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
||||
"k8s.io/utils/exec"
|
||||
|
@ -207,7 +208,7 @@ func verifyDevicePath(devicePaths []string, sdBeforeSet sets.String, diskName st
|
|||
}
|
||||
|
||||
for _, path := range devicePaths {
|
||||
if pathExists, err := volumeutil.PathExists(path); err != nil {
|
||||
if pathExists, err := mount.PathExists(path); err != nil {
|
||||
return "", fmt.Errorf("Error checking if path exists: %v", err)
|
||||
} else if pathExists {
|
||||
// validate that the path actually resolves to the correct disk
|
||||
|
|
|
@ -590,7 +590,7 @@ func deleteDevices(c iscsiDiskUnmounter) error {
|
|||
|
||||
// DetachDisk unmounts and detaches a volume from node
|
||||
func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, mntPath string) error {
|
||||
if pathExists, pathErr := volumeutil.PathExists(mntPath); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(mntPath); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", mntPath)
|
||||
|
@ -667,7 +667,7 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, mntPath string) error {
|
|||
|
||||
// DetachBlockISCSIDisk removes loopback device for a volume and detaches a volume from node
|
||||
func (util *ISCSIUtil) DetachBlockISCSIDisk(c iscsiDiskUnmapper, mapPath string) error {
|
||||
if pathExists, pathErr := volumeutil.PathExists(mapPath); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(mapPath); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Warning: Unmap skipped because path does not exist: %v", mapPath)
|
||||
|
|
|
@ -293,7 +293,7 @@ func (detacher *photonPersistentDiskDetacher) WaitForDetach(devicePath string, t
|
|||
select {
|
||||
case <-ticker.C:
|
||||
klog.V(4).Infof("Checking device %q is detached.", devicePath)
|
||||
if pathExists, err := volumeutil.PathExists(devicePath); err != nil {
|
||||
if pathExists, err := mount.PathExists(devicePath); err != nil {
|
||||
return fmt.Errorf("Error checking if device path exists: %v", err)
|
||||
} else if !pathExists {
|
||||
return nil
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
cloudprovider "k8s.io/cloud-provider"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider/providers/photon"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
||||
)
|
||||
|
@ -69,7 +70,7 @@ func scsiHostScan() {
|
|||
}
|
||||
|
||||
func verifyDevicePath(path string) (string, error) {
|
||||
if pathExists, err := volumeutil.PathExists(path); err != nil {
|
||||
if pathExists, err := mount.PathExists(path); err != nil {
|
||||
return "", fmt.Errorf("Error checking if path exists: %v", err)
|
||||
} else if pathExists {
|
||||
return path, nil
|
||||
|
|
|
@ -197,7 +197,7 @@ var _ volume.DeviceUnmounter = &rbdDetacher{}
|
|||
// - Remove the deviceMountPath at last.
|
||||
// This method is idempotent, callers are responsible for retrying on failure.
|
||||
func (detacher *rbdDetacher) UnmountDevice(deviceMountPath string) error {
|
||||
if pathExists, pathErr := volutil.PathExists(deviceMountPath); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(deviceMountPath); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", deviceMountPath)
|
||||
|
|
|
@ -848,7 +848,7 @@ func (c *rbdUnmounter) TearDown() error {
|
|||
|
||||
func (c *rbdUnmounter) TearDownAt(dir string) error {
|
||||
klog.V(4).Infof("rbd: attempting to teardown at %s", dir)
|
||||
if pathExists, pathErr := volutil.PathExists(dir); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(dir); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
|
||||
|
|
|
@ -363,7 +363,7 @@ func (util *RBDUtil) AttachDisk(b rbdMounter) (string, error) {
|
|||
var output []byte
|
||||
|
||||
globalPDPath := util.MakeGlobalPDName(*b.rbd)
|
||||
if pathExists, pathErr := volutil.PathExists(globalPDPath); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(globalPDPath); pathErr != nil {
|
||||
return "", fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
if err := os.MkdirAll(globalPDPath, 0750); err != nil {
|
||||
|
@ -505,7 +505,7 @@ func (util *RBDUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, devic
|
|||
// DetachBlockDisk detaches the disk from the node.
|
||||
func (util *RBDUtil) DetachBlockDisk(disk rbdDiskUnmapper, mapPath string) error {
|
||||
|
||||
if pathExists, pathErr := volutil.PathExists(mapPath); pathErr != nil {
|
||||
if pathExists, pathErr := mount.PathExists(mapPath); pathErr != nil {
|
||||
return fmt.Errorf("Error checking if path exists: %v", pathErr)
|
||||
} else if !pathExists {
|
||||
klog.Warningf("Warning: Unmap skipped because path does not exist: %v", mapPath)
|
||||
|
|
|
@ -125,12 +125,6 @@ func SetReady(dir string) {
|
|||
file.Close()
|
||||
}
|
||||
|
||||
// PathExists returns true if the specified path exists.
|
||||
// TODO: Change callers to call mount pkg directly
|
||||
func PathExists(path string) (bool, error) {
|
||||
return mount.PathExists(path)
|
||||
}
|
||||
|
||||
// IsCorruptedMnt return true if err is about corrupted mount point
|
||||
// TODO: Change callers to call mount pkg directly
|
||||
func IsCorruptedMnt(err error) bool {
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"k8s.io/klog"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere"
|
||||
"k8s.io/kubernetes/pkg/cloudprovider/providers/vsphere/vclib"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
||||
)
|
||||
|
@ -73,7 +74,7 @@ type VolumeSpec struct {
|
|||
}
|
||||
|
||||
func verifyDevicePath(path string) (string, error) {
|
||||
if pathExists, err := volumeutil.PathExists(path); err != nil {
|
||||
if pathExists, err := mount.PathExists(path); err != nil {
|
||||
return "", fmt.Errorf("Error checking if path exists: %v", err)
|
||||
} else if pathExists {
|
||||
return path, nil
|
||||
|
|
Loading…
Reference in New Issue