Skip to content

Commit 605dc32

Browse files
authored
Merge pull request #163 from mhrivnak/let-start-return
lets controllerManager.start() return instead of blocking
2 parents 6eabf5c + 5790c83 commit 605dc32

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

pkg/manager/internal.go

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -204,42 +204,34 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error {
204204
}
205205

206206
func (cm *controllerManager) start(stop <-chan struct{}) {
207-
func() {
208-
cm.mu.Lock()
209-
defer cm.mu.Unlock()
210-
211-
cm.stop = stop
207+
cm.mu.Lock()
208+
defer cm.mu.Unlock()
212209

213-
// Start the Cache. Allow the function to start the cache to be mocked out for testing
214-
if cm.startCache == nil {
215-
cm.startCache = cm.cache.Start
216-
}
217-
go func() {
218-
if err := cm.startCache(stop); err != nil {
219-
cm.errChan <- err
220-
}
221-
}()
210+
cm.stop = stop
222211

223-
// Wait for the caches to sync.
224-
// TODO(community): Check the return value and write a test
225-
cm.cache.WaitForCacheSync(stop)
226-
227-
// Start the runnables after the cache has synced
228-
for _, c := range cm.runnables {
229-
// Controllers block, but we want to return an error if any have an error starting.
230-
// Write any Start errors to a channel so we can return them
231-
ctrl := c
232-
go func() {
233-
cm.errChan <- ctrl.Start(stop)
234-
}()
212+
// Start the Cache. Allow the function to start the cache to be mocked out for testing
213+
if cm.startCache == nil {
214+
cm.startCache = cm.cache.Start
215+
}
216+
go func() {
217+
if err := cm.startCache(stop); err != nil {
218+
cm.errChan <- err
235219
}
236-
237-
cm.started = true
238220
}()
239221

240-
select {
241-
case <-stop:
242-
// We are done
243-
return
222+
// Wait for the caches to sync.
223+
// TODO(community): Check the return value and write a test
224+
cm.cache.WaitForCacheSync(stop)
225+
226+
// Start the runnables after the cache has synced
227+
for _, c := range cm.runnables {
228+
// Controllers block, but we want to return an error if any have an error starting.
229+
// Write any Start errors to a channel so we can return them
230+
ctrl := c
231+
go func() {
232+
cm.errChan <- ctrl.Start(stop)
233+
}()
244234
}
235+
236+
cm.started = true
245237
}

0 commit comments

Comments
 (0)