Skip to content

Make ttl of discovery cache configurable and raise default #107130

@jonnylangefeld

Description

@jonnylangefeld

What would you like to be added?

The discovery cache for kubectl is defaulted to 10 minutes:

return diskcached.NewCachedDiscoveryClientForConfig(config, discoveryCacheDir, httpCacheDir, time.Duration(10*time.Minute))

That means that every 10 minutes of using kubectl against a cluster, it runs API requests against all group versions, which can take quite some time on clusters with many operators installed (like crossplane.io, GCP Config Connector, Azure Service Operator, etc.). I previously wrote this report that shows that every 10 minutes a simple kubectl get pods makes 170 API requests against a test cluster, vs 4 API requests when the cache exists. That results in significant productivity implications against such clusters. Here is a time comparison between a request that runs the discovery cache vs one that doesn't:

$ time kubectl get pods -n default
kubectl get pods -n default  0.50s user 1.19s system 11% cpu 14.174 total

$ time kubectl get --raw  "/api/v1/namespaces/default/pods"
kubectl get --raw "/api/v1/namespaces/default/pods"  0.06s user 0.03s system 23% cpu 0.398 total

The discovery cache doesn't really have to run every 10 minutes, as CRDs don't change that often. A lot of unnecessary load is created on clients and servers.

This issue is raised to change the discovery cache default to 24 hours and also to make the discovery cache ttl configurable.

Why is this needed?

Running the discovery cache every 10 minutes has a significant productivity impact on using kubectl on clusters with many CRDs as it is taking time to run these unnecessary requests.
The discovery cache doesn't really have to run every 10 minutes, as CRDs don't change that often. A lot of unnecessary load is created on clients and servers.

Metadata

Metadata

Assignees

Labels

kind/featureCategorizes issue or PR as related to a new feature.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.sig/cliCategorizes an issue or PR as relevant to SIG CLI.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions