From d94cd822b73e444c53b10c5e5c84c56e3cfb8640 Mon Sep 17 00:00:00 2001 From: danielqsj Date: Mon, 7 Jan 2019 13:24:59 +0800 Subject: [PATCH 1/3] Cleanup UnmountPath/UnmountMountPoint callers --- pkg/volume/awsebs/attacher.go | 2 +- pkg/volume/awsebs/aws_ebs.go | 2 +- pkg/volume/azure_dd/attacher.go | 2 +- pkg/volume/azure_file/azure_file.go | 2 +- pkg/volume/cephfs/cephfs.go | 4 ++-- pkg/volume/cinder/attacher.go | 2 +- pkg/volume/fc/attacher.go | 2 +- pkg/volume/fc/fc.go | 2 +- pkg/volume/flexvolume/detacher-defaults.go | 4 ++-- pkg/volume/flexvolume/unmounter-defaults.go | 4 ++-- pkg/volume/flocker/flocker.go | 3 +-- pkg/volume/gcepd/attacher.go | 3 ++- pkg/volume/gcepd/gce_pd.go | 2 +- pkg/volume/glusterfs/glusterfs.go | 4 ++-- pkg/volume/iscsi/iscsi.go | 2 +- pkg/volume/local/local.go | 4 ++-- pkg/volume/nfs/nfs.go | 2 +- pkg/volume/photon_pd/attacher.go | 2 +- pkg/volume/photon_pd/photon_pd.go | 2 +- pkg/volume/scaleio/sio_volume.go | 2 +- pkg/volume/storageos/storageos.go | 2 +- pkg/volume/util/util.go | 17 ----------------- pkg/volume/vsphere_volume/attacher.go | 2 +- pkg/volume/vsphere_volume/vsphere_volume.go | 2 +- 24 files changed, 29 insertions(+), 46 deletions(-) diff --git a/pkg/volume/awsebs/attacher.go b/pkg/volume/awsebs/attacher.go index a4a320633c2..1f5eeebc563 100644 --- a/pkg/volume/awsebs/attacher.go +++ b/pkg/volume/awsebs/attacher.go @@ -274,7 +274,7 @@ func (detacher *awsElasticBlockStoreDetacher) Detach(volumeName string, nodeName } func (detacher *awsElasticBlockStoreDetacher) UnmountDevice(deviceMountPath string) error { - return volumeutil.UnmountPath(deviceMountPath, detacher.mounter) + return mount.CleanupMountPoint(deviceMountPath, detacher.mounter, false) } func setNodeDisk( diff --git a/pkg/volume/awsebs/aws_ebs.go b/pkg/volume/awsebs/aws_ebs.go index ac934eccafe..3aa792d3c4a 100644 --- a/pkg/volume/awsebs/aws_ebs.go +++ b/pkg/volume/awsebs/aws_ebs.go @@ -485,7 +485,7 @@ func (c *awsElasticBlockStoreUnmounter) TearDown() error { // Unmounts the bind mount func (c *awsElasticBlockStoreUnmounter) TearDownAt(dir string) error { - return util.UnmountPath(dir, c.mounter) + return mount.CleanupMountPoint(dir, c.mounter, false) } type awsElasticBlockStoreDeleter struct { diff --git a/pkg/volume/azure_dd/attacher.go b/pkg/volume/azure_dd/attacher.go index 5787518aa52..0a99b4a91c6 100644 --- a/pkg/volume/azure_dd/attacher.go +++ b/pkg/volume/azure_dd/attacher.go @@ -309,7 +309,7 @@ func (d *azureDiskDetacher) Detach(diskURI string, nodeName types.NodeName) erro // UnmountDevice unmounts the volume on the node func (detacher *azureDiskDetacher) UnmountDevice(deviceMountPath string) error { - err := util.UnmountPath(deviceMountPath, detacher.plugin.host.GetMounter(detacher.plugin.GetPluginName())) + err := mount.CleanupMountPoint(deviceMountPath, detacher.plugin.host.GetMounter(detacher.plugin.GetPluginName()), false) if err == nil { klog.V(2).Infof("azureDisk - Device %s was unmounted", deviceMountPath) } else { diff --git a/pkg/volume/azure_file/azure_file.go b/pkg/volume/azure_file/azure_file.go index e0234ce780b..481b22f08f8 100644 --- a/pkg/volume/azure_file/azure_file.go +++ b/pkg/volume/azure_file/azure_file.go @@ -321,7 +321,7 @@ func (c *azureFileUnmounter) TearDown() error { } func (c *azureFileUnmounter) TearDownAt(dir string) error { - return volutil.UnmountPath(dir, c.mounter) + return mount.CleanupMountPoint(dir, c.mounter, false) } func getVolumeSource(spec *volume.Spec) (string, bool, error) { diff --git a/pkg/volume/cephfs/cephfs.go b/pkg/volume/cephfs/cephfs.go index 748fe11a475..2f720d86f81 100644 --- a/pkg/volume/cephfs/cephfs.go +++ b/pkg/volume/cephfs/cephfs.go @@ -260,7 +260,7 @@ func (cephfsVolume *cephfsMounter) SetUpAt(dir string, fsGroup *int64) error { err = cephfsVolume.execMount(dir) if err != nil { // cleanup upon failure. - util.UnmountPath(dir, cephfsVolume.mounter) + mount.CleanupMountPoint(dir, cephfsVolume.mounter, false) return err } return nil @@ -279,7 +279,7 @@ func (cephfsVolume *cephfsUnmounter) TearDown() error { // TearDownAt unmounts the bind mount func (cephfsVolume *cephfsUnmounter) TearDownAt(dir string) error { - return util.UnmountPath(dir, cephfsVolume.mounter) + return mount.CleanupMountPoint(dir, cephfsVolume.mounter, false) } // GetPath creates global mount path diff --git a/pkg/volume/cinder/attacher.go b/pkg/volume/cinder/attacher.go index 0db22a27386..16fbac3e433 100644 --- a/pkg/volume/cinder/attacher.go +++ b/pkg/volume/cinder/attacher.go @@ -403,7 +403,7 @@ func (detacher *cinderDiskDetacher) Detach(volumeName string, nodeName types.Nod } func (detacher *cinderDiskDetacher) UnmountDevice(deviceMountPath string) error { - return volumeutil.UnmountPath(deviceMountPath, detacher.mounter) + return mount.CleanupMountPoint(deviceMountPath, detacher.mounter, false) } func (attacher *cinderDiskAttacher) nodeInstanceID(nodeName types.NodeName) (string, error) { diff --git a/pkg/volume/fc/attacher.go b/pkg/volume/fc/attacher.go index 748c14f38e1..052567beb11 100644 --- a/pkg/volume/fc/attacher.go +++ b/pkg/volume/fc/attacher.go @@ -162,7 +162,7 @@ func (detacher *fcDetacher) UnmountDevice(deviceMountPath string) error { return err } // Unmount for deviceMountPath(=globalPDPath) - err = volumeutil.UnmountPath(deviceMountPath, detacher.mounter) + err = mount.CleanupMountPoint(deviceMountPath, detacher.mounter, false) if err != nil { return fmt.Errorf("fc: failed to unmount: %s\nError: %v", deviceMountPath, err) } diff --git a/pkg/volume/fc/fc.go b/pkg/volume/fc/fc.go index af257011077..4905c15d807 100644 --- a/pkg/volume/fc/fc.go +++ b/pkg/volume/fc/fc.go @@ -427,7 +427,7 @@ func (c *fcDiskUnmounter) TearDown() error { } func (c *fcDiskUnmounter) TearDownAt(dir string) error { - return util.UnmountPath(dir, c.mounter) + return mount.CleanupMountPoint(dir, c.mounter, false) } // Block Volumes Support diff --git a/pkg/volume/flexvolume/detacher-defaults.go b/pkg/volume/flexvolume/detacher-defaults.go index f0f43262394..134f26da059 100644 --- a/pkg/volume/flexvolume/detacher-defaults.go +++ b/pkg/volume/flexvolume/detacher-defaults.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/klog" - "k8s.io/kubernetes/pkg/volume/util" + "k8s.io/kubernetes/pkg/util/mount" ) type detacherDefaults flexVolumeDetacher @@ -41,5 +41,5 @@ func (d *detacherDefaults) WaitForDetach(devicePath string, timeout time.Duratio // UnmountDevice is part of the volume.Detacher interface. func (d *detacherDefaults) UnmountDevice(deviceMountPath string) error { klog.Warning(logPrefix(d.plugin.flexVolumePlugin), "using default UnmountDevice for device mount path ", deviceMountPath) - return util.UnmountPath(deviceMountPath, d.plugin.host.GetMounter(d.plugin.GetPluginName())) + return mount.CleanupMountPoint(deviceMountPath, d.plugin.host.GetMounter(d.plugin.GetPluginName()), false) } diff --git a/pkg/volume/flexvolume/unmounter-defaults.go b/pkg/volume/flexvolume/unmounter-defaults.go index 919a6be890e..e3f05f0ec87 100644 --- a/pkg/volume/flexvolume/unmounter-defaults.go +++ b/pkg/volume/flexvolume/unmounter-defaults.go @@ -18,12 +18,12 @@ package flexvolume import ( "k8s.io/klog" - "k8s.io/kubernetes/pkg/volume/util" + "k8s.io/kubernetes/pkg/util/mount" ) type unmounterDefaults flexVolumeUnmounter func (f *unmounterDefaults) TearDownAt(dir string) error { klog.Warning(logPrefix(f.plugin), "using default TearDownAt for ", dir) - return util.UnmountPath(dir, f.mounter) + return mount.CleanupMountPoint(dir, f.mounter, false) } diff --git a/pkg/volume/flocker/flocker.go b/pkg/volume/flocker/flocker.go index 8651ba49083..b6a8c09077c 100644 --- a/pkg/volume/flocker/flocker.go +++ b/pkg/volume/flocker/flocker.go @@ -31,7 +31,6 @@ import ( "k8s.io/kubernetes/pkg/volume" flockerapi "github.com/clusterhq/flocker-go" - "k8s.io/kubernetes/pkg/volume/util" ) // ProbeVolumePlugins is the primary entrypoint for volume plugins. @@ -430,7 +429,7 @@ func (c *flockerVolumeUnmounter) TearDown() error { // TearDownAt unmounts the bind mount func (c *flockerVolumeUnmounter) TearDownAt(dir string) error { - return util.UnmountPath(dir, c.mounter) + return mount.CleanupMountPoint(dir, c.mounter, false) } func (p *flockerPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, error) { diff --git a/pkg/volume/gcepd/attacher.go b/pkg/volume/gcepd/attacher.go index 5567e29f28f..4a998579c05 100644 --- a/pkg/volume/gcepd/attacher.go +++ b/pkg/volume/gcepd/attacher.go @@ -29,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog" "k8s.io/kubernetes/pkg/cloudprovider/providers/gce" + "k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/volume" volumeutil "k8s.io/kubernetes/pkg/volume/util" ) @@ -285,5 +286,5 @@ func (detacher *gcePersistentDiskDetacher) Detach(volumeName string, nodeName ty } func (detacher *gcePersistentDiskDetacher) UnmountDevice(deviceMountPath string) error { - return volumeutil.UnmountPath(deviceMountPath, detacher.host.GetMounter(gcePersistentDiskPluginName)) + return mount.CleanupMountPoint(deviceMountPath, detacher.host.GetMounter(gcePersistentDiskPluginName), false) } diff --git a/pkg/volume/gcepd/gce_pd.go b/pkg/volume/gcepd/gce_pd.go index 74cf74ce627..b02864633ca 100644 --- a/pkg/volume/gcepd/gce_pd.go +++ b/pkg/volume/gcepd/gce_pd.go @@ -454,7 +454,7 @@ func (c *gcePersistentDiskUnmounter) TearDown() error { // TearDownAt unmounts the bind mount func (c *gcePersistentDiskUnmounter) TearDownAt(dir string) error { - return util.UnmountPath(dir, c.mounter) + return mount.CleanupMountPoint(dir, c.mounter, false) } type gcePersistentDiskDeleter struct { diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go index 408898c114e..171795b8926 100644 --- a/pkg/volume/glusterfs/glusterfs.go +++ b/pkg/volume/glusterfs/glusterfs.go @@ -291,7 +291,7 @@ func (b *glusterfsMounter) SetUpAt(dir string, fsGroup *int64) error { } // Cleanup upon failure. - volutil.UnmountPath(dir, b.mounter) + mount.CleanupMountPoint(dir, b.mounter, false) return err } @@ -311,7 +311,7 @@ func (c *glusterfsUnmounter) TearDown() error { } func (c *glusterfsUnmounter) TearDownAt(dir string) error { - return volutil.UnmountPath(dir, c.mounter) + return mount.CleanupMountPoint(dir, c.mounter, false) } func (b *glusterfsMounter) setUpAtInternal(dir string) error { diff --git a/pkg/volume/iscsi/iscsi.go b/pkg/volume/iscsi/iscsi.go index 54ad75febfe..369774a0aa8 100644 --- a/pkg/volume/iscsi/iscsi.go +++ b/pkg/volume/iscsi/iscsi.go @@ -355,7 +355,7 @@ func (c *iscsiDiskUnmounter) TearDown() error { } func (c *iscsiDiskUnmounter) TearDownAt(dir string) error { - return ioutil.UnmountPath(dir, c.mounter) + return mount.CleanupMountPoint(dir, c.mounter, false) } // Block Volumes Support diff --git a/pkg/volume/local/local.go b/pkg/volume/local/local.go index 45249313424..5314eaa637b 100644 --- a/pkg/volume/local/local.go +++ b/pkg/volume/local/local.go @@ -367,7 +367,7 @@ func (dm *deviceMounter) UnmountDevice(deviceMountPath string) error { // has base mount path: /var/lib/kubelet/plugins/kubernetes.io/local-volume/mounts basemountPath := dm.plugin.generateBlockDeviceBaseGlobalPath() if mount.PathWithinBase(deviceMountPath, basemountPath) { - return util.UnmountPath(deviceMountPath, dm.mounter) + return mount.CleanupMountPoint(deviceMountPath, dm.mounter, false) } return nil @@ -542,7 +542,7 @@ func (u *localVolumeUnmounter) TearDown() error { // TearDownAt unmounts the bind mount func (u *localVolumeUnmounter) TearDownAt(dir string) error { klog.V(4).Infof("Unmounting volume %q at path %q\n", u.volName, dir) - return util.UnmountMountPoint(dir, u.mounter, true) /* extensiveMountPointCheck = true */ + return mount.CleanupMountPoint(dir, u.mounter, true) /* extensiveMountPointCheck = true */ } // localVolumeMapper implements the BlockVolumeMapper interface for local volumes. diff --git a/pkg/volume/nfs/nfs.go b/pkg/volume/nfs/nfs.go index 92384b3db01..fbac686ea79 100644 --- a/pkg/volume/nfs/nfs.go +++ b/pkg/volume/nfs/nfs.go @@ -294,7 +294,7 @@ func (c *nfsUnmounter) TearDownAt(dir string) error { // Use extensiveMountPointCheck to consult /proc/mounts. We can't use faster // IsLikelyNotMountPoint (lstat()), since there may be root_squash on the // NFS server and kubelet may not be able to do lstat/stat() there. - return util.UnmountMountPoint(dir, c.mounter, true /* extensiveMountPointCheck */) + return mount.CleanupMountPoint(dir, c.mounter, true /* extensiveMountPointCheck */) } func getVolumeSource(spec *volume.Spec) (*v1.NFSVolumeSource, bool, error) { diff --git a/pkg/volume/photon_pd/attacher.go b/pkg/volume/photon_pd/attacher.go index d2570a4a743..2421eee6980 100644 --- a/pkg/volume/photon_pd/attacher.go +++ b/pkg/volume/photon_pd/attacher.go @@ -305,5 +305,5 @@ func (detacher *photonPersistentDiskDetacher) WaitForDetach(devicePath string, t } func (detacher *photonPersistentDiskDetacher) UnmountDevice(deviceMountPath string) error { - return volumeutil.UnmountPath(deviceMountPath, detacher.mounter) + return mount.CleanupMountPoint(deviceMountPath, detacher.mounter, false) } diff --git a/pkg/volume/photon_pd/photon_pd.go b/pkg/volume/photon_pd/photon_pd.go index 03cbd9b0ecb..3549b4d3d99 100644 --- a/pkg/volume/photon_pd/photon_pd.go +++ b/pkg/volume/photon_pd/photon_pd.go @@ -277,7 +277,7 @@ func (c *photonPersistentDiskUnmounter) 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 *photonPersistentDiskUnmounter) TearDownAt(dir string) error { - return util.UnmountPath(dir, c.mounter) + return mount.CleanupMountPoint(dir, c.mounter, false) } func makeGlobalPDPath(host volume.VolumeHost, devName string) string { diff --git a/pkg/volume/scaleio/sio_volume.go b/pkg/volume/scaleio/sio_volume.go index 4a5cb35221e..c73e16ae96c 100644 --- a/pkg/volume/scaleio/sio_volume.go +++ b/pkg/volume/scaleio/sio_volume.go @@ -193,7 +193,7 @@ func (v *sioVolume) TearDownAt(dir string) error { } klog.V(4).Info(log("attempting to unmount %s", dir)) - if err := util.UnmountPath(dir, mounter); err != nil { + if err := mount.CleanupMountPoint(dir, mounter, false); err != nil { klog.Error(log("teardown failed while unmounting dir %s: %v ", dir, err)) return err } diff --git a/pkg/volume/storageos/storageos.go b/pkg/volume/storageos/storageos.go index 9cb56b353aa..36469c7f51a 100644 --- a/pkg/volume/storageos/storageos.go +++ b/pkg/volume/storageos/storageos.go @@ -529,7 +529,7 @@ func (b *storageosUnmounter) 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 (b *storageosUnmounter) TearDownAt(dir string) error { - if err := util.UnmountPath(dir, b.mounter); err != nil { + if err := mount.CleanupMountPoint(dir, b.mounter, false); err != nil { klog.V(4).Infof("Unmounted StorageOS volume %s failed with: %v", b.pvName, err) } if err := b.manager.UnmountVolume(b); err != nil { diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index 18e24d69f05..437803b7afc 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -125,23 +125,6 @@ func SetReady(dir string) { file.Close() } -// UnmountPath is a common unmount routine that unmounts the given path and -// deletes the remaining directory if successful. -// TODO: Remove this function and change callers to call mount pkg directly -func UnmountPath(mountPath string, mounter mount.Interface) error { - return mount.CleanupMountPoint(mountPath, mounter, false /* extensiveMountPointCheck */) -} - -// UnmountMountPoint is a common unmount routine that unmounts the given path and -// deletes the remaining directory if successful. -// if extensiveMountPointCheck is true -// IsNotMountPoint will be called instead of IsLikelyNotMountPoint. -// IsNotMountPoint is more expensive but properly handles bind mounts. -// TODO: Change callers to call mount pkg directly -func UnmountMountPoint(mountPath string, mounter mount.Interface, extensiveMountPointCheck bool) error { - return mount.CleanupMountPoint(mountPath, mounter, extensiveMountPointCheck) -} - // PathExists returns true if the specified path exists. // TODO: Change callers to call mount pkg directly func PathExists(path string) (bool, error) { diff --git a/pkg/volume/vsphere_volume/attacher.go b/pkg/volume/vsphere_volume/attacher.go index ca934b45abd..ed7688f91eb 100644 --- a/pkg/volume/vsphere_volume/attacher.go +++ b/pkg/volume/vsphere_volume/attacher.go @@ -292,7 +292,7 @@ func (detacher *vsphereVMDKDetacher) Detach(volumeName string, nodeName types.No } func (detacher *vsphereVMDKDetacher) UnmountDevice(deviceMountPath string) error { - return volumeutil.UnmountPath(deviceMountPath, detacher.mounter) + return mount.CleanupMountPoint(deviceMountPath, detacher.mounter, false) } func setNodeVolume( diff --git a/pkg/volume/vsphere_volume/vsphere_volume.go b/pkg/volume/vsphere_volume/vsphere_volume.go index 7097005ef9e..aa7b2e8d56b 100644 --- a/pkg/volume/vsphere_volume/vsphere_volume.go +++ b/pkg/volume/vsphere_volume/vsphere_volume.go @@ -285,7 +285,7 @@ func (v *vsphereVolumeUnmounter) 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 (v *vsphereVolumeUnmounter) TearDownAt(dir string) error { - return util.UnmountPath(dir, v.mounter) + return mount.CleanupMountPoint(dir, v.mounter, false) } func makeGlobalPDPath(host volume.VolumeHost, devName string) string { From 8092904e3c20d7fff0a8ffb20b59b0e5fa027fc2 Mon Sep 17 00:00:00 2001 From: danielqsj Date: Tue, 8 Jan 2019 22:08:00 +0800 Subject: [PATCH 2/3] Cleanup PathExists callers --- pkg/kubelet/kubelet_getters.go | 8 ++++---- pkg/volume/awsebs/aws_util.go | 5 +++-- pkg/volume/azure_dd/azure_mounter.go | 3 ++- pkg/volume/cinder/attacher.go | 2 +- pkg/volume/cinder/cinder.go | 2 +- pkg/volume/emptydir/empty_dir.go | 2 +- pkg/volume/fc/fc_util.go | 3 ++- pkg/volume/flexvolume/detacher.go | 5 +++-- pkg/volume/flexvolume/unmounter.go | 5 +++-- pkg/volume/gcepd/gce_util.go | 3 ++- pkg/volume/iscsi/iscsi_util.go | 4 ++-- pkg/volume/photon_pd/attacher.go | 2 +- pkg/volume/photon_pd/photon_util.go | 3 ++- pkg/volume/rbd/attacher.go | 2 +- pkg/volume/rbd/rbd.go | 2 +- pkg/volume/rbd/rbd_util.go | 4 ++-- pkg/volume/util/util.go | 6 ------ pkg/volume/vsphere_volume/vsphere_volume_util.go | 3 ++- 18 files changed, 33 insertions(+), 31 deletions(-) diff --git a/pkg/kubelet/kubelet_getters.go b/pkg/kubelet/kubelet_getters.go index a577a6bfad7..1386a83ccb6 100644 --- a/pkg/kubelet/kubelet_getters.go +++ b/pkg/kubelet/kubelet_getters.go @@ -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 diff --git a/pkg/volume/awsebs/aws_util.go b/pkg/volume/awsebs/aws_util.go index e1c85aa8b70..b7a8438c756 100644 --- a/pkg/volume/awsebs/aws_util.go +++ b/pkg/volume/awsebs/aws_util.go @@ -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) } diff --git a/pkg/volume/azure_dd/azure_mounter.go b/pkg/volume/azure_dd/azure_mounter.go index 66c0e12910b..a47d709b0ca 100644 --- a/pkg/volume/azure_dd/azure_mounter.go +++ b/pkg/volume/azure_dd/azure_mounter.go @@ -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) diff --git a/pkg/volume/cinder/attacher.go b/pkg/volume/cinder/attacher.go index 16fbac3e433..493d2a54c1d 100644 --- a/pkg/volume/cinder/attacher.go +++ b/pkg/volume/cinder/attacher.go @@ -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 diff --git a/pkg/volume/cinder/cinder.go b/pkg/volume/cinder/cinder.go index e4e488b8d2e..2366eb93023 100644 --- a/pkg/volume/cinder/cinder.go +++ b/pkg/volume/cinder/cinder.go @@ -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) diff --git a/pkg/volume/emptydir/empty_dir.go b/pkg/volume/emptydir/empty_dir.go index 0dd6c6508a0..226480c60e4 100644 --- a/pkg/volume/emptydir/empty_dir.go +++ b/pkg/volume/emptydir/empty_dir.go @@ -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) diff --git a/pkg/volume/fc/fc_util.go b/pkg/volume/fc/fc_util.go index 2beafee94bf..9c08d52ffe4 100644 --- a/pkg/volume/fc/fc_util.go +++ b/pkg/volume/fc/fc_util.go @@ -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) diff --git a/pkg/volume/flexvolume/detacher.go b/pkg/volume/flexvolume/detacher.go index d98791f3d1b..72292f876fa 100644 --- a/pkg/volume/flexvolume/detacher.go +++ b/pkg/volume/flexvolume/detacher.go @@ -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 diff --git a/pkg/volume/flexvolume/unmounter.go b/pkg/volume/flexvolume/unmounter.go index a62636aba40..2827d67d2dd 100644 --- a/pkg/volume/flexvolume/unmounter.go +++ b/pkg/volume/flexvolume/unmounter.go @@ -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 diff --git a/pkg/volume/gcepd/gce_util.go b/pkg/volume/gcepd/gce_util.go index 153bab8716d..d0e13a8ddf7 100644 --- a/pkg/volume/gcepd/gce_util.go +++ b/pkg/volume/gcepd/gce_util.go @@ -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 diff --git a/pkg/volume/iscsi/iscsi_util.go b/pkg/volume/iscsi/iscsi_util.go index e5e04c518fd..9e04ab2b5f8 100644 --- a/pkg/volume/iscsi/iscsi_util.go +++ b/pkg/volume/iscsi/iscsi_util.go @@ -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) diff --git a/pkg/volume/photon_pd/attacher.go b/pkg/volume/photon_pd/attacher.go index 2421eee6980..3592e7ce8e3 100644 --- a/pkg/volume/photon_pd/attacher.go +++ b/pkg/volume/photon_pd/attacher.go @@ -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 diff --git a/pkg/volume/photon_pd/photon_util.go b/pkg/volume/photon_pd/photon_util.go index fe3a6c24c6d..23ebf92d033 100644 --- a/pkg/volume/photon_pd/photon_util.go +++ b/pkg/volume/photon_pd/photon_util.go @@ -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 diff --git a/pkg/volume/rbd/attacher.go b/pkg/volume/rbd/attacher.go index 626dc321489..c82a20e40f3 100644 --- a/pkg/volume/rbd/attacher.go +++ b/pkg/volume/rbd/attacher.go @@ -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) diff --git a/pkg/volume/rbd/rbd.go b/pkg/volume/rbd/rbd.go index d9197428f8b..96fc66d64e8 100644 --- a/pkg/volume/rbd/rbd.go +++ b/pkg/volume/rbd/rbd.go @@ -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) diff --git a/pkg/volume/rbd/rbd_util.go b/pkg/volume/rbd/rbd_util.go index ec0dd7f2ebb..a4afb518605 100644 --- a/pkg/volume/rbd/rbd_util.go +++ b/pkg/volume/rbd/rbd_util.go @@ -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) diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index 437803b7afc..da79215b5d3 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -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 { diff --git a/pkg/volume/vsphere_volume/vsphere_volume_util.go b/pkg/volume/vsphere_volume/vsphere_volume_util.go index a5880ea7fbf..4c87623326c 100644 --- a/pkg/volume/vsphere_volume/vsphere_volume_util.go +++ b/pkg/volume/vsphere_volume/vsphere_volume_util.go @@ -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 From 2426f0ee4eced3288940ac5e84b8b337a0abac79 Mon Sep 17 00:00:00 2001 From: danielqsj Date: Tue, 8 Jan 2019 22:09:36 +0800 Subject: [PATCH 3/3] Cleanup IsCorruptedMnt callers --- pkg/volume/flexvolume/detacher.go | 5 ++--- pkg/volume/flexvolume/unmounter.go | 3 +-- pkg/volume/util/util.go | 6 ------ 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/pkg/volume/flexvolume/detacher.go b/pkg/volume/flexvolume/detacher.go index 72292f876fa..39ff9770436 100644 --- a/pkg/volume/flexvolume/detacher.go +++ b/pkg/volume/flexvolume/detacher.go @@ -24,7 +24,6 @@ import ( "k8s.io/klog" "k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/volume" - "k8s.io/kubernetes/pkg/volume/util" ) type flexVolumeDetacher struct { @@ -57,13 +56,13 @@ func (d *flexVolumeDetacher) UnmountDevice(deviceMountPath string) error { klog.Warningf("Warning: Unmount skipped because path does not exist: %v", deviceMountPath) return nil } - if pathErr != nil && !util.IsCorruptedMnt(pathErr) { + if pathErr != nil && !mount.IsCorruptedMnt(pathErr) { return fmt.Errorf("Error checking path: %v", pathErr) } notmnt, err := isNotMounted(d.plugin.host.GetMounter(d.plugin.GetPluginName()), deviceMountPath) if err != nil { - if util.IsCorruptedMnt(err) { + if mount.IsCorruptedMnt(err) { notmnt = false // Corrupted error is assumed to be mounted. } else { return err diff --git a/pkg/volume/flexvolume/unmounter.go b/pkg/volume/flexvolume/unmounter.go index 2827d67d2dd..3da5f77e81f 100644 --- a/pkg/volume/flexvolume/unmounter.go +++ b/pkg/volume/flexvolume/unmounter.go @@ -23,7 +23,6 @@ import ( "k8s.io/klog" "k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/volume" - "k8s.io/kubernetes/pkg/volume/util" "k8s.io/utils/exec" ) @@ -50,7 +49,7 @@ func (f *flexVolumeUnmounter) TearDownAt(dir string) error { return nil } - if pathErr != nil && !util.IsCorruptedMnt(pathErr) { + if pathErr != nil && !mount.IsCorruptedMnt(pathErr) { return fmt.Errorf("Error checking path: %v", pathErr) } diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index da79215b5d3..8de0469f50e 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -125,12 +125,6 @@ func SetReady(dir string) { file.Close() } -// IsCorruptedMnt return true if err is about corrupted mount point -// TODO: Change callers to call mount pkg directly -func IsCorruptedMnt(err error) bool { - return mount.IsCorruptedMnt(err) -} - // GetSecretForPod locates secret by name in the pod's namespace and returns secret map func GetSecretForPod(pod *v1.Pod, secretName string, kubeClient clientset.Interface) (map[string]string, error) { secret := make(map[string]string)