Skip to content

Commit

Permalink
Merge pull request #3301 from nilo19/fix/cherry-pick-2950-1.25
Browse files Browse the repository at this point in the history
fix: remove vmss vm from cache when invalidate the cache
  • Loading branch information
k8s-ci-robot committed Feb 9, 2023
2 parents cc97e00 + 2faf61e commit 1ee32bb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/provider/azure_vmss_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,27 @@ func (ss *ScaleSet) getVMSSVMCache(resourceGroup, vmssName string) (string, *azc

// gcVMSSVMCache delete stale VMSS VMs caches from deleted VMSSes.
func (ss *ScaleSet) gcVMSSVMCache() error {
return ss.vmssCache.Delete(consts.VMSSKey)
cached, err := ss.vmssCache.Get(consts.VMSSKey, azcache.CacheReadTypeUnsafe)
if err != nil {
return err
}

vmsses := cached.(*sync.Map)
removed := map[string]bool{}
ss.vmssVMCache.Range(func(key, value interface{}) bool {
cacheKey := key.(string)
vlistIdx := cacheKey[strings.LastIndex(cacheKey, "/")+1:]
if _, ok := vmsses.Load(vlistIdx); !ok {
removed[cacheKey] = true
}
return true
})

for key := range removed {
ss.vmssVMCache.Delete(key)
}

return nil
}

// newVMSSVirtualMachinesCache instantiates a new VMs cache for VMs belonging to the provided VMSS.
Expand Down

0 comments on commit 1ee32bb

Please sign in to comment.