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

Support discovery cache in local ~/.kube/cache/discovery directory like kubectl #1021

Open
imuxin opened this issue Sep 22, 2022 · 6 comments
Labels
api Api abstraction related help wanted Not immediately prioritised, please help!

Comments

@imuxin
Copy link
Contributor

imuxin commented Sep 22, 2022

Would you like to work on this feature?

No response

What problem are you trying to solve?

Since the API resources are not changing frequently, we do not need to discover the resource which has been found in the previous API query.

Describe the solution you'd like

Cache the discovery in ~/.kube/cache/discovery like what kubectl does.

Describe alternatives you've considered

No alternatives

Documentation, Adoption, Migration Strategy

No response

Target crate for feature

kube-client

@nightkr nightkr added the api Api abstraction related label Sep 22, 2022
@clux
Copy link
Member

clux commented Sep 22, 2022

Yeah, I think this makes sense. It's probably not something we should have on by default (since we are more a client-go equivalent than a kubectl equivalent), but we can pass in a cache location like ~/.kube/cache/discovery/{context} to Discovery and re-use from there.

Some questions;

  • Should we try to re-use kubectl's format? It seems like A LOT of files that are never garbage collected. We could just do one file per context.
  • How do we determine whether a cache is out of date?

@clux clux added the help wanted Not immediately prioritised, please help! label Sep 22, 2022
@imuxin
Copy link
Contributor Author

imuxin commented Sep 22, 2022

It's probably not something we should have on by default (since we are more a client-go equivalent than a kubectl equivalent), but we can pass in a cache location like ~/.kube/cache/discovery/{context} to Discovery and re-use from there.

I agree.

Indeed, there are many unclear points, and we need more time to figure out.

@imuxin
Copy link
Contributor Author

imuxin commented Sep 23, 2022

I see that kubectl uses discovery_client which is provided by client-go to own ability to cache api resources. And discovery client exposes Invalidate method to enforce no cached data and the next request will refresh the cache. Maybe we can set a timeout for cache refresh, FYI.

more details:
discovery package
func (d *CachedDiscoveryClient) Invalidate()

@clux
Copy link
Member

clux commented Sep 23, 2022

Can also see that this is wrapped up in a CachedDiscoveryClient which sets at ttl of 6 hours (other blog posts mentioned invalidation every 10 minutes, but it seems to be updated when going to master).

A long timeout makes sense for this type of cache, but if a controller is mutating apis it can also make sense to expose the invalidate call.

@imuxin
Copy link
Contributor Author

imuxin commented Sep 23, 2022

Yeah, it looks like an available solution. But still have many details not reach a consensus, like cache file format. I am going to implement it first and make a pr. By that time, let's explore further.

@liangyuanpeng
Copy link

Should we try to re-use kubectl's format?

Keep the same format for Interoperability would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Api abstraction related help wanted Not immediately prioritised, please help!
Projects
None yet
Development

No branches or pull requests

4 participants