-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix nil stop value for source.Channel #154
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -75,6 +75,9 @@ type controllerManager struct { | |||||
errChan chan error | ||||||
stop <-chan struct{} | ||||||
|
||||||
// stopper is the write side of the stop channel. They should have the same value. | ||||||
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.
Suggested change
|
||||||
stopper chan<- struct{} | ||||||
|
||||||
startCache func(stop <-chan struct{}) error | ||||||
} | ||||||
|
||||||
|
@@ -158,9 +161,13 @@ func (cm *controllerManager) GetRESTMapper() meta.RESTMapper { | |||||
} | ||||||
|
||||||
func (cm *controllerManager) Start(stop <-chan struct{}) error { | ||||||
defer close(cm.stopper) | ||||||
|
||||||
if cm.resourceLock == nil { | ||||||
go cm.start(stop) | ||||||
go cm.start() | ||||||
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. nit: this doesn't block. Does it really need a goroutine? 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.
Suggested change
|
||||||
select { | ||||||
// Only this function should receive from stop, and everything else | ||||||
// should receive from cm.stop. | ||||||
case <-stop: | ||||||
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. nit: this flow gets a bit confusing to read with |
||||||
// we are done | ||||||
return nil | ||||||
|
@@ -178,7 +185,13 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error { | |||||
RenewDeadline: 10 * time.Second, | ||||||
RetryPeriod: 2 * time.Second, | ||||||
Callbacks: leaderelection.LeaderCallbacks{ | ||||||
OnStartedLeading: cm.start, | ||||||
// This type changes in k8s 1.12 to func(context.Context) | ||||||
// Ignore the passed-in stop channel from leaderelection. The next | ||||||
// thing it does anyway after closing its stop channel is call | ||||||
// OnStoppedLeading. | ||||||
OnStartedLeading: func(_ <-chan struct{}) { | ||||||
cm.start() | ||||||
}, | ||||||
OnStoppedLeading: func() { | ||||||
// Most implementations of leader election log.Fatal() here. | ||||||
// Since Start is wrapped in log.Fatal when called, we can just return | ||||||
|
@@ -203,43 +216,33 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error { | |||||
} | ||||||
} | ||||||
|
||||||
func (cm *controllerManager) start(stop <-chan struct{}) { | ||||||
func() { | ||||||
cm.mu.Lock() | ||||||
defer cm.mu.Unlock() | ||||||
|
||||||
cm.stop = stop | ||||||
|
||||||
// Start the Cache. Allow the function to start the cache to be mocked out for testing | ||||||
if cm.startCache == nil { | ||||||
cm.startCache = cm.cache.Start | ||||||
} | ||||||
go func() { | ||||||
if err := cm.startCache(stop); err != nil { | ||||||
cm.errChan <- err | ||||||
} | ||||||
}() | ||||||
func (cm *controllerManager) start() { | ||||||
cm.mu.Lock() | ||||||
defer cm.mu.Unlock() | ||||||
|
||||||
// Wait for the caches to sync. | ||||||
// TODO(community): Check the return value and write a test | ||||||
cm.cache.WaitForCacheSync(stop) | ||||||
|
||||||
// Start the runnables after the cache has synced | ||||||
for _, c := range cm.runnables { | ||||||
// Controllers block, but we want to return an error if any have an error starting. | ||||||
// Write any Start errors to a channel so we can return them | ||||||
ctrl := c | ||||||
go func() { | ||||||
cm.errChan <- ctrl.Start(stop) | ||||||
}() | ||||||
// Start the Cache. Allow the function to start the cache to be mocked out for testing | ||||||
if cm.startCache == nil { | ||||||
cm.startCache = cm.cache.Start | ||||||
} | ||||||
go func() { | ||||||
if err := cm.startCache(cm.stop); err != nil { | ||||||
cm.errChan <- err | ||||||
} | ||||||
|
||||||
cm.started = true | ||||||
}() | ||||||
|
||||||
select { | ||||||
case <-stop: | ||||||
// We are done | ||||||
return | ||||||
// Wait for the caches to sync. | ||||||
// TODO(community): Check the return value and write a test | ||||||
cm.cache.WaitForCacheSync(cm.stop) | ||||||
|
||||||
// Start the runnables after the cache has synced | ||||||
for _, c := range cm.runnables { | ||||||
// Controllers block, but we want to return an error if any have an error starting. | ||||||
// Write any Start errors to a channel so we can return them | ||||||
ctrl := c | ||||||
go func() { | ||||||
cm.errChan <- ctrl.Start(cm.stop) | ||||||
}() | ||||||
} | ||||||
|
||||||
cm.started = true | ||||||
} |
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: maybe change to (for a bit more clarity -- it took me a moment to parse what "they" was):