From 352adefe8f952ea329d2391316d39d1ece0123a8 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Fri, 6 Oct 2017 15:43:47 +0200 Subject: Switch to lister --- contributors/devel/controllers.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contributors/devel/controllers.md b/contributors/devel/controllers.md index 2daa0a50..c78b9095 100644 --- a/contributors/devel/controllers.md +++ b/contributors/devel/controllers.md @@ -74,8 +74,9 @@ Overall, your controller should look something like this: ```go type Controller struct { - // pods gives access to a shared informer and a lister for pods. - pods informers.PodInformer + // pods gives cached access to pods. + pods informers.PodLister + podsSynced cache.InformerSynced // queue is where incoming work is placed to de-dup and to allow "easy" // rate limited requeues on errors @@ -84,12 +85,13 @@ type Controller struct { func NewController(pods informers.PodInformer) *Controller { c := &Controller{ - pods: pods + pods: pods.Lister(), + podsSynced pods.Informer().HasSynced, queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "controller-name"), } // register event handlers to fill the queue with pod creations, updates and deletions - c.pods.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + pods.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { key, err := cache.MetaNamespaceKeyFunc(obj) if err == nil { @@ -124,7 +126,7 @@ func (c *Controller) Run(threadiness int, stopCh chan struct{}) { glog.Infof("Starting controller") // wait for your secondary caches to fill before starting your work - if !cache.WaitForCacheSync(stopCh, c.pods.Informer().HasSynced) { + if !cache.WaitForCacheSync(stopCh, c.podsSynced) { return } -- cgit v1.2.3