Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit a8cabf1

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #46458 from jsafrane/mount-prep
Automatic merge from submit-queue (batch tested with PRs 46458, 50934, 50766, 50970, 47698) Prepare VolumeHost for running mount tools in containers This is the first part of implementation of kubernetes/enhancements#278 - running mount utilities in containers. It updates `VolumeHost` interface: * `GetMounter()` now requires volume plugin name, as it is going to return different mounter to different volume plugings, because mount utilities for these plugins can be on different places. * New `GetExec()` method that should volume plugins use to execute any utilities. This new `Exec` interface will execute them on proper place. * `SafeFormatAndMount` is updated to the new `Exec` interface. This is just a preparation, `GetExec` right now leads to simple `os.Exec` and mount utilities are executed on the same place as before. Also, the volume plugins will be updated in subsequent PRs (split into separate PRs, some plugins required lot of changes). ```release-note NONE ``` @kubernetes/sig-storage-pr-reviews @rootfs @gnufied
2 parents c405b3b + 411f805 commit a8cabf1

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

pkg/volume/cinder/attacher.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"k8s.io/kubernetes/pkg/util/mount"
3030
"k8s.io/kubernetes/pkg/volume"
3131
volumeutil "k8s.io/kubernetes/pkg/volume/util"
32-
"k8s.io/utils/exec"
32+
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
3333
)
3434

3535
type cinderDiskAttacher struct {
@@ -66,7 +66,7 @@ func (plugin *cinderPlugin) NewAttacher() (volume.Attacher, error) {
6666
}
6767

6868
func (plugin *cinderPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) {
69-
mounter := plugin.host.GetMounter()
69+
mounter := plugin.host.GetMounter(plugin.GetPluginName())
7070
return mount.GetMountRefs(mounter, deviceMountPath)
7171
}
7272

@@ -262,7 +262,7 @@ func (attacher *cinderDiskAttacher) GetDeviceMountPath(
262262

263263
// FIXME: this method can be further pruned.
264264
func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error {
265-
mounter := attacher.host.GetMounter()
265+
mounter := attacher.host.GetMounter(cinderVolumePluginName)
266266
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
267267
if err != nil {
268268
if os.IsNotExist(err) {
@@ -285,7 +285,7 @@ func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath st
285285
options = append(options, "ro")
286286
}
287287
if notMnt {
288-
diskMounter := &mount.SafeFormatAndMount{Interface: mounter, Runner: exec.New()}
288+
diskMounter := volumehelper.NewSafeFormatAndMountFromHost(cinderVolumePluginName, attacher.host)
289289
mountOptions := volume.MountOptionFromSpec(spec, options...)
290290
err = diskMounter.FormatAndMount(devicePath, deviceMountPath, volumeSource.FSType, mountOptions)
291291
if err != nil {
@@ -309,7 +309,7 @@ func (plugin *cinderPlugin) NewDetacher() (volume.Detacher, error) {
309309
return nil, err
310310
}
311311
return &cinderDiskDetacher{
312-
mounter: plugin.host.GetMounter(),
312+
mounter: plugin.host.GetMounter(plugin.GetPluginName()),
313313
cinderProvider: cinder,
314314
}, nil
315315
}

pkg/volume/cinder/cinder.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"k8s.io/kubernetes/pkg/volume"
3737
"k8s.io/kubernetes/pkg/volume/util"
3838
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
39-
"k8s.io/utils/exec"
4039
)
4140

4241
// This is the primary entrypoint for volume plugins.
@@ -116,7 +115,7 @@ func (plugin *cinderPlugin) GetAccessModes() []v1.PersistentVolumeAccessMode {
116115
}
117116

118117
func (plugin *cinderPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volume.VolumeOptions) (volume.Mounter, error) {
119-
return plugin.newMounterInternal(spec, pod.UID, &CinderDiskUtil{}, plugin.host.GetMounter())
118+
return plugin.newMounterInternal(spec, pod.UID, &CinderDiskUtil{}, plugin.host.GetMounter(plugin.GetPluginName()))
120119
}
121120

122121
func (plugin *cinderPlugin) newMounterInternal(spec *volume.Spec, podUID types.UID, manager cdManager, mounter mount.Interface) (volume.Mounter, error) {
@@ -139,11 +138,11 @@ func (plugin *cinderPlugin) newMounterInternal(spec *volume.Spec, podUID types.U
139138
},
140139
fsType: fsType,
141140
readOnly: readOnly,
142-
blockDeviceMounter: &mount.SafeFormatAndMount{Interface: mounter, Runner: exec.New()}}, nil
141+
blockDeviceMounter: volumehelper.NewSafeFormatAndMountFromHost(plugin.GetPluginName(), plugin.host)}, nil
143142
}
144143

145144
func (plugin *cinderPlugin) NewUnmounter(volName string, podUID types.UID) (volume.Unmounter, error) {
146-
return plugin.newUnmounterInternal(volName, podUID, &CinderDiskUtil{}, plugin.host.GetMounter())
145+
return plugin.newUnmounterInternal(volName, podUID, &CinderDiskUtil{}, plugin.host.GetMounter(plugin.GetPluginName()))
147146
}
148147

149148
func (plugin *cinderPlugin) newUnmounterInternal(volName string, podUID types.UID, manager cdManager, mounter mount.Interface) (volume.Unmounter, error) {
@@ -216,7 +215,7 @@ func (plugin *cinderPlugin) getCloudProvider() (CinderProvider, error) {
216215
}
217216

218217
func (plugin *cinderPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) {
219-
mounter := plugin.host.GetMounter()
218+
mounter := plugin.host.GetMounter(plugin.GetPluginName())
220219
pluginDir := plugin.host.GetPluginDir(plugin.GetPluginName())
221220
sourceName, err := mounter.GetDeviceNameFromMount(mountPath, pluginDir)
222221
if err != nil {

0 commit comments

Comments
 (0)