From 6835318d1e98aeb3c2f27b6f0f1e30a964996836 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Tue, 7 Apr 2015 17:40:30 -0700 Subject: [PATCH] switch to require 'go controller.Run()' --- pkg/controller/framework/controller.go | 5 +++-- pkg/controller/framework/controller_test.go | 4 ++-- plugin/pkg/scheduler/factory/factory.go | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/controller/framework/controller.go b/pkg/controller/framework/controller.go index a55e09dd6fd..b732d92b7a7 100644 --- a/pkg/controller/framework/controller.go +++ b/pkg/controller/framework/controller.go @@ -74,8 +74,9 @@ func New(c *Config) *Controller { // Run begins processing items, and will continue until a value is sent down stopCh. // It's an error to call Run more than once. -// Run does not block. +// Run blocks; call via go. func (c *Controller) Run(stopCh <-chan struct{}) { + defer util.HandleCrash() cache.NewReflector( c.config.ListerWatcher, c.config.ObjectType, @@ -83,7 +84,7 @@ func (c *Controller) Run(stopCh <-chan struct{}) { c.config.FullResyncPeriod, ).RunUntil(stopCh) - go util.Until(c.processLoop, time.Second, stopCh) + util.Until(c.processLoop, time.Second, stopCh) } // processLoop drains the work queue. diff --git a/pkg/controller/framework/controller_test.go b/pkg/controller/framework/controller_test.go index bbcf8719956..db9e1c747d7 100644 --- a/pkg/controller/framework/controller_test.go +++ b/pkg/controller/framework/controller_test.go @@ -94,7 +94,7 @@ func Example() { // Create the controller and run it until we close stop. stop := make(chan struct{}) - framework.New(cfg).Run(stop) + go framework.New(cfg).Run(stop) // Let's add a few objects to the source. for _, name := range []string{"a-hello", "b-controller", "c-framework"} { @@ -151,7 +151,7 @@ func ExampleInformer() { // Run the controller and run it until we close stop. stop := make(chan struct{}) - controller.Run(stop) + go controller.Run(stop) // Let's add a few objects to the source. for _, name := range []string{"a-hello", "b-controller", "c-framework"} { diff --git a/plugin/pkg/scheduler/factory/factory.go b/plugin/pkg/scheduler/factory/factory.go index 4c8dda283ee..d0084d13576 100644 --- a/plugin/pkg/scheduler/factory/factory.go +++ b/plugin/pkg/scheduler/factory/factory.go @@ -164,7 +164,7 @@ func (f *ConfigFactory) CreateFromKeys(predicateKeys, priorityKeys util.StringSe cache.NewReflector(f.createUnassignedPodLW(), &api.Pod{}, f.PodQueue, 0).RunUntil(f.StopEverything) // Begin populating scheduled pods. - f.scheduledPodPopulator.Run(f.StopEverything) + go f.scheduledPodPopulator.Run(f.StopEverything) // Watch minions. // Minions may be listed frequently, so provide a local up-to-date cache.