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

✨ Take context when getting informer. #663

Merged
merged 1 commit into from
Feb 26, 2020

Conversation

djzager
Copy link
Contributor

@djzager djzager commented Oct 28, 2019

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

Let's punt on the default for now (do it in a separate PR) so we can at least get the capability in and unbreak people that want to use this.

What this PR needs

  • Testing. Currently pursuing faking out the HasSynced method.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 28, 2019
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot
Copy link
Contributor

Welcome @djzager!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 28, 2019
@djzager
Copy link
Contributor Author

djzager commented Oct 28, 2019

/assign @DirectXMan12

@@ -162,9 +164,22 @@ func (ip *specificInformersMap) Get(gvk schema.GroupVersionKind, obj runtime.Obj
}

if started && !i.Informer.HasSynced() {
syncReturn := make(chan bool)
Copy link
Contributor

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

Suggested change
syncReturn := make(chan bool)
syncReturn := make(chan bool, 1 /* don't leak goroutines on timeout */)

select {
case <-ctx.Done():
//end the polling for cache to sync
done <- struct{}{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
done <- struct{}{}
close(done)

pkg/cache/internal/informers_map.go Outdated Show resolved Hide resolved
@DirectXMan12
Copy link
Contributor

hey, are you still interested in working on this?

@djzager
Copy link
Contributor Author

djzager commented Feb 6, 2020

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.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 7, 2020
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 11, 2020
@djzager djzager changed the title [WIP] ✨ Adding timeout to unset context for waiting for cache to sync. ✨ Adding timeout to unset context for waiting for cache to sync. Feb 11, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 11, 2020
@vincepri
Copy link
Member

/ok-to-test
@djzager Can you squash commits down to 1?

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 11, 2020
@djzager djzager force-pushed the cache-timeout branch 2 times, most recently from 6fa0ae5 to 5c3a188 Compare February 11, 2020 15:44
@djzager
Copy link
Contributor Author

djzager commented Feb 11, 2020

/retest

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/assign @DirectXMan12

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 11, 2020
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 12, 2020
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 12, 2020
@vincepri
Copy link
Member

/assign @DirectXMan12 @gerred


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{})))
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 26, 2020
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a 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)
Copy link
Contributor

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?

@DirectXMan12
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 26, 2020
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 26, 2020
@k8s-ci-robot k8s-ci-robot merged commit 741745a into kubernetes-sigs:master Feb 26, 2020
camilamacedo86 added a commit to operator-framework/operator-sdk that referenced this pull request Apr 22, 2020
**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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create timeout and error when informer set up in the cache is hanging
7 participants