From b2578c71203cdf0cf6973a31f45104e2723a0d5c Mon Sep 17 00:00:00 2001 From: Michael McCune Date: Mon, 18 Jul 2022 14:35:19 -0400 Subject: [PATCH] remove cache from clusterapi infra machine template --- .../clusterapi/clusterapi_controller.go | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller.go b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller.go index 9f5ff295ff91..52d4ecddc790 100644 --- a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller.go +++ b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller.go @@ -73,11 +73,6 @@ type infrastructureTemplateCacheEntry struct { template *unstructured.Unstructured } -// infrastructureTemplateCache holds infrastructure machine templates and -// their time to live values. It is used by the getInfrastructureResource -// function. -var infrastructureTemplateCache map[string]infrastructureTemplateCacheEntry = map[string]infrastructureTemplateCacheEntry{} - // machineController watches for Nodes, Machines, MachineSets and // MachineDeployments as they are added, updated and deleted on the // cluster. Additionally, it adds indices to the node informers to @@ -727,27 +722,7 @@ func (c *machineController) allowedByAutoDiscoverySpecs(r *unstructured.Unstruct } // Get an infrastructure machine template given its GVR, name, and namespace. -// This function exists so that we can implement a cache for the -// infrastructure template objects. A local cache is used in favor of the -// client-go informers because of the frequency of read requests combined -// with the fact that the infrastructure template will not be updated -// frequently (if at all). In practice, the autoscaler can make calls to -// the API server at a high frequency, which results in many calls being -// throttled on the client-side. To reduce the amount of throttling we keep -// an in-memory cache of infrastructure templates. The cache has a time to -// live on any entry of 1 minute. func (c *machineController) getInfrastructureResource(resource schema.GroupVersionResource, name string, namespace string) (*unstructured.Unstructured, error) { - // this cache key is only used internally, join the GVR+name+namespace - cachekey := strings.Join([]string{resource.String(), name, namespace}, "") - if entry, ok := infrastructureTemplateCache[cachekey]; ok { - // if the infrastructure template exists in the cache and is under the time to live, return it - if time.Now().Before(entry.timeToLive) { - return entry.template, nil - } - } - - // if the infrastructure template does not exist in the cache or is older - // than the time to live, we get a fresh record from the API server infra, err := c.managementClient. Resource(resource). Namespace(namespace). @@ -761,11 +736,5 @@ func (c *machineController) getInfrastructureResource(resource schema.GroupVersi return nil, err } - // update the cache with the new record - infrastructureTemplateCache[cachekey] = infrastructureTemplateCacheEntry{ - timeToLive: time.Now().Add(cacheEntryTimeToLive), - template: infra, - } - return infra, err }