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

Commit 5d09d31

Browse files
author
FengyunPan
committed
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.
1 parent fc99c7a commit 5d09d31

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

pkg/cloudprovider/providers/openstack/openstack_volumes.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,7 @@ func (os *OpenStack) AttachDisk(instanceID, volumeID string) (string, error) {
215215
if err != nil {
216216
return "", err
217217
}
218-
if volume.Status != VolumeAvailableStatus {
219-
errmsg := fmt.Sprintf("volume %s status is %s, not %s, can not be attached to instance %s.", volume.Name, volume.Status, VolumeAvailableStatus, instanceID)
220-
glog.Errorf(errmsg)
221-
return "", errors.New(errmsg)
222-
}
218+
223219
cClient, err := os.NewComputeV2()
224220
if err != nil {
225221
return "", err
@@ -258,6 +254,12 @@ func (os *OpenStack) DetachDisk(instanceID, volumeID string) error {
258254
if err != nil {
259255
return err
260256
}
257+
if volume.Status == VolumeAvailableStatus {
258+
// "available" is fine since that means the volume is detached from instance already.
259+
glog.V(2).Infof("volume: %s has been detached from compute: %s ", volume.ID, instanceID)
260+
return nil
261+
}
262+
261263
if volume.Status != VolumeInUseStatus {
262264
errmsg := fmt.Sprintf("can not detach volume %s, its status is %s.", volume.Name, volume.Status)
263265
glog.Errorf(errmsg)

0 commit comments

Comments
 (0)