From dd26cdf0f7f8fe3159e6b0e34feef985c09cfbfd Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Fri, 10 Apr 2015 17:05:07 -0700 Subject: [PATCH] Fix comments; switch to watching nodes --- pkg/controller/framework/controller.go | 4 +++- pkg/controller/framework/controller_test.go | 5 +++-- plugin/pkg/scheduler/factory/factory.go | 10 ++-------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/controller/framework/controller.go b/pkg/controller/framework/controller.go index b732d92b7a7..f34913e5a02 100644 --- a/pkg/controller/framework/controller.go +++ b/pkg/controller/framework/controller.go @@ -115,7 +115,9 @@ func (c *Controller) processLoop() { // get called even if nothing changed. This is useful for periodically // evaluating or syncing something. // * OnDelete will get the final state of the item if it is known, otherwise -// it will get an object of type cache.DeletedFinalStateUnknown. +// it will get an object of type cache.DeletedFinalStateUnknown. This can +// happen if the watch is closed and misses the delete event and we don't +// notice the deletion until the subsequent re-list. type ResourceEventHandler interface { OnAdd(obj interface{}) OnUpdate(oldObj, newObj interface{}) diff --git a/pkg/controller/framework/controller_test.go b/pkg/controller/framework/controller_test.go index 924a8c8289f..12132677382 100644 --- a/pkg/controller/framework/controller_test.go +++ b/pkg/controller/framework/controller_test.go @@ -302,8 +302,9 @@ func TestUpdate(t *testing.T) { var testDoneWG sync.WaitGroup - // Make a controller that immediately deletes anything added to it, and - // logs anything deleted. + // Make a controller that deletes things once it observes an update. + // It calls Done() on the wait group on deletions so we can tell when + // everything we've added has been deleted. _, controller := framework.NewInformer( source, &api.Pod{}, diff --git a/plugin/pkg/scheduler/factory/factory.go b/plugin/pkg/scheduler/factory/factory.go index d0084d13576..83d997b2611 100644 --- a/plugin/pkg/scheduler/factory/factory.go +++ b/plugin/pkg/scheduler/factory/factory.go @@ -168,13 +168,7 @@ func (f *ConfigFactory) CreateFromKeys(predicateKeys, priorityKeys util.StringSe // Watch minions. // Minions may be listed frequently, so provide a local up-to-date cache. - if false { - // Disable this code until minions support watches. Note when this code is enabled, - // we need to make sure minion ListWatcher has proper FieldSelector. - cache.NewReflector(f.createMinionLW(), &api.Node{}, f.NodeLister.Store, 10*time.Second).RunUntil(f.StopEverything) - } else { - cache.NewPoller(f.pollMinions, 10*time.Second, f.NodeLister.Store).RunUntil(f.StopEverything) - } + cache.NewReflector(f.createMinionLW(), &api.Node{}, f.NodeLister.Store, 0).RunUntil(f.StopEverything) // Watch and cache all service objects. Scheduler needs to find all pods // created by the same service, so that it can spread them correctly. @@ -232,7 +226,7 @@ func (factory *ConfigFactory) createAssignedPodLW() *cache.ListWatch { // createMinionLW returns a cache.ListWatch that gets all changes to minions. func (factory *ConfigFactory) createMinionLW() *cache.ListWatch { - return cache.NewListWatchFromClient(factory.Client, "minions", api.NamespaceAll, parseSelectorOrDie("")) + return cache.NewListWatchFromClient(factory.Client, "nodes", api.NamespaceAll, parseSelectorOrDie("")) } // Lists all minions and filter out unhealthy ones, then returns