Merge pull request #54696 from jsafrane/fix-rbd-exec

Automatic merge from submit-queue (batch tested with PRs 54635, 54250, 54657, 54696, 54700). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Don't cache exec and mounter in RBD volume plugin

#51608 has broken containerized RBD mount utilities proposed in https://github.com/kubernetes/kubernetes/pull/53440.

Volume plugin can get a different exec and mounter implementation with every call, it must not be cached.

```release-note
NONE
```

/sig storage
/assign @rootfs
This commit is contained in:
Kubernetes Submit Queue 2017-10-27 14:38:28 -07:00 committed by GitHub
commit 713abdf2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -27,6 +27,7 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
volutil "k8s.io/kubernetes/pkg/volume/util"
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
)
// NewAttacher implements AttachableVolumePlugin.NewAttacher.
@ -38,6 +39,7 @@ func (plugin *rbdPlugin) newAttacherInternal(manager diskManager) (volume.Attach
return &rbdAttacher{
plugin: plugin,
manager: manager,
mounter: volumehelper.NewSafeFormatAndMountFromHost(plugin.GetPluginName(), plugin.host),
}, nil
}
@ -50,6 +52,7 @@ func (plugin *rbdPlugin) newDetacherInternal(manager diskManager) (volume.Detach
return &rbdDetacher{
plugin: plugin,
manager: manager,
mounter: volumehelper.NewSafeFormatAndMountFromHost(plugin.GetPluginName(), plugin.host),
}, nil
}
@ -62,6 +65,7 @@ func (plugin *rbdPlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, e
// rbdAttacher implements volume.Attacher interface.
type rbdAttacher struct {
plugin *rbdPlugin
mounter *mount.SafeFormatAndMount
manager diskManager
}
@ -124,7 +128,7 @@ func (attacher *rbdAttacher) GetDeviceMountPath(spec *volume.Spec) (string, erro
// This method is idempotent, callers are responsible for retrying on failure.
func (attacher *rbdAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error {
glog.V(4).Infof("rbd: mouting device %s to %s", devicePath, deviceMountPath)
notMnt, err := attacher.plugin.mounter.IsLikelyNotMountPoint(deviceMountPath)
notMnt, err := attacher.mounter.IsLikelyNotMountPoint(deviceMountPath)
if err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(deviceMountPath, 0750); err != nil {
@ -151,7 +155,7 @@ func (attacher *rbdAttacher) MountDevice(spec *volume.Spec, devicePath string, d
options = append(options, "ro")
}
mountOptions := volume.MountOptionFromSpec(spec, options...)
err = attacher.plugin.mounter.FormatAndMount(devicePath, deviceMountPath, fstype, mountOptions)
err = attacher.mounter.FormatAndMount(devicePath, deviceMountPath, fstype, mountOptions)
if err != nil {
os.Remove(deviceMountPath)
return fmt.Errorf("rbd: failed to mount device %s at %s (fstype: %s), error %v", devicePath, deviceMountPath, fstype, err)
@ -164,6 +168,7 @@ func (attacher *rbdAttacher) MountDevice(spec *volume.Spec, devicePath string, d
type rbdDetacher struct {
plugin *rbdPlugin
manager diskManager
mounter *mount.SafeFormatAndMount
}
var _ volume.Detacher = &rbdDetacher{}
@ -185,7 +190,7 @@ func (detacher *rbdDetacher) UnmountDevice(deviceMountPath string) error {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", deviceMountPath)
return nil
}
devicePath, cnt, err := mount.GetDeviceNameFromMount(detacher.plugin.mounter, deviceMountPath)
devicePath, cnt, err := mount.GetDeviceNameFromMount(detacher.mounter, deviceMountPath)
if err != nil {
return err
}
@ -195,7 +200,7 @@ func (detacher *rbdDetacher) UnmountDevice(deviceMountPath string) error {
if cnt == 1 {
// Unmount the device from the device mount point.
glog.V(4).Infof("rbd: unmouting device mountpoint %s", deviceMountPath)
if err = detacher.plugin.mounter.Unmount(deviceMountPath); err != nil {
if err = detacher.mounter.Unmount(deviceMountPath); err != nil {
return err
}
glog.V(3).Infof("rbd: successfully umount device mountpath %s", deviceMountPath)

View File

@ -41,14 +41,12 @@ var (
// This is the primary entrypoint for volume plugins.
func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.VolumePlugin{&rbdPlugin{nil, nil, nil}}
return []volume.VolumePlugin{&rbdPlugin{}}
}
// rbdPlugin implements Volume.VolumePlugin.
type rbdPlugin struct {
host volume.VolumeHost
exec mount.Exec
mounter *mount.SafeFormatAndMount
host volume.VolumeHost
}
var _ volume.VolumePlugin = &rbdPlugin{}
@ -74,8 +72,6 @@ func getPath(uid types.UID, volName string, host volume.VolumeHost) string {
func (plugin *rbdPlugin) Init(host volume.VolumeHost) error {
plugin.host = host
plugin.exec = host.GetExec(plugin.GetPluginName())
plugin.mounter = volumehelper.NewSafeFormatAndMountFromHost(plugin.GetPluginName(), plugin.host)
return nil
}
@ -505,8 +501,8 @@ func newRBD(podUID types.UID, volName string, image string, pool string, readOnl
Pool: pool,
ReadOnly: readOnly,
plugin: plugin,
mounter: plugin.mounter,
exec: plugin.exec,
mounter: volumehelper.NewSafeFormatAndMountFromHost(plugin.GetPluginName(), plugin.host),
exec: plugin.host.GetExec(plugin.GetPluginName()),
manager: manager,
MetricsProvider: volume.NewMetricsStatFS(getPath(podUID, volName, plugin.host)),
}

View File

@ -297,7 +297,8 @@ func (util *RBDUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, devic
var err error
if len(device) > 0 {
// rbd unmap
_, err = plugin.exec.Run("rbd", "unmap", device)
exec := plugin.host.GetExec(plugin.GetPluginName())
_, err = exec.Run("rbd", "unmap", device)
if err != nil {
return rbdErrors(err, fmt.Errorf("rbd: failed to unmap device %s:Error: %v", device, err))
}