Refactor the memcached discovery client #68865
Labels
kind/cleanup
Categorizes issue or PR as related to cleaning up code, process, or technical debt.
sig/api-machinery
Categorizes an issue or PR as relevant to SIG API Machinery.
When debugging #68735, I found the cached discovery clients confusing, which in turn makes the DeferredDiscoveryRESTMapper hard to understand. I'll try to summarize the confusion and propose a high-level fix.
We have two implementations of the CacheDiscoveryInterface, one mem-cached, and one disk-cached.
The behavior of the disk-cached discovery client is intuitive,
Invalidate()
method invalidates local caches, future requests results in server traffic.Fresh()
method returns true unless pre-existing on-disk cache is used.The behavior of the mem-cached one is not intuitive,
Invalidate()
function setsvalid=true
.Invalidate()
to populate the cache.Fresh()
method always returns true as long asInvalidate()
is called once.IIUC, mem-cached client is implemented in this way to avoid overloading the apiserver in case the caller keeps causing cache misses with invalid
groupVersion
. The disk-cached one is used by kubectl, which is intended for human users, so it doesn't have this concern.I plan to refactor the mem-cached client to:
Invalidate()
just sets the cache as "not-fresh"I will add a
Refresh()
method to the cached discovery client interface. The method will do the discovery, and marks the cache as fresh upon success.The current comment on the DeferredDiscoveryRESTMapper.Reset() claims the method marks the cached restmapper as invalid, but does not do discovery. However, if it's using the current memcached client as the underlying discovery client, the claim is false. I plan to give the
DeferredDiscoveryRESTMapper
anInvalidate
method and aRefresh
method, so user can choose whether the restmapper is lazily initialized./sig api-machinery
/assign
The text was updated successfully, but these errors were encountered: