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 #93316: Fix instance not found issues when an Azure Node is recreated #93461

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
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