-
Notifications
You must be signed in to change notification settings - Fork 64
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 context correctly #360
Conversation
✔️ Deploy Preview for elated-stonebraker-105904 canceled. 🔨 Explore the source changes: 67d8796 🔍 Inspect the deploy log: https://app.netlify.com/sites/elated-stonebraker-105904/deploys/6196976325770900073b2ec4 |
- at some point controller-runtime started doing this for us Co-authored-by: Emily Johnson <emjohnson@vmware.com>
f00efb2
to
67d8796
Compare
yayy nice! that's a lot of changes 😅 thanks for putting the work! overall, lgtm! trying to follow the chain of
cartographer/cmd/cartographer/main.go Line 54 in 1bd6074
Lines 112 to 113 in 1bd6074
that's not very usual, and discouraged - the idiomatic way of doing doing would be to pass it via the function instead, being the first argument of the list. it's not something introduced in this PR, but, sounds somewhat appropriate to patch given the context (no pun intended) 😁 wdyt? thx! |
oh also, here Lines 68 to 70 in 1bd6074
we should make |
sorry, one more 😅 we're doing the right thing creating a context with an associated cancel function cartographer/cmd/cartographer/main.go Lines 42 to 44 in 1bd6074
but that will not by default lead to a proper smooth termination when a signal is sent (either us sending a SIGINT / SIGTERM to
(from https://pkg.go.dev/os/signal#hdr-Default_behavior_of_signals_in_Go_programs) i.e., despite passing the context to the right places, we're not being graceful at all. controller-runtime provides a nice little utility for covering this though: https://github.com/kubernetes-sigs/controller-runtime/blob/4d10a0615b11507451ecb58bfd59f0f6ef313a29/pkg/manager/signals/signal.go#L26-L30 // SetupSignalHandler registers for SIGTERM and SIGINT. A context is returned
// which is canceled on one of these signals. If a second signal is caught, the program
// is terminated with exit code 1.
func SetupSignalHandler() context.Context { so, doing something like - if err = cmd.Execute(); err != nil {
+ if err = cmd.Execute(ctrl.SetupSignalHandler()); err != nil {
panic(err)
}
} we should see that after sending a signal, it actually exits gracefully:
(without that context w/ proper signal handling, we don't have the messages above ^) |
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.
left a couple comments about some complementary changes that could go in together, but that's it! lgtm 😁
I agree but I don't think I want to wait to rebase against main again just to get this work in. |
Issue created: #361 |
as suggested in [#360], we should be closer to idiomatic go where rather than passing context via structs, we make use of 1st-arg for ctx. see https://pkg.go.dev/context for more details [#360]: #360 (comment) Signed-off-by: Ciro S. Costa <ciroscosta@vmware.com>
as suggested in [#360], we should be closer to idiomatic go where rather than passing context via structs, we make use of 1st-arg for ctx. see https://pkg.go.dev/context for more details [#360]: #360 (comment) Signed-off-by: Ciro S. Costa <ciroscosta@vmware.com>
as suggested in [#360], we should be closer to idiomatic go where rather than passing context via structs, we make use of 1st-arg for ctx. see https://pkg.go.dev/context for more details [#360]: #360 (comment) Signed-off-by: Ciro S. Costa <ciroscosta@vmware.com>
name: Pull request
about: Submit changes to the code
Changes proposed by this PR
Release Note
PR Checklist
Note: Please do not remove items. Mark items as done
[x]
or usestrikethroughif you believe they are not relevant[ ] Linked to a relevant issue. Eg:Fixes #123
orUpdates #123
wip
commits[ ] Filled in the Release Note section above[ ] Modified the docs to match changes