From 48db05166a92414358757727b56d1f854d940e54 Mon Sep 17 00:00:00 2001 From: FengyunPan Date: Mon, 7 Aug 2017 17:11:40 +0800 Subject: [PATCH] Ignore the available volume when calling DetachDisk If use detachs the volume by nova in openstack env, volume becomes available. If nova instance is been deleted, nova will detach it automatically. So the "available" is fine since that means the volume is detached from instance already. --- .../providers/openstack/openstack_volumes.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/cloudprovider/providers/openstack/openstack_volumes.go b/pkg/cloudprovider/providers/openstack/openstack_volumes.go index 7f7b499bb77..a5479a4f4b6 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_volumes.go +++ b/pkg/cloudprovider/providers/openstack/openstack_volumes.go @@ -215,11 +215,7 @@ func (os *OpenStack) AttachDisk(instanceID, volumeID string) (string, error) { if err != nil { return "", err } - if volume.Status != VolumeAvailableStatus { - errmsg := fmt.Sprintf("volume %s status is %s, not %s, can not be attached to instance %s.", volume.Name, volume.Status, VolumeAvailableStatus, instanceID) - glog.Errorf(errmsg) - return "", errors.New(errmsg) - } + cClient, err := os.NewComputeV2() if err != nil { return "", err @@ -258,6 +254,12 @@ func (os *OpenStack) DetachDisk(instanceID, volumeID string) error { if err != nil { return err } + if volume.Status == VolumeAvailableStatus { + // "available" is fine since that means the volume is detached from instance already. + glog.V(2).Infof("volume: %s has been detached from compute: %s ", volume.ID, instanceID) + return nil + } + if volume.Status != VolumeInUseStatus { errmsg := fmt.Sprintf("can not detach volume %s, its status is %s.", volume.Name, volume.Status) glog.Errorf(errmsg)