Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: When a node is deleted and then recreated in short time, the "instance not found" error would be reported from Azure cloud provider and hence the node object is deleted by kube-controller-manager. It is because the deleted VMSS VM would be cached for 15 minutes (this is used to avoid throttling issues when a large number of nodes are deleted): The cache above is too long and should be reduced to a shorter value, e.g. 3 minutes. What you expected to happen: The newly created Node should not be deleted. How to reproduce it (as minimally and precisely as possible): Anything else we need to know?: Environment: Kubernetes version (use ): Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others: /kind bug /priority critical-urgent /area provider/azure /sig cloud-provider
is anyone already working on this?
is working on a fix for this. Would you like to have a look?
will do
Thank you for working on this, and /assign

Discussion:
if found && vm != nil { return vm, nil } <ins> if found && vm == nil { klog.V(2).Infof("Couldn't find VMSS VM with scaleSetName %q and instanceID %q, refreshing the cache if it is expired", scaleSetName, instanceID) vm, found, err = getter(azcache.CacheReadTypeDefault) if err != nil { return nil, err } } </ins> if !found || vm == nil { return nil, cloudprovider.InstanceNotFound }

// newVMSSVirtualMachinesCache instanciates a new VMs cache for VMs belonging to the provided VMSS. func (ss *scaleSet) newVMSSVirtualMachinesCache(resourceGroupName, vmssName, cacheKey string) (*azcache.TimedCache, error) { <ins> if ss.Config.VmssVirtualMachinesCacheTTLInSeconds == 0 { ss.Config.VmssVirtualMachinesCacheTTLInSeconds = vmssVirtualMachinesCacheTTLDefaultInSeconds } vmssVirtualMachinesCacheTTL := time.Duration(ss.Config.VmssVirtualMachinesCacheTTLInSeconds) * time.Second </ins> getter := func(key string) (interface{}, error) { localCache := &sync.Map{} // [nodeName]*vmssVirtualMachinesEntry

// add old missing cache data with nil entries to prevent aggressive // ARM calls during cache invalidation for name, vmEntry := range oldCache { <del> // if the nil cache entry has existed for 15 minutes in the cache </del> <ins> // if the nil cache entry has existed for vmssVirtualMachinesCacheTTL in the cache </ins> // then it should not be added back to the cache <del> if vmEntry.virtualMachine == nil && time.Since(vmEntry.lastUpdate) > 15*time.Minute { </del> <ins> if vmEntry.virtualMachine == nil && time.Since(vmEntry.lastUpdate) > vmssVirtualMachinesCacheTTL { </ins> klog.V(5).Infof("ignoring expired entries from old cache for %s", name) continue }

return localCache, nil } <del> if ss.Config.VmssVirtualMachinesCacheTTLInSeconds == 0 { ss.Config.VmssVirtualMachinesCacheTTLInSeconds = vmssVirtualMachinesCacheTTLDefaultInSeconds } return azcache.NewTimedcache(time.Duration(ss.Config.VmssVirtualMachinesCacheTTLInSeconds)*time.Second, getter) </del> <ins> return azcache.NewTimedcache(vmssVirtualMachinesCacheTTL, getter) </ins> } func (ss *scaleSet) deleteCacheForNode(nodeName string) error {