-
Notifications
You must be signed in to change notification settings - Fork 1.2k
🐛 Wait for NonLeaderElectionRunnables to terminate #1005
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
Closed
michaelgugino
wants to merge
1
commit into
kubernetes-sigs:master
from
mgugino-upstream-stage:wait-for-webhooks
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -436,8 +436,14 @@ func (cm *controllerManager) serveHealthProbes(stop <-chan struct{}) { | |
} | ||
|
||
func (cm *controllerManager) Start(stop <-chan struct{}) error { | ||
// join the passed-in stop channel as an upstream feeding into cm.internalStopper | ||
defer close(cm.internalStopper) | ||
// This will block until all runnables started via | ||
// startNonLeaderElectionRunnables finish. | ||
doneCh := make(chan struct{}) | ||
defer func() { | ||
// join the passed-in stop channel as an upstream feeding into cm.internalStopper | ||
close(cm.internalStopper) | ||
<-doneCh | ||
}() | ||
|
||
// initialize this here so that we reset the signal channel state on every start | ||
cm.errSignal = &errSignaler{errSignal: make(chan struct{})} | ||
|
@@ -454,7 +460,7 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error { | |
go cm.serveHealthProbes(cm.internalStop) | ||
} | ||
|
||
go cm.startNonLeaderElectionRunnables() | ||
go cm.startNonLeaderElectionRunnables(doneCh) | ||
|
||
if cm.resourceLock != nil { | ||
err := cm.startLeaderElection() | ||
|
@@ -477,12 +483,13 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error { | |
} | ||
} | ||
|
||
func (cm *controllerManager) startNonLeaderElectionRunnables() { | ||
func (cm *controllerManager) startNonLeaderElectionRunnables(doneCh chan<- struct{}) { | ||
cm.mu.Lock() | ||
defer cm.mu.Unlock() | ||
|
||
cm.waitForCache() | ||
|
||
returnCh := make(chan struct{}) | ||
// Start the non-leaderelection Runnables after the cache has synced | ||
for _, c := range cm.nonLeaderElectionRunnables { | ||
// Controllers block, but we want to return an error if any have an error starting. | ||
|
@@ -495,8 +502,22 @@ func (cm *controllerManager) startNonLeaderElectionRunnables() { | |
// we use %T here because we don't have a good stand-in for "name", | ||
// and the full runnable might not serialize (mutexes, etc) | ||
log.V(1).Info("non-leader-election runnable finished", "runnable type", fmt.Sprintf("%T", ctrl)) | ||
returnCh <- struct{}{} | ||
}() | ||
} | ||
|
||
doneCount := 0 | ||
|
||
numRunners := len(cm.nonLeaderElectionRunnables) | ||
for doneCount < numRunners { | ||
select { | ||
case <-returnCh: | ||
doneCount++ | ||
default: | ||
} | ||
} | ||
Comment on lines
+511
to
+518
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works and I'm fine with it, though it does make me think of a sync.WaitGroup, are we effectively reimplementing that? |
||
close(returnCh) | ||
close(doneCh) | ||
} | ||
|
||
func (cm *controllerManager) startLeaderElectionRunnables() { | ||
|
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.
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.
Would this work as an alternative? This should wait for the done channel on all exits from this function without having to explicitly write it at all exits from the function