From 12b7f1450c9646dbd6e6b79a05e943bd2c70ee81 Mon Sep 17 00:00:00 2001 From: Travis Rhoden Date: Fri, 29 Mar 2019 16:07:07 -0600 Subject: [PATCH] Move MountsInGlobalPDPath from mount pkg to volume Since pkg/util/mount is going to move out of k/k, this exported constant that is Kubernetes specific needed to move somewhere else. Made sense to move it to pkg/volume/util. Update GetDeviceNameFromMount in the mount interface to now take a pluginMountDir argument, which is volume plugin dir with the global mount path appended to it already. --- pkg/util/mount/fake.go | 4 ++-- pkg/util/mount/mount.go | 17 ++++++++--------- pkg/util/mount/mount_linux.go | 17 ++++++++--------- pkg/util/mount/mount_unsupported.go | 4 ++-- pkg/util/mount/mount_windows.go | 10 +++++----- pkg/volume/awsebs/aws_ebs.go | 6 +++--- pkg/volume/azure_dd/attacher.go | 2 +- pkg/volume/azure_dd/azure_common.go | 4 ++-- pkg/volume/azure_dd/azure_dd.go | 4 ++-- pkg/volume/cinder/cinder.go | 6 +++--- pkg/volume/gcepd/gce_pd.go | 6 +++--- pkg/volume/local/local.go | 2 +- pkg/volume/photon_pd/photon_pd.go | 6 +++--- pkg/volume/rbd/rbd.go | 4 ++-- pkg/volume/rbd/rbd_util.go | 3 ++- pkg/volume/storageos/storageos.go | 2 +- pkg/volume/util/exec/exec_mount.go | 4 ++-- pkg/volume/util/exec/exec_mount_unsupported.go | 2 +- pkg/volume/util/nsenter/nsenter_mount.go | 4 ++-- .../util/nsenter/nsenter_mount_unsupported.go | 2 +- pkg/volume/util/util.go | 11 +++++++++++ pkg/volume/vsphere_volume/vsphere_volume.go | 6 +++--- 22 files changed, 68 insertions(+), 58 deletions(-) diff --git a/pkg/util/mount/fake.go b/pkg/util/mount/fake.go index 29ffbc98238..22b46d95c93 100644 --- a/pkg/util/mount/fake.go +++ b/pkg/util/mount/fake.go @@ -182,8 +182,8 @@ func (f *FakeMounter) PathIsDevice(pathname string) (bool, error) { return true, nil } -func (f *FakeMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return getDeviceNameFromMount(f, mountPath, pluginDir) +func (f *FakeMounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) { + return getDeviceNameFromMount(f, mountPath, pluginMountDir) } func (f *FakeMounter) MakeRShared(path string) error { diff --git a/pkg/util/mount/mount.go b/pkg/util/mount/mount.go index 40de6ed7c96..cc313909fc7 100644 --- a/pkg/util/mount/mount.go +++ b/pkg/util/mount/mount.go @@ -29,13 +29,12 @@ type FileType string const ( // Default mount command if mounter path is not specified - defaultMountCommand = "mount" - MountsInGlobalPDPath = "mounts" - FileTypeDirectory FileType = "Directory" - FileTypeFile FileType = "File" - FileTypeSocket FileType = "Socket" - FileTypeCharDev FileType = "CharDevice" - FileTypeBlockDev FileType = "BlockDevice" + defaultMountCommand = "mount" + FileTypeDirectory FileType = "Directory" + FileTypeFile FileType = "File" + FileTypeSocket FileType = "Socket" + FileTypeCharDev FileType = "CharDevice" + FileTypeBlockDev FileType = "BlockDevice" ) type Interface interface { @@ -62,8 +61,8 @@ type Interface interface { // PathIsDevice determines if a path is a device. PathIsDevice(pathname string) (bool, error) // GetDeviceNameFromMount finds the device name by checking the mount path - // to get the global mount path which matches its plugin directory - GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) + // to get the global mount path within its plugin directory + GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) // MakeRShared checks that given path is on a mount with 'rshared' mount // propagation. If not, it bind-mounts the path as rshared. MakeRShared(path string) error diff --git a/pkg/util/mount/mount_linux.go b/pkg/util/mount/mount_linux.go index 8ba7806864b..b603f2780de 100644 --- a/pkg/util/mount/mount_linux.go +++ b/pkg/util/mount/mount_linux.go @@ -304,19 +304,19 @@ func ExclusiveOpenFailsOnDevice(pathname string) (bool, error) { } //GetDeviceNameFromMount: given a mount point, find the device name from its global mount point -func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return GetDeviceNameFromMountLinux(mounter, mountPath, pluginDir) +func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) { + return GetDeviceNameFromMountLinux(mounter, mountPath, pluginMountDir) } -func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (string, error) { - return GetDeviceNameFromMountLinux(mounter, mountPath, pluginDir) +func getDeviceNameFromMount(mounter Interface, mountPath, pluginMountDir string) (string, error) { + return GetDeviceNameFromMountLinux(mounter, mountPath, pluginMountDir) } // GetDeviceNameFromMountLinux find the device name from /proc/mounts in which -// the mount path reference should match the given plugin directory. In case no mount path reference +// the mount path reference should match the given plugin mount directory. In case no mount path reference // matches, returns the volume name taken from its given mountPath // This implementation is shared with NsEnterMounter -func GetDeviceNameFromMountLinux(mounter Interface, mountPath, pluginDir string) (string, error) { +func GetDeviceNameFromMountLinux(mounter Interface, mountPath, pluginMountDir string) (string, error) { refs, err := mounter.GetMountRefs(mountPath) if err != nil { klog.V(4).Infof("GetMountRefs failed for mount path %q: %v", mountPath, err) @@ -326,10 +326,9 @@ func GetDeviceNameFromMountLinux(mounter Interface, mountPath, pluginDir string) klog.V(4).Infof("Directory %s is not mounted", mountPath) return "", fmt.Errorf("directory %s is not mounted", mountPath) } - basemountPath := path.Join(pluginDir, MountsInGlobalPDPath) for _, ref := range refs { - if strings.HasPrefix(ref, basemountPath) { - volumeID, err := filepath.Rel(basemountPath, ref) + if strings.HasPrefix(ref, pluginMountDir) { + volumeID, err := filepath.Rel(pluginMountDir, ref) if err != nil { klog.Errorf("Failed to get volume id from mount %s - %v", mountPath, err) return "", err diff --git a/pkg/util/mount/mount_unsupported.go b/pkg/util/mount/mount_unsupported.go index 638b941e2fa..362ece518a3 100644 --- a/pkg/util/mount/mount_unsupported.go +++ b/pkg/util/mount/mount_unsupported.go @@ -58,11 +58,11 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) { return true, unsupportedErr } -func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { +func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) { return "", unsupportedErr } -func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (string, error) { +func getDeviceNameFromMount(mounter Interface, mountPath, pluginMountDir string) (string, error) { return "", unsupportedErr } diff --git a/pkg/util/mount/mount_windows.go b/pkg/util/mount/mount_windows.go index 026d42196c5..dd79842b999 100644 --- a/pkg/util/mount/mount_windows.go +++ b/pkg/util/mount/mount_windows.go @@ -196,14 +196,14 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) { } // GetDeviceNameFromMount given a mnt point, find the device -func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return getDeviceNameFromMount(mounter, mountPath, pluginDir) +func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) { + return getDeviceNameFromMount(mounter, mountPath, pluginMountDir) } // getDeviceNameFromMount find the device(drive) name in which -// the mount path reference should match the given plugin directory. In case no mount path reference +// the mount path reference should match the given plugin mount directory. In case no mount path reference // matches, returns the volume name taken from its given mountPath -func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (string, error) { +func getDeviceNameFromMount(mounter Interface, mountPath, pluginMountDir string) (string, error) { refs, err := mounter.GetMountRefs(mountPath) if err != nil { klog.V(4).Infof("GetMountRefs failed for mount path %q: %v", mountPath, err) @@ -212,7 +212,7 @@ func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (str if len(refs) == 0 { return "", fmt.Errorf("directory %s is not mounted", mountPath) } - basemountPath := normalizeWindowsPath(path.Join(pluginDir, MountsInGlobalPDPath)) + basemountPath := normalizeWindowsPath(pluginMountDir) for _, ref := range refs { if strings.Contains(ref, basemountPath) { volumeID, err := filepath.Rel(normalizeWindowsPath(basemountPath), ref) diff --git a/pkg/volume/awsebs/aws_ebs.go b/pkg/volume/awsebs/aws_ebs.go index 2f6e285e84b..77f2d589d8f 100644 --- a/pkg/volume/awsebs/aws_ebs.go +++ b/pkg/volume/awsebs/aws_ebs.go @@ -250,8 +250,8 @@ func getVolumeSource( func (plugin *awsElasticBlockStorePlugin) ConstructVolumeSpec(volName, mountPath string) (*volume.Spec, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName()) - volumeID, err := mounter.GetDeviceNameFromMount(mountPath, pluginDir) + pluginMntDir := util.GetPluginMountDir(plugin.host, plugin.GetPluginName()) + volumeID, err := mounter.GetDeviceNameFromMount(mountPath, pluginMntDir) if err != nil { return nil, err } @@ -451,7 +451,7 @@ func makeGlobalPDPath(host volume.VolumeHost, volumeID aws.KubernetesVolumeID) s // Clean up the URI to be more fs-friendly name := string(volumeID) name = strings.Replace(name, "://", "/", -1) - return filepath.Join(host.GetPluginDir(awsElasticBlockStorePluginName), mount.MountsInGlobalPDPath, name) + return filepath.Join(host.GetPluginDir(awsElasticBlockStorePluginName), util.MountsInGlobalPDPath, name) } func (ebs *awsElasticBlockStore) GetPath() string { diff --git a/pkg/volume/azure_dd/attacher.go b/pkg/volume/azure_dd/attacher.go index 3f0ca0ef8c1..001a8bae008 100644 --- a/pkg/volume/azure_dd/attacher.go +++ b/pkg/volume/azure_dd/attacher.go @@ -199,7 +199,7 @@ func (a *azureDiskAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error } if volumeSource.Kind == nil { // this spec was constructed from info on the node - pdPath := filepath.Join(a.plugin.host.GetPluginDir(azureDataDiskPluginName), mount.MountsInGlobalPDPath, volumeSource.DataDiskURI) + pdPath := filepath.Join(a.plugin.host.GetPluginDir(azureDataDiskPluginName), util.MountsInGlobalPDPath, volumeSource.DataDiskURI) return pdPath, nil } diff --git a/pkg/volume/azure_dd/azure_common.go b/pkg/volume/azure_dd/azure_common.go index 89cf06b6477..ae85a7f9596 100644 --- a/pkg/volume/azure_dd/azure_common.go +++ b/pkg/volume/azure_dd/azure_common.go @@ -31,8 +31,8 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" api "k8s.io/kubernetes/pkg/apis/core" - "k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/volume" + "k8s.io/kubernetes/pkg/volume/util" "k8s.io/legacy-cloud-providers/azure" utilstrings "k8s.io/utils/strings" ) @@ -80,7 +80,7 @@ func makeGlobalPDPath(host volume.VolumeHost, diskUri string, isManaged bool) (s } // "{m for managed b for blob}{hashed diskUri or DiskId depending on disk kind }" diskName := fmt.Sprintf(uniqueDiskNameTemplate, prefix, hashedDiskUri) - pdPath := filepath.Join(host.GetPluginDir(azureDataDiskPluginName), mount.MountsInGlobalPDPath, diskName) + pdPath := filepath.Join(host.GetPluginDir(azureDataDiskPluginName), util.MountsInGlobalPDPath, diskName) return pdPath, nil } diff --git a/pkg/volume/azure_dd/azure_dd.go b/pkg/volume/azure_dd/azure_dd.go index 19551bc41c0..a15f4390695 100644 --- a/pkg/volume/azure_dd/azure_dd.go +++ b/pkg/volume/azure_dd/azure_dd.go @@ -328,8 +328,8 @@ var _ volume.NodeExpandableVolumePlugin = &azureDataDiskPlugin{} func (plugin *azureDataDiskPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName()) - sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginDir) + pluginMntDir := util.GetPluginMountDir(plugin.host, plugin.GetPluginName()) + sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginMntDir) if err != nil { return nil, err diff --git a/pkg/volume/cinder/cinder.go b/pkg/volume/cinder/cinder.go index 3347b46eccd..73af9787636 100644 --- a/pkg/volume/cinder/cinder.go +++ b/pkg/volume/cinder/cinder.go @@ -266,8 +266,8 @@ func (plugin *cinderPlugin) getCloudProvider() (BlockStorageProvider, error) { func (plugin *cinderPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName()) - sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginDir) + pluginMntDir := util.GetPluginMountDir(plugin.host, plugin.GetPluginName()) + sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginMntDir) if err != nil { return nil, err } @@ -449,7 +449,7 @@ func (b *cinderVolumeMounter) SetUpAt(dir string, fsGroup *int64) error { } func makeGlobalPDName(host volume.VolumeHost, devName string) string { - return path.Join(host.GetPluginDir(cinderVolumePluginName), mount.MountsInGlobalPDPath, devName) + return path.Join(host.GetPluginDir(cinderVolumePluginName), util.MountsInGlobalPDPath, devName) } func (cd *cinderVolume) GetPath() string { diff --git a/pkg/volume/gcepd/gce_pd.go b/pkg/volume/gcepd/gce_pd.go index b48fc283d5c..86e7e39a616 100644 --- a/pkg/volume/gcepd/gce_pd.go +++ b/pkg/volume/gcepd/gce_pd.go @@ -302,8 +302,8 @@ var _ volume.NodeExpandableVolumePlugin = &gcePersistentDiskPlugin{} func (plugin *gcePersistentDiskPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName()) - sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginDir) + pluginMntDir := util.GetPluginMountDir(plugin.host, plugin.GetPluginName()) + sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginMntDir) if err != nil { return nil, err } @@ -441,7 +441,7 @@ func (b *gcePersistentDiskMounter) SetUpAt(dir string, fsGroup *int64) error { } func makeGlobalPDName(host volume.VolumeHost, devName string) string { - return path.Join(host.GetPluginDir(gcePersistentDiskPluginName), mount.MountsInGlobalPDPath, devName) + return path.Join(host.GetPluginDir(gcePersistentDiskPluginName), util.MountsInGlobalPDPath, devName) } func (b *gcePersistentDiskMounter) GetPath() string { diff --git a/pkg/volume/local/local.go b/pkg/volume/local/local.go index 05c52f6ba17..5b3c30fab15 100644 --- a/pkg/volume/local/local.go +++ b/pkg/volume/local/local.go @@ -222,7 +222,7 @@ func (plugin *localVolumePlugin) ConstructBlockVolumeSpec(podUID types.UID, volu } func (plugin *localVolumePlugin) generateBlockDeviceBaseGlobalPath() string { - return filepath.Join(plugin.host.GetPluginDir(localVolumePluginName), mount.MountsInGlobalPDPath) + return filepath.Join(plugin.host.GetPluginDir(localVolumePluginName), util.MountsInGlobalPDPath) } func (plugin *localVolumePlugin) getGlobalLocalPath(spec *volume.Spec) (string, error) { diff --git a/pkg/volume/photon_pd/photon_pd.go b/pkg/volume/photon_pd/photon_pd.go index 9dfa7dab3d7..44bc0a3694e 100644 --- a/pkg/volume/photon_pd/photon_pd.go +++ b/pkg/volume/photon_pd/photon_pd.go @@ -136,8 +136,8 @@ func (plugin *photonPersistentDiskPlugin) newUnmounterInternal(volName string, p func (plugin *photonPersistentDiskPlugin) ConstructVolumeSpec(volumeSpecName, mountPath string) (*volume.Spec, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName()) - pdID, err := mounter.GetDeviceNameFromMount(mountPath, pluginDir) + pluginMntDir := util.GetPluginMountDir(plugin.host, plugin.GetPluginName()) + pdID, err := mounter.GetDeviceNameFromMount(mountPath, pluginMntDir) if err != nil { return nil, err } @@ -285,7 +285,7 @@ func (c *photonPersistentDiskUnmounter) TearDownAt(dir string) error { } func makeGlobalPDPath(host volume.VolumeHost, devName string) string { - return path.Join(host.GetPluginDir(photonPersistentDiskPluginName), mount.MountsInGlobalPDPath, devName) + return path.Join(host.GetPluginDir(photonPersistentDiskPluginName), util.MountsInGlobalPDPath, devName) } func (ppd *photonPersistentDisk) GetPath() string { diff --git a/pkg/volume/rbd/rbd.go b/pkg/volume/rbd/rbd.go index 8d2fbd31577..bae23bc7334 100644 --- a/pkg/volume/rbd/rbd.go +++ b/pkg/volume/rbd/rbd.go @@ -374,8 +374,8 @@ func (plugin *rbdPlugin) newUnmounterInternal(volName string, podUID types.UID, func (plugin *rbdPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName()) - sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginDir) + pluginMntDir := volutil.GetPluginMountDir(plugin.host, plugin.GetPluginName()) + sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginMntDir) if err != nil { return nil, err } diff --git a/pkg/volume/rbd/rbd_util.go b/pkg/volume/rbd/rbd_util.go index e16327bf323..8d7b1cbf02a 100644 --- a/pkg/volume/rbd/rbd_util.go +++ b/pkg/volume/rbd/rbd_util.go @@ -41,6 +41,7 @@ import ( "k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/node" "k8s.io/kubernetes/pkg/volume" + volutil "k8s.io/kubernetes/pkg/volume/util" utilpath "k8s.io/utils/path" ) @@ -255,7 +256,7 @@ func makePDNameInternal(host volume.VolumeHost, pool string, image string) strin return deprecatedDir } // Return the canonical format path. - return path.Join(host.GetPluginDir(rbdPluginName), mount.MountsInGlobalPDPath, pool+"-image-"+image) + return path.Join(host.GetPluginDir(rbdPluginName), volutil.MountsInGlobalPDPath, pool+"-image-"+image) } // Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/volumeDevices/pool-image-image. diff --git a/pkg/volume/storageos/storageos.go b/pkg/volume/storageos/storageos.go index f9ad832013b..4e85e70d3be 100644 --- a/pkg/volume/storageos/storageos.go +++ b/pkg/volume/storageos/storageos.go @@ -441,7 +441,7 @@ func (b *storageosMounter) SetUpAt(dir string, fsGroup *int64) error { } func makeGlobalPDName(host volume.VolumeHost, pvName, volNamespace, volName string) string { - return path.Join(host.GetPluginDir(utilstrings.EscapeQualifiedName(storageosPluginName)), mount.MountsInGlobalPDPath, pvName+"."+volNamespace+"."+volName) + return path.Join(host.GetPluginDir(utilstrings.EscapeQualifiedName(storageosPluginName)), util.MountsInGlobalPDPath, pvName+"."+volNamespace+"."+volName) } // Given the pod id and PV name, finds the volume's namespace and name from the diff --git a/pkg/volume/util/exec/exec_mount.go b/pkg/volume/util/exec/exec_mount.go index a5ab848a85d..1d2cfbdeac7 100644 --- a/pkg/volume/util/exec/exec_mount.go +++ b/pkg/volume/util/exec/exec_mount.go @@ -112,8 +112,8 @@ func (m *execMounter) PathIsDevice(pathname string) (bool, error) { } //GetDeviceNameFromMount given a mount point, find the volume id from checking /proc/mounts -func (m *execMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return m.wrappedMounter.GetDeviceNameFromMount(mountPath, pluginDir) +func (m *execMounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) { + return m.wrappedMounter.GetDeviceNameFromMount(mountPath, pluginMountDir) } func (m *execMounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool { diff --git a/pkg/volume/util/exec/exec_mount_unsupported.go b/pkg/volume/util/exec/exec_mount_unsupported.go index fa02c1fa257..ece0234b785 100644 --- a/pkg/volume/util/exec/exec_mount_unsupported.go +++ b/pkg/volume/util/exec/exec_mount_unsupported.go @@ -53,7 +53,7 @@ func (mounter *execMounter) IsLikelyNotMountPoint(file string) (bool, error) { return true, nil } -func (mounter *execMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { +func (mounter *execMounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) { return "", nil } diff --git a/pkg/volume/util/nsenter/nsenter_mount.go b/pkg/volume/util/nsenter/nsenter_mount.go index c4f5f265777..91145fa9d10 100644 --- a/pkg/volume/util/nsenter/nsenter_mount.go +++ b/pkg/volume/util/nsenter/nsenter_mount.go @@ -228,8 +228,8 @@ func (n *Mounter) PathIsDevice(pathname string) (bool, error) { } //GetDeviceNameFromMount given a mount point, find the volume id from checking /proc/mounts -func (n *Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return mount.GetDeviceNameFromMountLinux(n, mountPath, pluginDir) +func (n *Mounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) { + return mount.GetDeviceNameFromMountLinux(n, mountPath, pluginMountDir) } // MakeRShared checks if path is shared and bind-mounts it as rshared if needed. diff --git a/pkg/volume/util/nsenter/nsenter_mount_unsupported.go b/pkg/volume/util/nsenter/nsenter_mount_unsupported.go index bfa784529b6..2ce12ad3a5e 100644 --- a/pkg/volume/util/nsenter/nsenter_mount_unsupported.go +++ b/pkg/volume/util/nsenter/nsenter_mount_unsupported.go @@ -78,7 +78,7 @@ func (*Mounter) PathIsDevice(pathname string) (bool, error) { // GetDeviceNameFromMount finds the device name from its global mount point using the // given mountpath and plugin location. It is a noop of unsupported platforms -func (*Mounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { +func (*Mounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) { return "", nil } diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index 2565c6b07f4..d6ea5165a70 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -58,6 +58,10 @@ const ( // that decides if pod volumes are unmounted when pod is terminated KeepTerminatedPodVolumesAnnotation string = "volumes.kubernetes.io/keep-terminated-pod-volumes" + // MountsInGlobalPDPath is name of the directory appended to a volume plugin + // name to create the place for volume mounts in the global PD path. + MountsInGlobalPDPath = "mounts" + // VolumeGidAnnotationKey is the of the annotation on the PersistentVolume // object that specifies a supplemental GID. VolumeGidAnnotationKey = "pv.beta.kubernetes.io/gid" @@ -530,3 +534,10 @@ func MapBlockVolume( return nil } + +// GetPluginMountDir returns the global mount directory name appended +// to the given plugin name's plugin directory +func GetPluginMountDir(host volume.VolumeHost, name string) string { + mntDir := filepath.Join(host.GetPluginDir(name), MountsInGlobalPDPath) + return mntDir +} diff --git a/pkg/volume/vsphere_volume/vsphere_volume.go b/pkg/volume/vsphere_volume/vsphere_volume.go index 31473d58dce..7a606794020 100644 --- a/pkg/volume/vsphere_volume/vsphere_volume.go +++ b/pkg/volume/vsphere_volume/vsphere_volume.go @@ -145,8 +145,8 @@ func (plugin *vsphereVolumePlugin) newUnmounterInternal(volName string, podUID t func (plugin *vsphereVolumePlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) { mounter := plugin.host.GetMounter(plugin.GetPluginName()) - pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName()) - volumePath, err := mounter.GetDeviceNameFromMount(mountPath, pluginDir) + pluginMntDir := util.GetPluginMountDir(plugin.host, plugin.GetPluginName()) + volumePath, err := mounter.GetDeviceNameFromMount(mountPath, pluginMntDir) if err != nil { return nil, err } @@ -294,7 +294,7 @@ func (v *vsphereVolumeUnmounter) TearDownAt(dir string) error { } func makeGlobalPDPath(host volume.VolumeHost, devName string) string { - return path.Join(host.GetPluginDir(vsphereVolumePluginName), mount.MountsInGlobalPDPath, devName) + return path.Join(host.GetPluginDir(vsphereVolumePluginName), util.MountsInGlobalPDPath, devName) } func (vv *vsphereVolume) GetPath() string {