Skip to content

Commit

Permalink
remove cache from clusterapi infra machine template
Browse files Browse the repository at this point in the history
  • Loading branch information
elmiko committed Jul 18, 2022
1 parent e3b37b0 commit b2578c7
Showing 1 changed file with 0 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand All @@ -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
}

0 comments on commit b2578c7

Please sign in to comment.