fix detch azure disk issue by clean vm cache

This commit is contained in:
andyzhangx
2018-11-28 06:25:09 +00:00
parent 5dfe48b0ff
commit cd2930258c
2 changed files with 17 additions and 11 deletions

View File

@@ -77,6 +77,9 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
ctx, cancel := getContextWithCancel()
defer cancel()
// Invalidate the cache right after updating
defer as.cloud.vmCache.Delete(vmName)
_, err = as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM)
if err != nil {
klog.Errorf("azureDisk - attach disk(%s) failed, err: %v", diskName, err)
@@ -88,8 +91,6 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
}
} else {
klog.V(2).Infof("azureDisk - attach disk(%s) succeeded", diskName)
// Invalidate the cache right after updating
as.cloud.vmCache.Delete(vmName)
}
return err
}
@@ -139,13 +140,15 @@ func (as *availabilitySet) DetachDiskByName(diskName, diskURI string, nodeName t
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk(%s)", nodeResourceGroup, vmName, diskName)
ctx, cancel := getContextWithCancel()
defer cancel()
// Invalidate the cache right after updating
defer as.cloud.vmCache.Delete(vmName)
_, err = as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM)
if err != nil {
klog.Errorf("azureDisk - detach disk(%s) failed, err: %v", diskName, err)
} else {
klog.V(2).Infof("azureDisk - detach disk(%s) succeeded", diskName)
// Invalidate the cache right after updating
as.cloud.vmCache.Delete(vmName)
}
return err
}