Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #71495: fix detch azure disk issue by clean vm cache #71496

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions pkg/cloudprovider/providers/azure/azure_controller_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
},
}
vmName := mapNodeNameToVMName(nodeName)

// Invalidate the cache right after updating
defer as.cloud.vmCache.Delete(vmName)

glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s)", as.resourceGroup, vmName, diskName)
respChan, errChan := as.VirtualMachinesClient.CreateOrUpdate(as.resourceGroup, vmName, newVM, nil)
<-respChan
Expand All @@ -83,8 +87,6 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
}
} else {
glog.V(2).Infof("azureDisk - attach disk(%s) succeeded", diskName)
// Invalidate the cache right after updating
as.cloud.vmCache.Delete(vmName)
}
return err
}
Expand Down Expand Up @@ -126,6 +128,10 @@ func (as *availabilitySet) DetachDiskByName(diskName, diskURI string, nodeName t
},
}
vmName := mapNodeNameToVMName(nodeName)

// Invalidate the cache right after updating
defer as.cloud.vmCache.Delete(vmName)

glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk(%s)", as.resourceGroup, vmName, diskName)
respChan, errChan := as.VirtualMachinesClient.CreateOrUpdate(as.resourceGroup, vmName, newVM, nil)
<-respChan
Expand All @@ -134,8 +140,6 @@ func (as *availabilitySet) DetachDiskByName(diskName, diskURI string, nodeName t
glog.Errorf("azureDisk - detach disk(%s) failed, err: %v", diskName, err)
} else {
glog.V(2).Infof("azureDisk - detach disk(%s) succeeded", diskName)
// Invalidate the cache right after updating
as.cloud.vmCache.Delete(vmName)
}
return err
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/cloudprovider/providers/azure/azure_controller_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod

ctx, cancel := getContextWithCancel()
defer cancel()

// Invalidate the cache right after updating
defer ss.vmssVMCache.Delete(ss.makeVmssVMName(ssName, instanceID))

glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s)", ss.resourceGroup, nodeName, diskName)
_, err = ss.VirtualMachineScaleSetVMsClient.Update(ctx, ss.resourceGroup, ssName, instanceID, vm)
if err != nil {
Expand All @@ -75,8 +79,6 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
}
} else {
glog.V(2).Infof("azureDisk - attach disk(%s) succeeded", diskName)
// Invalidate the cache right after updating
ss.vmssVMCache.Delete(ss.makeVmssVMName(ssName, instanceID))
}
return err
}
Expand Down Expand Up @@ -110,14 +112,16 @@ 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
defer ss.vmssVMCache.Delete(ss.makeVmssVMName(ssName, instanceID))

glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk(%s)", ss.resourceGroup, nodeName, diskName)
_, err = ss.VirtualMachineScaleSetVMsClient.Update(ctx, ss.resourceGroup, ssName, instanceID, vm)
if err != nil {
glog.Errorf("azureDisk - detach disk(%s) from %s failed, err: %v", diskName, nodeName, err)
} else {
glog.V(2).Infof("azureDisk - detach disk(%s) succeeded", diskName)
// Invalidate the cache right after updating
ss.vmssVMCache.Delete(ss.makeVmssVMName(ssName, instanceID))
}

return err
Expand Down