Remove call to clear mount info if already set

https://github.com/kubernetes/kubernetes/pull/69782 introduced a change
to register the device attachment (in the StorageOS API) prior to the
volume attachment.  The volume attachment code would clear any mount
info, causing the StorageOS API to register the mount and then
immediately de-register it.

The code to clear the mount info on volume attach is no longer needed.
It was used to force-mount a volume if StorageOS thought it was already
mounted.  In practice it was not needed, and administrators have other
ways of clearing stale mount information if required.
k3s-v1.15.3
Simon Croome 2019-05-30 13:57:39 +01:00
parent b3981a2f9a
commit 6d9f4659d8
1 changed files with 20 additions and 15 deletions

View File

@ -88,7 +88,7 @@ func (u *storageosUtil) NewAPI(apiCfg *storageosAPIConfig) error {
apiPass: defaultAPIPassword,
apiVersion: defaultAPIVersion,
}
klog.V(4).Infof("Using default StorageOS API settings: addr %s, version: %s", apiCfg.apiAddr, defaultAPIVersion)
klog.V(4).Infof("using default StorageOS API settings: addr %s, version: %s", apiCfg.apiAddr, defaultAPIVersion)
}
api, err := storageosapi.NewVersionedClient(apiCfg.apiAddr, defaultAPIVersion)
@ -103,6 +103,9 @@ func (u *storageosUtil) NewAPI(apiCfg *storageosAPIConfig) error {
// Creates a new StorageOS volume and makes it available as a device within
// /var/lib/storageos/volumes.
func (u *storageosUtil) CreateVolume(p *storageosProvisioner) (*storageosVolume, error) {
klog.V(4).Infof("creating StorageOS volume %q with namespace %q", p.volName, p.volNamespace)
if err := u.NewAPI(p.apiCfg); err != nil {
return nil, err
}
@ -145,6 +148,9 @@ func (u *storageosUtil) CreateVolume(p *storageosProvisioner) (*storageosVolume,
// or a file device. Block devices can be used directly, but file devices must
// be made accessible as a block device before using.
func (u *storageosUtil) AttachVolume(b *storageosMounter) (string, error) {
klog.V(4).Infof("attaching StorageOS volume %q with namespace %q", b.volName, b.volNamespace)
if err := u.NewAPI(b.apiCfg); err != nil {
return "", err
}
@ -161,19 +167,6 @@ func (u *storageosUtil) AttachVolume(b *storageosMounter) (string, error) {
return "", err
}
// Clear any existing mount reference from the API. These may be leftover
// from previous mounts where the unmount operation couldn't get access to
// the API credentials.
if vol.Mounted {
opts := storageostypes.VolumeUnmountOptions{
Name: vol.Name,
Namespace: vol.Namespace,
}
if err := u.api.VolumeUnmount(opts); err != nil {
klog.Warningf("Couldn't clear existing StorageOS mount reference: %v", err)
}
}
srcPath := filepath.Join(b.deviceDir, vol.ID)
dt, err := pathDeviceType(srcPath)
if err != nil {
@ -194,6 +187,9 @@ func (u *storageosUtil) AttachVolume(b *storageosMounter) (string, error) {
// Detach detaches a volume from the host. This is only needed when NBD is not
// enabled and loop devices are used to simulate a block device.
func (u *storageosUtil) DetachVolume(b *storageosUnmounter, devicePath string) error {
klog.V(4).Infof("detaching StorageOS volume %q with namespace %q", b.volName, b.volNamespace)
if !isLoopDevice(devicePath) {
return nil
}
@ -205,6 +201,9 @@ func (u *storageosUtil) DetachVolume(b *storageosUnmounter, devicePath string) e
// AttachDevice attaches the volume device to the host at a given mount path.
func (u *storageosUtil) AttachDevice(b *storageosMounter, deviceMountPath string) error {
klog.V(4).Infof("attaching StorageOS device for volume %q with namespace %q", b.volName, b.volNamespace)
if err := u.NewAPI(b.apiCfg); err != nil {
return err
}
@ -224,6 +223,9 @@ func (u *storageosUtil) AttachDevice(b *storageosMounter, deviceMountPath string
// Mount mounts the volume on the host.
func (u *storageosUtil) MountVolume(b *storageosMounter, mntDevice, deviceMountPath string) error {
klog.V(4).Infof("mounting StorageOS volume %q with namespace %q", b.volName, b.volNamespace)
notMnt, err := b.mounter.IsLikelyNotMountPoint(deviceMountPath)
if err != nil {
if os.IsNotExist(err) {
@ -256,10 +258,13 @@ func (u *storageosUtil) MountVolume(b *storageosMounter, mntDevice, deviceMountP
// Unmount removes the mount reference from the volume allowing it to be
// re-mounted elsewhere.
func (u *storageosUtil) UnmountVolume(b *storageosUnmounter) error {
klog.V(4).Infof("clearing StorageOS mount reference for volume %q with namespace %q", b.volName, b.volNamespace)
if err := u.NewAPI(b.apiCfg); err != nil {
// We can't always get the config we need, so allow the unmount to
// succeed even if we can't remove the mount reference from the API.
klog.V(4).Infof("Could not remove mount reference in the StorageOS API as no credentials available to the unmount operation")
klog.Warningf("could not remove mount reference in the StorageOS API as no credentials available to the unmount operation")
return nil
}