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

Invalidate API resources cache #256

Open
jacobtomlinson opened this issue Dec 15, 2023 · 4 comments
Open

Invalidate API resources cache #256

jacobtomlinson opened this issue Dec 15, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Dec 15, 2023

In #254 I added a cache for API resources to mimic the behaviour of kubectl. However it looks like kubectl invalidates the cache if you request a resource not contained in the cache and tries again.

Reproducible steps:

  • Call kr8s.get("po") # Populates the cache and lists pods
  • Create a new CRD with the short name foo and a kr8s class for it
  • Call kr8s.get("foo") # Will not find it because "foo" is not in the cache

When we fail to look up foo we need to invalidate the cache and try again.

@jacobtomlinson jacobtomlinson added the bug Something isn't working label Dec 15, 2023
@benedikt-bartscher
Copy link
Contributor

benedikt-bartscher commented Dec 16, 2023

I noticed this kubectl behaviour aswell. If i apply a new CRD kubectls auto-completion only works after some minutes or if i interact with those crds for example with kubectl get. Maybe we also want to invalidate the cache if kr8s executes any of the CRUD actions on crds itself.

Edit: iirc kubectl does not do this. If you create a new CRD with kubectl, the cache does not get invalidated. Its your choice if kr8s should be a little "smarter" or tied to the kubectl design.

@jacobtomlinson
Copy link
Member Author

Oh interesting, when I was poking around the kubectl source I felt like it was retrying if the resource name was not found in the cache, but maybe not!

@marceloFA
Copy link
Contributor

Can I work with this one? If yes, here's a question about this issue:

| When we fail to look up foo we need to invalidate the cache and try again.

Is there any way to differentiate a look-up failure due to a new CRD instead of a resource that actually does not exist? I think the latter is what happens the most and it would be a bit of time and network resource waste to look-up again something that actually does not exist

@jacobtomlinson
Copy link
Member Author

Sure that would be great.

The way the Go client implements this is to have a function that looks up a resource. Then within that function, it first tries to look that up in the cache only, if it isn't found then it invalidates the cache and tries again.

We might want to go down the same road of encapsulating the lookup logic into a single function where we can control the cache more directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants