-
Notifications
You must be signed in to change notification settings - Fork 1.2k
⚠ make Start on Source interface cancellable #903
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
Conversation
/assign @joelanford |
for _, watch := range c.watches { | ||
log.Info("Starting EventSource", "controller", c.Name, "source", watch.src) | ||
if err := watch.src.Start(watch.handler, c.Queue, watch.predicates...); err != nil { | ||
if err := watch.src.Start(context.TODO(), watch.handler, c.Queue, watch.predicates...); err != nil { |
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.
Here (and in various other places), we have access to a stop channel but not a context. Rather than using context.TODO()
, could we create an equivalent context from the channel?
For example:
func contextWithStopChannel(parent context.Context, stop <-chan struct{}) (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancel(parent)
// If stop is already closed, cancel immediately synchronously.
// Otherwise start a goroutine that asynchronously cancels when stop is closed.
select {
case <-stop:
cancel()
default:
go func() {
<-stop
cancel()
}()
}
return ctx, cancel
}
Using something like this, we may be able to make these sources cancellable while not having to fully migrate stop channels to contexts.
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.
seems reasonable to me
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.
Here (and in various other places), we have access to a stop channel but not a context.
I don't doubt you, I simply wasn't able to find any inside the current scope of this PR. Should I create an issue to look into this (this being - find other scenarios where we have a stop channel but not a context)?
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 think you're not finding many because you started in a place that used the injection pattern and didn't already accept a context. For the cases where the Start function accepts a context, this might be useful to help use remove the stop channels from children without doing so from the parent right away.
eec1fe2
to
9c81c22
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: djzager The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
package source_test | ||
|
||
import ( | ||
"context" |
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.
Do we need tests that check whether Start
will return an error if the passed context is cancelled?
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
9c81c22
to
fe2e8e0
Compare
Adding context.Context to the Source interface's Start method makes it cancellable.
fe2e8e0
to
adc6740
Compare
/test pull-controller-runtime-apidiff-master (just testing) |
@djzager: 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. 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. I understand the commands that are listed here. |
@djzager: PR needs rebase. 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. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
This was implemented as part of #1116 |
@alvaroaleman: Closed this PR. In 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/test-infra repository. |
Adding context.Context to the Source interface's Start method makes it
cancellable.
Fixes #879