From 4152f38d5445f3d203e22cbab8cc187c31378d52 Mon Sep 17 00:00:00 2001 From: Qingqing Zheng Date: Fri, 13 Dec 2019 13:13:13 -0800 Subject: [PATCH] cache ttl is configurable --- .../legacy-cloud-providers/azure/azure.go | 16 +++++++++++ .../azure/azure_vmss_cache.go | 21 ++++++++++---- .../azure/azure_wrap.go | 28 +++++++++++++------ 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go index 3abb91eaf32..04ed230192a 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go @@ -174,6 +174,22 @@ 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"` + + // AvailabilitySetNodesCacheTTL sets the Cache TTL for availabilitySetNodesCache + // if not set, will use default value + AvailabilitySetNodesCacheTTL int `json:"availabilitySetNodesCacheTTL,omitempty" yaml:"availabilitySetNodesCacheTTL,omitempty"` + // VmssCacheTTL sets the cache TTL for VMSS + VmssCacheTTL int `json:"vmssCacheTTL,omitempty" yaml:"vmssCacheTTL,omitempty"` + // VmssVirtualMachinesCacheTTL sets the cache TTL for vmssVirtualMachines + VmssVirtualMachinesCacheTTL int `json:"vmssVirtualMachinesCacheTTL,omitempty" yaml:"vmssVirtualMachinesCacheTTL,omitempty"` + // VmCacheTTL sets the cache TTL for vm + VMCacheTTL int `json:"vmCacheTTL,omitempty" yaml:"vmCacheTTL,omitempty"` + // LbCacheTTL sets the cache TTL for load balancer + LbCacheTTL int `json:"lbCacheTTL,omitempty" yaml:"lbcacheTTL,omitempty"` + // NsgCacheTTL sets the cache TTL for network security group + NsgCacheTTL int `json:"nsgCacheTTL,omityempty" yaml:"nsgCacheTTL,omitempty"` + // RtCacheTTL sets the cache TTL for route table + RtCacheTTL int `json:"rtCacheTTL,omitempty" yaml:"rtCacheTTL,omitempty"` } var _ cloudprovider.Interface = (*Cloud)(nil) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_cache.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_cache.go index 51ff2ca3255..eedc9cda132 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_cache.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_cache.go @@ -38,9 +38,9 @@ var ( vmssVirtualMachinesKey = "k8svmssVirtualMachinesKey" availabilitySetNodesKey = "k8sAvailabilitySetNodesKey" - availabilitySetNodesCacheTTL = 15 * time.Minute - vmssTTL = 10 * time.Minute - vmssVirtualMachinesTTL = 10 * time.Minute + availabilitySetNodesCacheTTLDefault = 900 // in seconds + vmssCacheTTLDefault = 600 // in seconds + vmssVirtualMachinesCacheTTLDefault = 600 // in seconds ) type vmssVirtualMachinesEntry struct { @@ -87,7 +87,10 @@ func (ss *scaleSet) newVMSSCache() (*timedCache, error) { return localCache, nil } - return newTimedcache(vmssTTL, getter) + if ss.Config.VmssCacheTTL == 0 { + return newTimedcache(time.Duration(vmssCacheTTLDefault)*time.Second, getter) + } + return newTimedcache(time.Duration(ss.Config.VmssCacheTTL)*time.Second, getter) } func extractVmssVMName(name string) (string, string, error) { @@ -147,7 +150,10 @@ func (ss *scaleSet) newVMSSVirtualMachinesCache() (*timedCache, error) { return localCache, nil } - return newTimedcache(vmssVirtualMachinesTTL, getter) + if ss.Config.VmssVirtualMachinesCacheTTL == 0 { + return newTimedcache(time.Duration(vmssVirtualMachinesCacheTTLDefault)*time.Second, getter) + } + return newTimedcache(time.Duration(ss.Config.VmssVirtualMachinesCacheTTL)*time.Second, getter) } func (ss *scaleSet) deleteCacheForNode(nodeName string) error { @@ -186,7 +192,10 @@ func (ss *scaleSet) newAvailabilitySetNodesCache() (*timedCache, error) { return localCache, nil } - return newTimedcache(availabilitySetNodesCacheTTL, getter) + if ss.Config.AvailabilitySetNodesCacheTTL == 0 { + return newTimedcache(time.Duration(availabilitySetNodesCacheTTLDefault)*time.Second, getter) + } + return newTimedcache(time.Duration(ss.Config.AvailabilitySetNodesCacheTTL)*time.Second, getter) } func (ss *scaleSet) isNodeManagedByAvailabilitySet(nodeName string, crt cacheReadType) (bool, error) { diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_wrap.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_wrap.go index cc2851ae783..3c32d4912d3 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_wrap.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_wrap.go @@ -35,10 +35,10 @@ import ( ) var ( - vmCacheTTL = time.Minute - lbCacheTTL = 2 * time.Minute - nsgCacheTTL = 2 * time.Minute - rtCacheTTL = 2 * time.Minute + vmCacheTTLDefault = 60 // in seconds + lbCacheTTLDefault = 120 // in seconds + nsgCacheTTLDefault = 120 // in seconds + rtCacheTTLDefault = 120 // in seconds azureNodeProviderIDRE = regexp.MustCompile(`^azure:///subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Compute/(?:.*)`) azureResourceGroupNameRE = regexp.MustCompile(`.*/subscriptions/(?:.*)/resourceGroups/(.+)/providers/(?:.*)`) @@ -228,7 +228,10 @@ func (az *Cloud) newVMCache() (*timedCache, error) { return &vm, nil } - return newTimedcache(vmCacheTTL, getter) + if az.VMCacheTTL == 0 { + return newTimedcache(time.Duration(vmCacheTTLDefault)*time.Second, getter) + } + return newTimedcache(time.Duration(az.VMCacheTTL)*time.Second, getter) } func (az *Cloud) newLBCache() (*timedCache, error) { @@ -250,7 +253,10 @@ func (az *Cloud) newLBCache() (*timedCache, error) { return &lb, nil } - return newTimedcache(lbCacheTTL, getter) + if az.LbCacheTTL == 0 { + return newTimedcache(time.Duration(lbCacheTTLDefault)*time.Second, getter) + } + return newTimedcache(time.Duration(az.LbCacheTTL)*time.Second, getter) } func (az *Cloud) newNSGCache() (*timedCache, error) { @@ -271,7 +277,10 @@ func (az *Cloud) newNSGCache() (*timedCache, error) { return &nsg, nil } - return newTimedcache(nsgCacheTTL, getter) + if az.NsgCacheTTL == 0 { + return newTimedcache(time.Duration(nsgCacheTTLDefault)*time.Second, getter) + } + return newTimedcache(time.Duration(az.NsgCacheTTL)*time.Second, getter) } func (az *Cloud) newRouteTableCache() (*timedCache, error) { @@ -292,7 +301,10 @@ func (az *Cloud) newRouteTableCache() (*timedCache, error) { return &rt, nil } - return newTimedcache(rtCacheTTL, getter) + if az.RtCacheTTL == 0 { + return newTimedcache(time.Duration(rtCacheTTLDefault)*time.Second, getter) + } + return newTimedcache(time.Duration(az.RtCacheTTL)*time.Second, getter) } func (az *Cloud) useStandardLoadBalancer() bool {