Skip to content

Commit

Permalink
Merge pull request #93461 from nilo19/automated-cherry-pick-of-#93316…
Browse files Browse the repository at this point in the history
…-upstream-release-1.17

Automated cherry pick of #93316: Fix instance not found issues when an Azure Node is recreated
  • Loading branch information
k8s-ci-robot committed Aug 2, 2020
2 parents 55afe5a + d728ed1 commit 7d89b9a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions staging/src/k8s.io/legacy-cloud-providers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ type Config struct {
// LoadBalancerResourceGroup determines the specific resource group of the load balancer user want to use, working
// with LoadBalancerName
LoadBalancerResourceGroup string `json:"loadBalancerResourceGroup,omitempty" yaml:"loadBalancerResourceGroup,omitempty"`

// VmssVirtualMachinesCacheTTLInSeconds sets the cache TTL for vmssVirtualMachines
VmssVirtualMachinesCacheTTLInSeconds int `json:"vmssVirtualMachinesCacheTTLInSeconds,omitempty" yaml:"vmssVirtualMachinesCacheTTLInSeconds,omitempty"`
}

var _ cloudprovider.Interface = (*Cloud)(nil)
Expand Down
7 changes: 7 additions & 0 deletions staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ func (ss *scaleSet) getVmssVMByInstanceID(resourceGroup, scaleSetName, instanceI
if found && vm != nil {
return vm, nil
}
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(cacheReadTypeDefault)
if err != nil {
return nil, err
}
}
if !found || vm == nil {
return nil, cloudprovider.InstanceNotFound
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ var (
availabilitySetNodesCacheTTL = 15 * time.Minute
vmssTTL = 10 * time.Minute
vmssVirtualMachinesTTL = 10 * time.Minute

vmssVirtualMachinesCacheTTLDefaultInSeconds = 600
)

type vmssVirtualMachinesEntry struct {
Expand Down Expand Up @@ -107,6 +109,11 @@ func extractVmssVMName(name string) (string, string, error) {
}

func (ss *scaleSet) newVMSSVirtualMachinesCache() (*timedCache, error) {
if ss.Config.VmssVirtualMachinesCacheTTLInSeconds == 0 {
ss.Config.VmssVirtualMachinesCacheTTLInSeconds = vmssVirtualMachinesCacheTTLDefaultInSeconds
}
vmssVirtualMachinesCacheTTL := time.Duration(ss.Config.VmssVirtualMachinesCacheTTLInSeconds) * time.Second

getter := func(key string) (interface{}, error) {
localCache := &sync.Map{} // [nodeName]*vmssVirtualMachinesEntry

Expand Down Expand Up @@ -172,9 +179,9 @@ func (ss *scaleSet) newVMSSVirtualMachinesCache() (*timedCache, error) {
// add old missing cache data with nil entries to prevent aggressive
// ARM calls during cache invalidation
for name, vmEntry := range oldCache {
// if the nil cache entry has existed for 15 minutes in the cache
// if the nil cache entry has existed for vmssVirtualMachinesCacheTTL in the cache
// then it should not be added back to the cache
if vmEntry.virtualMachine == nil || time.Since(vmEntry.lastUpdate) > 15*time.Minute {
if vmEntry.virtualMachine == nil || time.Since(vmEntry.lastUpdate) > vmssVirtualMachinesCacheTTL {
klog.V(5).Infof("ignoring expired entries from old cache for %s", name)
continue
}
Expand Down

0 comments on commit 7d89b9a

Please sign in to comment.