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

Delay informer start after controller. #1757

Closed
wants to merge 1 commit into from

Conversation

zhongduo
Copy link
Contributor

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

@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 29, 2020
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Sep 29, 2020
@zhongduo
Copy link
Contributor Author

/assign @n3wscott

@zhongduo
Copy link
Contributor Author

/assign @grantr

@codecov
Copy link

codecov bot commented Sep 29, 2020

Codecov Report

Merging #1757 into master will not change coverage.
The diff coverage is 58.33%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1757   +/-   ##
=======================================
  Coverage   68.61%   68.61%           
=======================================
  Files         215      215           
  Lines        9239     9239           
=======================================
  Hits         6339     6339           
  Misses       2584     2584           
  Partials      316      316           
Impacted Files Coverage Δ
codegen/cmd/injection-gen/generators/packages.go 0.00% <0.00%> (ø)
test/helpers/dryrun.go 0.00% <0.00%> (ø)
test/interactive/docker.go 42.42% <0.00%> (ø)
test/mako/config/benchmark.go 0.00% <0.00%> (ø)
test/mako/config/environment.go 0.00% <0.00%> (ø)
apis/field_error.go 98.29% <100.00%> (ø)
metrics/prometheus_exporter.go 89.28% <100.00%> (ø)
profiling/server.go 84.37% <100.00%> (ø)
testutils/clustermanager/e2e-tests/util.go 75.00% <100.00%> (ø)
webhook/webhook.go 77.38% <100.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2478414...735f6a3. Read the comment docs.

@knative-prow-robot knative-prow-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 Sep 29, 2020

// Start the injection clients and informers.
logging.FromContext(ctx).Info("Starting informers...")
go func(ctx context.Context) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@n3wscott n3wscott Oct 6, 2020

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.

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

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

Copy link
Contributor Author

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.

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 30, 2020
ctx = sharedmain.EnableInjectionOrDie(ctx, nil)

ctx, informers := sharedmain.EnableInjectionOrDie(ctx, nil)
if err := controller.StartInformers(ctx.Done(), informers...); err != nil {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 4, 2020
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 6, 2020
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zhongduo
To complete the pull request process, please assign grantr after the PR has been reviewed.
You can assign the PR to them by writing /assign @grantr in a comment when ready.

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

@zhongduo zhongduo requested a review from n3wscott October 6, 2020 13:40
@knative-prow-robot
Copy link
Contributor

@zhongduo: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-knative-pkg-unit-tests 735f6a3 link /test pull-knative-pkg-unit-tests

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.

@zhongduo
Copy link
Contributor Author

zhongduo commented Oct 7, 2020

Closing this because the fix is done in #1772

@zhongduo zhongduo closed this Oct 7, 2020
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 7, 2020
@knative-prow-robot
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indicates the PR's author has signed the CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.

PR #1658 is preventing resync period of informer to be overwritten
5 participants