mirror of https://github.com/k3s-io/k3s
Merge pull request #71495 from andyzhangx/detach-azuredisk-issue
fix detach azure disk issue due to dirty cachepull/564/head
commit
b75a34644e
|
@ -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
|
||||
}
|
||||
|
|
|
@ -71,8 +71,12 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
|
|||
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s)", nodeResourceGroup, nodeName, diskName)
|
||||
|
||||
// Invalidate the cache right after updating
|
||||
key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID))
|
||||
defer ss.vmssVMCache.Delete(key)
|
||||
|
||||
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s)", nodeResourceGroup, nodeName, diskName)
|
||||
_, err = ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm)
|
||||
if err != nil {
|
||||
detail := err.Error()
|
||||
|
@ -83,9 +87,6 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
|
|||
}
|
||||
} else {
|
||||
klog.V(2).Infof("azureDisk - attach disk(%s) succeeded", diskName)
|
||||
// Invalidate the cache right after updating
|
||||
key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID))
|
||||
ss.vmssVMCache.Delete(key)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -128,15 +129,17 @@ func (ss *scaleSet) DetachDiskByName(diskName, diskURI string, nodeName types.No
|
|||
vm.StorageProfile.DataDisks = &disks
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
|
||||
// Invalidate the cache right after updating
|
||||
key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID))
|
||||
defer ss.vmssVMCache.Delete(key)
|
||||
|
||||
klog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk(%s)", nodeResourceGroup, nodeName, diskName)
|
||||
_, err = ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm)
|
||||
if err != nil {
|
||||
klog.Errorf("azureDisk - detach disk(%s) from %s failed, err: %v", diskName, nodeName, err)
|
||||
} else {
|
||||
klog.V(2).Infof("azureDisk - detach disk(%s) succeeded", diskName)
|
||||
// Invalidate the cache right after updating
|
||||
key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID))
|
||||
ss.vmssVMCache.Delete(key)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue