fix: check disk status before disk azure disk

This commit is contained in:
andyzhangx 2020-02-20 07:26:43 +00:00
parent 96dfa3f605
commit 44e6a506b9

View File

@ -214,7 +214,16 @@ func (c *ManagedDiskController) DeleteManagedDisk(diskURI string) error {
return fmt.Errorf("failed to delete disk(%s) since it's in attaching or detaching state", diskURI)
}
rerr := c.common.cloud.DisksClient.Delete(ctx, resourceGroup, diskName)
disk, rerr := c.common.cloud.DisksClient.Get(ctx, resourceGroup, diskName)
if rerr != nil {
return rerr.Error()
}
if disk.ManagedBy != nil {
return fmt.Errorf("disk(%s) already attached to node(%s), could not be deleted", diskURI, *disk.ManagedBy)
}
rerr = c.common.cloud.DisksClient.Delete(ctx, resourceGroup, diskName)
if rerr != nil {
return rerr.Error()
}