🐛 Cache reader: Wait for cache sync when ReaderFailOnMissingInformer is true#3425
Conversation
cd58e14 to
81fb5ab
Compare
81f3497 to
2a68a6b
Compare
pkg/cache/informer_cache.go
Outdated
| if !ok { | ||
| return false, nil, &ErrResourceNotCached{GVK: gvk} | ||
| } | ||
| if !cache.Informer.HasSynced() { |
There was a problem hiding this comment.
This might still differ too much from the behavior in Informers.Get
Maybe ic.readerFailOnMissingInformer should be passed into Informers.Get and handled there to make it easier to keep both branches in sync.
@alvaroaleman WDYT?
There was a problem hiding this comment.
Yeah, we should use the same code to determine and do the syncing regardless of if readerFailOnMissingInformer is set or not, that it was added outside of that was basically the main mistake back then.
There was a problem hiding this comment.
Yeah, we should use the same code to determine and do the syncing regardless of if readerFailOnMissingInformer is set or not, that it was added outside of that was basically the main mistake back then.
Wouldn't that change the test that is with it?
Describe("as a Reader", func() {
Context("with structured objects", func() {
It("should not be able to list objects that haven't been watched previously", func(ctx SpecContext) {
By("listing all services in the cluster")
listObj := &corev1.ServiceList{}
Expect(errors.As(informerCache.List(ctx, listObj), &errNotCached)).To(BeTrue())
})I am trying to understand the behavior we want because if we don't care whether this is set or not:
- Should we fail if this is set?
- Should we add to the informerMap and then wait for sync, then fail?
There was a problem hiding this comment.
Assuming the above test is for a cache that has ReaderFailOnMissingInformer it needs to keep passing, yes. The only difference in Get between that option being set and not should be that we error out if the informer is not in the map already
There was a problem hiding this comment.
Gotcha, that's how I understood it after I re-read the issue and the setting. I am dealing with a context cancelled test failure at the moment, that I am hunting down.
2a68a6b to
651a146
Compare
651a146 to
7ae5df3
Compare
pkg/cache/internal/informers.go
Outdated
| i, started, ok := ip.Peek(gvk, obj) | ||
| if !ok { | ||
| if readerFailOnMissingInformer { | ||
| return false, nil, fmt.Errorf("failed to get informer for %v: informer not found", gvk) |
There was a problem hiding this comment.
This is wrong, this here needs to return ErrResourceNotCached. That in turn requires to move that to internal, something like this will do that without breaking the export:
+++ b/pkg/cache/informer_cache.go
@@ -51,16 +51,7 @@ var _ error = (*ErrCacheNotStarted)(nil)
// ErrResourceNotCached indicates that the resource type
// the client asked the cache for is not cached, i.e. the
// corresponding informer does not exist yet.
-type ErrResourceNotCached struct {
- GVK schema.GroupVersionKind
-}
-
-// Error returns the error
-func (r ErrResourceNotCached) Error() string {
- return fmt.Sprintf("%s is not cached", r.GVK.String())
-}
-
-var _ error = (*ErrResourceNotCached)(nil)
+type ErrResourceNotCached = internal.ErrResourceNotCached
pkg/cache/informer_cache.go
Outdated
| return started, cache, nil | ||
| started, cache, err := ic.Informers.Get(ctx, gvk, obj, ic.readerFailOnMissingInformer, &internal.GetOptions{}) | ||
| if err != nil { | ||
| return false, nil, &ErrResourceNotCached{GVK: gvk} |
There was a problem hiding this comment.
This here needs to just return the error and not overwrite it with ErrResourceNotCached, as there is a range of other errors that Informers.Get may return
7ae5df3 to
8ede9cf
Compare
| return i.Informer, nil | ||
| } | ||
|
|
||
| func (ic *informerCache) getInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, obj runtime.Object) (bool, *internal.Cache, error) { |
There was a problem hiding this comment.
Its not very obvious from the code but this is the only place where we need to pass ic.readerFailOnMissingInformer, in the two others we need to pass false.
This is because this here is only used by the cache reader whereas GetInformer and GetInformerForKind are methods on the cache. If those error out when readerFailOnMissingInformer is true, it becomes impossible to construct an informer at all
Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
8ede9cf to
8a2b6fe
Compare
|
@troy0820: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
LGTM label has been added. DetailsGit tree hash: 04a492b074bb478257b0a0557e2adc0ea2fbe882 |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, troy0820 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/cherrypick release-0.23 |
|
@alvaroaleman: once the present PR merges, I will cherry-pick it on top of DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@alvaroaleman: new pull request created: #3432 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@alvaroaleman: new pull request created: #3433 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Resolves #3424
/assign @alvaroaleman