-
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
Put EnableInjectionOrDie back on the main path #1772
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1772 +/- ##
=========================================
Coverage ? 68.23%
=========================================
Files ? 218
Lines ? 9295
Branches ? 0
=========================================
Hits ? 6342
Misses ? 2637
Partials ? 316
Continue to review full report at Codecov.
|
/retest |
injection/sharedmain/main.go
Outdated
} | ||
|
||
untyped := ctx.Value(informerStartChanKey{}) | ||
if untyped == 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.
given return is interface{}
this might not always work.
https://medium.com/@mangatmodi/go-check-nil-interface-the-right-way-d142776edef1
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.
thanks
Hi @n3wscott, I think this PR needs some discussion. I understand you are trying to avoid changing the function signature to maintain compatibility, but I believe API compatibility also includes underlying logic too and this PR changes the logic considerably IMO. If I understand correctly, with this PR:
For 1, though I know the timeout is configurable, I do believe most users won't notice this change until they encounter a problem. I am afraid that we are making the issue harder to reproduce to most users and the magic 5 seconds can cause some unexpected problems. Eg, in some case if the controller setup takes about 5 seconds for whatever reason, they will experience some flakiness depending on the actual runtime > 5s or < 5s. Another possible problem is that some logic might be assuming informer start at that time, and this delay start will be quite difficult to debug. So to me it is not much different from the original logic, which starts the informer immediately. For 2 or any other users that are aware of this problem and decide to start it manually, they can easily just use existing code without this PR. If we want to keep API and at the same time avoid duplicate code, here is what I would suggest: Thanks, |
I have updated #1757 with this idea, which will keep API compatibility, could you please see if that can be an alternative solution too? |
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.
Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print)
goimports -w $(find -name '*.go' | grep -v vendor | grep -v third_party | grep -v .pb.go | grep -v wire_gen.go)
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.
Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print)
goimports -w $(find -name '*.go' | grep -v vendor | grep -v third_party | grep -v .pb.go | grep -v wire_gen.go)
Thanks for the thoughtful response. I agree that the timeout was strange. I have moved the Using a callback means the caller can not have access to start informers out of order. |
How do you like this way? |
/retest |
injection/sharedmain/main.go
Outdated
// Start the injection clients and informers. | ||
logging.FromContext(ctx).Info("Starting informers...") | ||
go func(ctx context.Context) { | ||
go func() { |
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 really need this go function? I think it is safer to let it finishes.
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 will be deleted asap after knative rolls to the new one, shared main now calls down to the new version. this method is not changed and is legacy.
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.
My original question is about using go func or not in the old function, but I guess the whole function will be removed anyway.
// EnableInjectionOrDie enables Knative Injection and starts the informers. | ||
// Both Context and Config are optional. Returns context with rest config set | ||
// and a function to start the informers after watches have been set up. | ||
func EnableInjectionOrDie(ctx context.Context, cfg *rest.Config) (context.Context, func()) { |
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 makes sense to me, though the name is a little bit confusing as the original EnableInjectionOrDie
is exported too.
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, that is intended, the original one is in a different package and marked deprecated.
@@ -116,8 +117,7 @@ func quack(ctx context.Context, kc kubernetes.Interface, component string, leade | |||
} | |||
|
|||
func main() { | |||
ctx := signals.NewContext() | |||
ctx = sharedmain.EnableInjectionOrDie(ctx, nil) | |||
ctx, _ := injection.EnableInjectionOrDie(signals.NewContext(), 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.
If we have to do this, that means we are really trying to avoid calling the original function. I would recommend to have a roadmap to deprecate the original function.
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.
It is marked deprecated and documented redirected to the new one version.
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.
That's awesome. Is this on purpose not to call the start function here? Note that the original logic will have informers started here.
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 this might skip your attention. Otherwise LGTM.
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 checked and the duck does not use informers so it is not needed.
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.
Thanks for checking.
injection/injection.go
Outdated
"k8s.io/client-go/rest" | ||
) | ||
|
||
// EnableInjectionOrDie enables Knative Injection and starts the informers. |
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.
Remove starts the informers
.
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.
Updated.
injection/sharedmain/main.go
Outdated
// Start the injection clients and informers. | ||
logging.FromContext(ctx).Info("Starting informers...") | ||
go func(ctx context.Context) { | ||
go func() { |
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.
My original question is about using go func or not in the old function, but I guess the whole function will be removed anyway.
The naming is just for illustration purpose only. :) |
/retest |
flakes: #1779 |
g2g? /cc @mattmoor |
/retest |
1 similar comment
/retest |
injection/config.go
Outdated
// 2. Fallback to the KUBECONFIG environment variable. | ||
// 3. Fallback to in-cluster config. | ||
// 4. Fallback to the ~/.kube/config. | ||
func GetRestConfig(serverURL, kubeconfig string) (*rest.Config, error) { |
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.
nit: REST
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.
ick, how about GetKubeconfig
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.
it is getting a rest.Config
...
@@ -129,12 +130,13 @@ func GetLeaderElectionConfig(ctx context.Context) (*leaderelection.Config, error | |||
|
|||
// EnableInjectionOrDie enables Knative Injection and starts the informers. | |||
// Both Context and Config are optional. | |||
// Deprecated: use injection.EnableInjectionOrDie |
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.
Should we change this method to:
ctx, si := injection.EnableInjectionOrDie(ctx, cfg)
go si()
return ctx
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.
yes, good idea!
@@ -63,6 +63,7 @@ import ( | |||
// 2. Fallback to the KUBECONFIG environment variable. | |||
// 3. Fallback to in-cluster config. | |||
// 4. Fallback to the ~/.kube/config. | |||
// Deprecated: use injection.GetRESTConfig |
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.
Should this call the other method?
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.
good idea.
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.
/lgtm
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mattmoor, n3wscott 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 |
Supersedes #1757
Reverts #1767