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

✨Use correct context to cancel "list and watch" & wait for all informers to complete #2121

Merged
merged 2 commits into from Jan 16, 2023

Conversation

inteon
Copy link
Member

@inteon inteon commented Jan 8, 2023

This PR fixes this TODO item:

// TODO(vincepri): Wire the context in here and don't use TODO().
// Can we use the context from the Get call?
ctx := context.TODO()

It also make sure that all informers finish (using a sync.WaitGroup) before returning from the Start function.

@k8s-ci-robot k8s-ci-robot added 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 Jan 8, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @inteon. 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 k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 8, 2023
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.

/hold

Looks good to me, thanks!

/cc @vincepri for a second set of eyes

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 8, 2023
@k8s-ci-robot
Copy link
Contributor

@alvaroaleman: GitHub didn't allow me to request PR reviews from the following users: set, of, eyes, for, a, second.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/hold

Looks good to me, thanks!

/cc @vincepri for a second set of eyes

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 k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 8, 2023
@inteon
Copy link
Member Author

inteon commented Jan 8, 2023

/retest

@k8s-ci-robot
Copy link
Contributor

@inteon: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@alvaroaleman
Copy link
Member

/ok-to-test
/retest

@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 Jan 8, 2023
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 8, 2023
@inteon inteon force-pushed the informer_map_context branch 4 times, most recently from 50c6e20 to 9a2f037 Compare January 8, 2023 22:51
… to complete

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
pkg/cache/internal/informers_map.go Outdated Show resolved Hide resolved
pkg/cache/internal/informers_map.go Outdated Show resolved Hide resolved
pkg/cache/internal/informers_map.go Outdated Show resolved Hide resolved
pkg/cache/internal/informers_map.go Outdated Show resolved Hide resolved
@@ -310,17 +334,17 @@ func (ip *InformersMap) addInformerToMap(gvk schema.GroupVersionKind, obj runtim
// Start the Informer if need by
Copy link
Member

Choose a reason for hiding this comment

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

At the top of this function, shouldn't we check first if we're stopped already before getting all the way down here and return an error?

If I got the flow right, this function would still return correctly even if the informermap has been stopped

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, I still return correctly. I did this to make sure the behavior remained identical to before the change.

Copy link
Member

Choose a reason for hiding this comment

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

We should probably return an error instead of treating it as a no-op, given that the code will silently fail

Copy link
Member Author

@inteon inteon Jan 9, 2023

Choose a reason for hiding this comment

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

It won't fail silently, it will error here (identical to current behavior):

return started, nil, apierrors.NewTimeoutError(fmt.Sprintf("failed waiting for %T Informer to sync", obj), 0)

I think that in order to prevent making a breaking change, we should return a valid informer (that has not been started) from addInformerToMap.

There are multiple ways to get to that timeout error, eg. if the cache is terminated + all informers are terminated before cache.WaitForCacheSync returns true. Ideally, we figure out how to cancel this cache.WaitForCacheSync call when ip.ctx is canceled.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense, although it sounds to me it might be a user error to add after Stop has been called. Could we mark this as a breaking change and return that error?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'll need some more time to figure out how to reliably return an error. I agree that it would be useful to make a breaking change here.

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@inteon
Copy link
Member Author

inteon commented Jan 9, 2023

/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.

/approve
/lgtm
/hold cancel

Merging this now, the current set of changes look good. Let's follow-up for the next iteration to return an error

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 16, 2023
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 16, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, inteon, vincepri

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:
  • OWNERS [alvaroaleman,vincepri]

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 merged commit 5028a59 into kubernetes-sigs:master Jan 16, 2023
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.

None yet

4 participants