-
Notifications
You must be signed in to change notification settings - Fork 332
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
Delay informer start after controller. #1757
Conversation
/assign @n3wscott |
/assign @grantr |
Codecov Report
@@ Coverage Diff @@
## master #1757 +/- ##
=======================================
Coverage 68.61% 68.61%
=======================================
Files 215 215
Lines 9239 9239
=======================================
Hits 6339 6339
Misses 2584 2584
Partials 316 316
Continue to review full report at Codecov.
|
|
||
// Start the injection clients and informers. | ||
logging.FromContext(ctx).Info("Starting informers...") | ||
go func(ctx context.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.
The whole point of this method is to start the informers here and not need to duplicate that code in the caller.
Perhaps we can pass a delay config in the inbound context object instead? The goal is to reduce the amount of special code each injection enabled cmd needs to run. MainWithConfig
is just one simple example.
Another example of integration: https://github.com/knative-sandbox/eventing-rabbitmq/blob/56208970df1d5db5526a12137d54ea16b37fe149/test/e2e/cmd/recorder/main.go#L32
I don't want to have to copy the informer startup code in all the places I have called enable injection.
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.
Delaying the start of goroutine might be a little bit tricky. If we use a magic time duration, then it might cause lots of unit test to fail. If we use a signal instead, then we still need to change all the downstream codes to signal start, which is same as calling StartInformers
directly.
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.
Please check this PR #1772 again. I think I prefer a single method that returns a callback over two new methods.
injection/sharedmain/main.go
Outdated
@@ -129,7 +129,7 @@ func GetLeaderElectionConfig(ctx context.Context) (*leaderelection.Config, error | |||
|
|||
// EnableInjectionOrDie enables Knative Injection and starts the informers. | |||
// Both Context and Config are optional. | |||
func EnableInjectionOrDie(ctx context.Context, cfg *rest.Config) context.Context { | |||
func EnableInjectionOrDie(ctx context.Context, cfg *rest.Config) (context.Context, []controller.Informer) { |
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.
This is a breaking api change for all things that already use this and we can't do that for all the downstreams.
/hold
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 guess this logic only works if StartInformers
is called immediately after this function. At least sharedmain
does not do that, so it needs to be reverted. Callers like chaosduck/main.go
however seems less a problem, though I still think it should be fixed.
leaderelection/chaosduck/main.go
Outdated
ctx = sharedmain.EnableInjectionOrDie(ctx, nil) | ||
|
||
ctx, informers := sharedmain.EnableInjectionOrDie(ctx, nil) | ||
if err := controller.StartInformers(ctx.Done(), informers...); 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.
yeah ^ exactly, I don't want to need to copy this chunk of code in the dozens of places EnableInjectionOrDie
is used.
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.
Same here, will it be better if the EnableInjectionOrDie
function return a start function instead of []informers
, so downstream just need to call a function instead of this chunk of code? I do know this will still break the API.
89b56be
to
735f6a3
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zhongduo 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 |
@zhongduo: The following test failed, say
Full PR test history. Your PR dashboard. 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. |
Closing this because the fix is done in #1772 |
@zhongduo: 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. |
Starting informer before controller will cause resync period set
in the informer not respected, this commit makes EnableInjectionOrDie
to return informers so that the callers can delay the start of the
informer.
Fix #1756