Skip to content

Commit

Permalink
Merge pull request #163 from mhrivnak/let-start-return
Browse files Browse the repository at this point in the history
lets controllerManager.start() return instead of blocking
  • Loading branch information
k8s-ci-robot committed Oct 19, 2018
2 parents 6eabf5c + 5790c83 commit 605dc32
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions pkg/manager/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,42 +204,34 @@ 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
cm.mu.Lock()
defer cm.mu.Unlock()

// 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
}
}()
cm.stop = stop

// 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(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(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)
}()
}

cm.started = true
}

0 comments on commit 605dc32

Please sign in to comment.