-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
✨ Take context when getting informer. #663
Conversation
Hi @djzager. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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/test-infra repository. |
Welcome @djzager! |
a188379
to
bd510e1
Compare
/assign @DirectXMan12 |
pkg/cache/internal/informers_map.go
Outdated
@@ -162,9 +164,22 @@ func (ip *specificInformersMap) Get(gvk schema.GroupVersionKind, obj runtime.Obj | |||
} | |||
|
|||
if started && !i.Informer.HasSynced() { | |||
syncReturn := make(chan 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.
make this buffered so that we don't leak the goroutine when we time out
syncReturn := make(chan bool) | |
syncReturn := make(chan bool, 1 /* don't leak goroutines on timeout */) |
pkg/cache/internal/informers_map.go
Outdated
select { | ||
case <-ctx.Done(): | ||
//end the polling for cache to sync | ||
done <- struct{}{} |
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 <- struct{}{} | |
close(done) |
🏃 build k8s 1.13.5 bundle
hey, are you still interested in working on this? |
Yes I am. Apologies for letting this fall off my radar. Will take today to catch up on the comments and start adding the test. |
593a2d4
to
22b906a
Compare
bf2f190
to
eeb187c
Compare
/ok-to-test |
6fa0ae5
to
5c3a188
Compare
5c3a188
to
dd1d52a
Compare
/retest |
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.
/lgtm
/assign @DirectXMan12
dd1d52a
to
9887317
Compare
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.
/lgtm
/assign @DirectXMan12 @gerred |
pkg/cache/cache_test.go
Outdated
|
||
By("verifying that an error is returned") | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(Equal(fmt.Sprintf("Timeout: failed waiting for %T Informer to sync", &kcorev1.Pod{}))) |
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.
In case this comes up in posterity: error messages are generally not part of our api guarantees.
In cases like this we should be checking errors.Is(err, context.DeadlineExceeded)
, which is a more type-checkable thing that we actually can guarantee.
I generally think of tests as doubling as the human-readable part of the API contract, and so it's good to stick as close to what we guarantee as possible
@@ -120,7 +120,8 @@ func (ip *informerCache) GetInformerForKind(gvk schema.GroupVersionKind) (Inform | |||
if err != nil { | |||
return nil, err | |||
} | |||
_, i, err := ip.InformersMap.Get(gvk, obj) | |||
|
|||
_, i, err := ip.InformersMap.Get(context.TODO(), gvk, obj) |
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.
can you add a TODO here explaining what we'd need to do to plumb this through?
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.
My best attempt at an explanation. WDYT?
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.
sure, looks good. Do you mind putting together a follow-up to do that?
Passing the context down to the `ip.InformersMap.Get()` makes it possible to handle scenarios where the cache takes too long to sync or will never sync.
9887317
to
a7df8ba
Compare
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.
/approve
@@ -120,7 +120,8 @@ func (ip *informerCache) GetInformerForKind(gvk schema.GroupVersionKind) (Inform | |||
if err != nil { | |||
return nil, err | |||
} | |||
_, i, err := ip.InformersMap.Get(gvk, obj) | |||
|
|||
_, i, err := ip.InformersMap.Get(context.TODO(), gvk, obj) |
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.
sure, looks good. Do you mind putting together a follow-up to do that?
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DirectXMan12, djzager 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 |
**Description** Add timeout in the watch feature for Ansible based-operators proxy to avoid appears that the reconcile is stuck and hang when the operator has not the correct permissions to List and Watch the resources. **Motivation for the change:** - #1638 - https://bugzilla.redhat.com/show_bug.cgi?id=1701041 **Note** Also, solved by kubernetes-sigs/controller-runtime#663.
Follow up to #580
Fixes #562
If the context's deadline is exceeded waiting for the cache to sync, then we should return an appropriate error.
This intentionally punts on what a sensible default should be for this timeout based on this comment
What this PR needs
HasSynced
method.