Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
operator: LeaderElectionReleaseOnCancel #556
operator: LeaderElectionReleaseOnCancel #556
Changes from all commits
fd786e2
8431672
0ef001c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 it's better to create this WithCancel context using the stopCh context (created below) instead of a context.Background
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 way
leaderElectionContext
would stop as soon as the stop context is Done. Which is what I'm trying to achieve with this PR.I tried using nested contexts here
https://go.dev/play/p/6dFfBQyXlW1
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.
by using the stop context as parent of this one, the leaderElectionMgr.Start function will be cancelled if a singint or sigterm is received.
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, that's what I don't want to happen. Here's the ending sequence
defer
sutils.Shutdown()
defer goes first. do the cleanup (the leader election is still running here, so we have the lock lease)cancelLeaderElection()
defer goes second, stopping the manager which in turn release the lockAm I missing something 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.
Right, it would be the same as using the
ReleaseOnCancel
option.My concern here is that after calling
cancelLeaderElection()
(with the defer), the program exits, so nothing ensures thatleaderElectionMgr
really finishes. There is a race condition.The internal implementation of the
ReleaseOnCancel
option uses a channel to ensure that the routine has stopped before continuing with the shutdown. Perhaps you can do the same 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.
Added a wait group to ensure leaderElectionMgr is correctly stopped
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 seems to me that this never exits. The leader election manager is stopped with a defer but before that, you are waiting for this to stop, so, it won't happen?
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.
fixed
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 a shutdown should be included here as well since the namespace manager might be up, and perhaps also in the case above. Not sure since the operator won't be elected anymore for that case.
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'm fine with including
utils.Shutdown()
in case of globalManager and namespacedManager error. I wouldn't do it in case of leaderelection error