-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
✨: pkg/cache: add options for cache miss policy #2406
✨: pkg/cache: add options for cache miss policy #2406
Conversation
e989142
to
dfadcb1
Compare
dfadcb1
to
730843a
Compare
9cf53b5
to
a993837
Compare
Seeing two failures in test that must be unrelated, kind of confused. Would appreciate knowing if these are known flakes? |
/retest |
5c064f3
to
a4f7424
Compare
Am I reading correctly that the default policy in If so, a few questions:
If we're changing the default to Fail, we should update the PR emoji to ⚠ to reflect that this is a breaking change. |
This is confusing: The setting in the client is for when the cache tells it that it doesn't have this resource and won't set up an informer. If that client setting is not fail, then it will read from the api directly instead of the cache. The overall default behavior should be unchanged. Do you think there is a way we could better clarify the above? |
@joelanford this PR adds configuration to both the client and the cache. Regardless of what you configure the cache to do, the client acts independently. We're not "defining the default in two places" since we're configuring two different bits entirely. The matrix looks like:
The states are:
My intent here is to allow using option 3 and |
@stevekuznetsov Thanks. I see the difference now. Another follow-up: It looks like the behavior of On the other hand, it doesn't look like Thoughts? |
Oh and a second question. In the case that |
Good catch. I can update those and add to the docs for
I'm open to suggestions here. |
In which case the configuration would be ignored? Maybe it's a matter of documentation, but |
@vincepri I understood @joelanford to mean that if you configure |
🤔 Yeah that needs to be fixed probably, the client's cache configuration portion should inform the internal cache and those option need to be related to each other. |
@vincepri is that a hard requirement? I don't really see this being that much of a UX problem to be honest and I don't know that the amount of work it might take to reconfigure these options into a hierarchy whereby the client can peer into the cache or vice versa would be worth it. The older configuration options that take a constructor closure are opaque, as well, so there's no trivial way to ensure folks using those (eg |
3845a5c
to
d0a389c
Compare
@joelanford updated the client options to affect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny comments, but LGTM
pkg/cache/cache.go
Outdated
// errors.NotFound. | ||
// | ||
// Defaults to false, which means that the cache will start a new informer | ||
// for every new requested resource. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth it to note that by default this creates a cluster-wide cache to help folks understand why they might choose to set it to true
if they don't have the background we do
In general lgtm from my side +/- the open nits and squash before merge (my nit is not a blocker) |
/retitle ✨: pkg/cache: add options for cache miss policy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small comment, other than that LGTM
pkg/cache/errors/errors.go
Outdated
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
// ErrResourceNotCached indicates that the resource type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I told you something else over Slack, but I realized there is another case of a cache error which is not in a subpackage:
type ErrCacheNotStarted struct{} |
Lets maybe move this into the cache package, too?
@vincepri did we want to rebase this? |
I think apart from a rebase and the nit above we're ready to merge |
Hey folks, |
db45ca3
to
b50077c
Compare
82691f3
to
8beaa5c
Compare
@alvaroaleman @vincepri Rebased, should be ready now |
pkg/cache/cache.go
Outdated
// | ||
// Defaults to false, which means that the cache will start a new informer | ||
// for every new requested resource. | ||
FailOnUnknownResource bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, it's not directly clear what an UnknownResource
is.
Could we maybe rename this to FailReadWithoutRegisteredInformer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe ReaderFailOnMissingInformer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Will update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the GoDoc here clear it up sufficiently? We've gone back and forth on the names here a couple of times and I'm not sure we will find something perfect. If the doc makes it sufficiently clear I think it's probably a good stopping place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(disregard, thanks @sbueringer )
This commit allows users to opt out of the "start informers in the background" behavior that the current cache implementation uses. Additionally, when opting out of this behavior, the client can be configured to do a live lookup on a cache miss. The default behaviors are: pkg/cache: backfill data on a miss (today's default, unchanged) pkg/client: live lookup when cache is configured to miss Signed-off-by: Steve Kuznetsov <[email protected]>
8beaa5c
to
fba58bc
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, stevekuznetsov The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This commit allows users to opt out of the "start informers in the background" behavior that the current cache implementation uses. Additionally, when opting out of this behavior, the client can be configured to do a live lookup on a cache miss. The default behaviors are:
pkg/cache: backfill data on a miss (today's default, unchanged)
pkg/client: live lookup when cache is configured to miss
Fixes #2397