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

Propagate Context #908

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

leonnicolas
Copy link

Propagate a context from the main function to wherever it is needed.

Use github.com/oklog/run run groups to handle the life cycle of the go
routines running the rebooter and metrics server.

Ref: #234
and #808

Signed-off-by: leonnicolas leonloechner@gmx.de

Copy link

github-actions bot commented May 4, 2024

This PR was automatically considered stale due to lack of activity. Please refresh it and/or join our slack channels to highlight it, before it automatically closes (in 7 days).

Copy link
Collaborator

@evrardjp evrardjp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good step. It implements what we talked about in the fast, with a real explanation of why we use context.

Yet, I am not the best person to judge wheter this is enough or whether it's the right context. (And I sadly don't have enough time to delve into it).

Would you mind explaining why it mattered for you? And why did you want to use background context, please? And why you used oklog?

Thank you.

@leonnicolas
Copy link
Author

Would you mind explaining why it mattered for you?

Passing down a context makes sure that when a caller wants to cancel an operation, some function down the line will not block until it returns. Instead it would probably return a context canceled.
In practice, when kured received a SIGINT, it can cancel all outgoing requests and finish processing all incoming requests to the metrics server before it exits.

And why did you want to use background context, please?

This is normally the context you use in the "root" of the application. https://pkg.go.dev/context#Background

And why you used oklog?

At the moment kured starts 2 concurrent processes (go threads) in its main function and the metrics server that blocks the main thread forever.
If any of the go threads crash, we would continue to run the metrics server. No way to tell the other thread to exit as well and terminate the main thread (or try to restart the crashed thread).
oklog's run package just provides one way to manage the life cycle of threads. We could probably use other packages as well. It was just my personal favorite because its API is so slim.

Propagate a context from the main function to wherever it is needed.

Use `github.com/oklog/run` run groups to handle the life cycle of the go
routines running the rebooter and metrics server.

Ref: kubereboot#234
and kubereboot#808

Signed-off-by: leonnicolas <leonloechner@gmx.de>
@@ -421,22 +425,23 @@ func (kb KubernetesBlockingChecker) isBlocked() bool {
return false
}

func rebootBlocked(blockers ...RebootBlocker) bool {
func rebootBlocked(ctx context.Context, blockers ...RebootBlocker) bool {
// TODO: can we do that concurrently
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that we don't commit a // TODO comment, could you add an issue describing this optimization instead? (agree that this is out of scope for this PR)

thank you!

Instead create an issue to address the possible optimization.

Signed-off-by: leonnicolas <leonloechner@gmx.de>
Copy link

This PR was automatically considered stale due to lack of activity. Please refresh it and/or join our slack channels to highlight it, before it automatically closes (in 7 days).

@evrardjp
Copy link
Collaborator

evrardjp commented Aug 7, 2024

Now that you commented on this PR, I think everyone can follow your train of thoughts in the future. I am fine with merging this.

The slight issue I have right now, is my lack of lab to test this. Can anyone test this and see the impact on stuff like the prom' integration? If it still works for someone, I am okay to go forward.

Copy link

github-actions bot commented Oct 7, 2024

This PR was automatically considered stale due to lack of activity. Please refresh it and/or join our slack channels to highlight it, before it automatically closes (in 7 days).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants