Skip to content

Commit e6ee924

Browse files
authored
Merge pull request kubernetes#93316 from feiskyer/fix-93287-2
Fix instance not found issues when an Azure Node is recreated in a short time
2 parents 2fbe301 + 3588856 commit e6ee924

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ func (ss *scaleSet) getVmssVMByInstanceID(resourceGroup, scaleSetName, instanceI
283283
if found && vm != nil {
284284
return vm, nil
285285
}
286+
if found && vm == nil {
287+
klog.V(2).Infof("Couldn't find VMSS VM with scaleSetName %q and instanceID %q, refreshing the cache if it is expired", scaleSetName, instanceID)
288+
vm, found, err = getter(azcache.CacheReadTypeDefault)
289+
if err != nil {
290+
return nil, err
291+
}
292+
}
286293
if !found || vm == nil {
287294
return nil, cloudprovider.InstanceNotFound
288295
}

staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_cache.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ func (ss *scaleSet) gcVMSSVMCache() error {
154154

155155
// newVMSSVirtualMachinesCache instanciates a new VMs cache for VMs belonging to the provided VMSS.
156156
func (ss *scaleSet) newVMSSVirtualMachinesCache(resourceGroupName, vmssName, cacheKey string) (*azcache.TimedCache, error) {
157+
if ss.Config.VmssVirtualMachinesCacheTTLInSeconds == 0 {
158+
ss.Config.VmssVirtualMachinesCacheTTLInSeconds = vmssVirtualMachinesCacheTTLDefaultInSeconds
159+
}
160+
vmssVirtualMachinesCacheTTL := time.Duration(ss.Config.VmssVirtualMachinesCacheTTLInSeconds) * time.Second
161+
157162
getter := func(key string) (interface{}, error) {
158163
localCache := &sync.Map{} // [nodeName]*vmssVirtualMachinesEntry
159164

@@ -212,9 +217,9 @@ func (ss *scaleSet) newVMSSVirtualMachinesCache(resourceGroupName, vmssName, cac
212217
// add old missing cache data with nil entries to prevent aggressive
213218
// ARM calls during cache invalidation
214219
for name, vmEntry := range oldCache {
215-
// if the nil cache entry has existed for 15 minutes in the cache
220+
// if the nil cache entry has existed for vmssVirtualMachinesCacheTTL in the cache
216221
// then it should not be added back to the cache
217-
if vmEntry.virtualMachine == nil && time.Since(vmEntry.lastUpdate) > 15*time.Minute {
222+
if vmEntry.virtualMachine == nil && time.Since(vmEntry.lastUpdate) > vmssVirtualMachinesCacheTTL {
218223
klog.V(5).Infof("ignoring expired entries from old cache for %s", name)
219224
continue
220225
}
@@ -238,10 +243,7 @@ func (ss *scaleSet) newVMSSVirtualMachinesCache(resourceGroupName, vmssName, cac
238243
return localCache, nil
239244
}
240245

241-
if ss.Config.VmssVirtualMachinesCacheTTLInSeconds == 0 {
242-
ss.Config.VmssVirtualMachinesCacheTTLInSeconds = vmssVirtualMachinesCacheTTLDefaultInSeconds
243-
}
244-
return azcache.NewTimedcache(time.Duration(ss.Config.VmssVirtualMachinesCacheTTLInSeconds)*time.Second, getter)
246+
return azcache.NewTimedcache(vmssVirtualMachinesCacheTTL, getter)
245247
}
246248

247249
func (ss *scaleSet) deleteCacheForNode(nodeName string) error {

0 commit comments

Comments
 (0)