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 #85158: fix vmss dirty cache issue #85177

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
Expand Up @@ -84,9 +84,7 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
defer cancel()

// Invalidate the cache right after updating
if err = ss.deleteCacheForNode(vmName); err != nil {
return err
}
defer ss.deleteCacheForNode(vmName)

klog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s, %s)", nodeResourceGroup, nodeName, diskName, diskURI)
_, err = ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, newVM, "attach_disk")
Expand Down Expand Up @@ -156,9 +154,7 @@ func (ss *scaleSet) DetachDisk(diskName, diskURI string, nodeName types.NodeName
defer cancel()

// Invalidate the cache right after updating
if err = ss.deleteCacheForNode(vmName); err != nil {
return nil, err
}
defer ss.deleteCacheForNode(vmName)

klog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk(%s, %s)", nodeResourceGroup, nodeName, diskName, diskURI)
return ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, newVM, "detach_disk")
Expand Down
12 changes: 4 additions & 8 deletions staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go
Expand Up @@ -778,10 +778,8 @@ func (ss *scaleSet) EnsureHostInPool(service *v1.Service, nodeName types.NodeNam
return err
}

// Invalidate the cache since we would update it.
if err = ss.deleteCacheForNode(vmName); err != nil {
return err
}
// Invalidate the cache since right after update
defer ss.deleteCacheForNode(vmName)

// Update vmssVM with backoff.
ctx, cancel := getContextWithCancel()
Expand Down Expand Up @@ -1053,10 +1051,8 @@ func (ss *scaleSet) ensureBackendPoolDeletedFromNode(service *v1.Service, nodeNa
return err
}

// Invalidate the cache since we would update it.
if err = ss.deleteCacheForNode(nodeName); err != nil {
return err
}
// Invalidate the cache since right after update
defer ss.deleteCacheForNode(nodeName)

// Update vmssVM with backoff.
ctx, cancel := getContextWithCancel()
Expand Down
Expand Up @@ -115,6 +115,7 @@ func (ss *scaleSet) newVMSSVirtualMachinesCache() (*timedCache, error) {
func (ss *scaleSet) deleteCacheForNode(nodeName string) error {
cached, err := ss.vmssVMCache.Get(vmssVirtualMachinesKey, cacheReadTypeUnsafe)
if err != nil {
klog.Errorf("deleteCacheForNode(%s) failed with error: %v", nodeName, err)
return err
}

Expand Down