summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDr. Stefan Schimanski <stefan.schimanski@gmail.com>2017-10-06 15:43:47 +0200
committerGitHub <noreply@github.com>2017-10-06 15:43:47 +0200
commit352adefe8f952ea329d2391316d39d1ece0123a8 (patch)
tree3db469ffd0842f73f80d04a0efea58bc59ca5275
parent5478979116155be4331921125491735b3cc90eff (diff)
Switch to lister
-rw-r--r--contributors/devel/controllers.md12
1 files 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 <NAME> 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
}