fix: azure disk detach failure if node not exists

fix comments
This commit is contained in:
andyzhangx 2019-09-12 14:05:50 +00:00
parent 06609b77e8
commit d11cac9ada
2 changed files with 14 additions and 8 deletions

View File

@ -150,17 +150,23 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
// DetachDisk detaches a disk from host. The vhd can be identified by diskName or diskURI.
func (c *controllerCommon) DetachDisk(diskName, diskURI string, nodeName types.NodeName) error {
instanceid, err := c.cloud.InstanceID(context.TODO(), nodeName)
if err != nil {
if err == cloudprovider.InstanceNotFound {
// if host doesn't exist, no need to detach
klog.Warningf("azureDisk - failed to get azure instance id(%q), DetachDisk(%s) will assume disk is already detached",
nodeName, diskURI)
return nil
}
klog.Warningf("failed to get azure instance id (%v)", err)
return fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err)
}
vmset, err := c.getNodeVMSet(nodeName)
if err != nil {
return err
}
instanceid, err := c.cloud.InstanceID(context.TODO(), nodeName)
if err != nil {
klog.Warningf("failed to get azure instance id (%v)", err)
return fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err)
}
klog.V(2).Infof("detach %v from node %q", diskURI, nodeName)
// make the lock here as small as possible

View File

@ -88,9 +88,9 @@ func TestCommonDetachDisk(t *testing.T) {
expectedErr bool
}{
{
desc: "an error shall be returned if there's no such instance corresponding to given nodeName",
desc: "error should not be returned if there's no such instance corresponding to given nodeName",
nodeName: "vm1",
expectedErr: true,
expectedErr: false,
},
{
desc: "no error shall be returned if there's no matching disk according to given diskName",