@@ -285,45 +285,7 @@ func NewInformer(
285
285
// This will hold the client state, as we know it.
286
286
clientState := NewStore (DeletionHandlingMetaNamespaceKeyFunc )
287
287
288
- // This will hold incoming changes. Note how we pass clientState in as a
289
- // KeyLister, that way resync operations will result in the correct set
290
- // of update/delete deltas.
291
- fifo := NewDeltaFIFO (MetaNamespaceKeyFunc , clientState )
292
-
293
- cfg := & Config {
294
- Queue : fifo ,
295
- ListerWatcher : lw ,
296
- ObjectType : objType ,
297
- FullResyncPeriod : resyncPeriod ,
298
- RetryOnError : false ,
299
-
300
- Process : func (obj interface {}) error {
301
- // from oldest to newest
302
- for _ , d := range obj .(Deltas ) {
303
- switch d .Type {
304
- case Sync , Added , Updated :
305
- if old , exists , err := clientState .Get (d .Object ); err == nil && exists {
306
- if err := clientState .Update (d .Object ); err != nil {
307
- return err
308
- }
309
- h .OnUpdate (old , d .Object )
310
- } else {
311
- if err := clientState .Add (d .Object ); err != nil {
312
- return err
313
- }
314
- h .OnAdd (d .Object )
315
- }
316
- case Deleted :
317
- if err := clientState .Delete (d .Object ); err != nil {
318
- return err
319
- }
320
- h .OnDelete (d .Object )
321
- }
322
- }
323
- return nil
324
- },
325
- }
326
- return clientState , New (cfg )
288
+ return clientState , newInformer (lw , objType , resyncPeriod , h , clientState )
327
289
}
328
290
329
291
// NewIndexerInformer returns a Indexer and a controller for populating the index
@@ -352,6 +314,30 @@ func NewIndexerInformer(
352
314
// This will hold the client state, as we know it.
353
315
clientState := NewIndexer (DeletionHandlingMetaNamespaceKeyFunc , indexers )
354
316
317
+ return clientState , newInformer (lw , objType , resyncPeriod , h , clientState )
318
+ }
319
+
320
+ // newInformer returns a controller for populating the store while also
321
+ // providing event notifications.
322
+ //
323
+ // Parameters
324
+ // * lw is list and watch functions for the source of the resource you want to
325
+ // be informed of.
326
+ // * objType is an object of the type that you expect to receive.
327
+ // * resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate
328
+ // calls, even if nothing changed). Otherwise, re-list will be delayed as
329
+ // long as possible (until the upstream source closes the watch or times out,
330
+ // or you stop the controller).
331
+ // * h is the object you want notifications sent to.
332
+ // * clientState is the store you want to populate
333
+ //
334
+ func newInformer (
335
+ lw ListerWatcher ,
336
+ objType runtime.Object ,
337
+ resyncPeriod time.Duration ,
338
+ h ResourceEventHandler ,
339
+ clientState Store ,
340
+ ) Controller {
355
341
// This will hold incoming changes. Note how we pass clientState in as a
356
342
// KeyLister, that way resync operations will result in the correct set
357
343
// of update/delete deltas.
@@ -390,5 +376,5 @@ func NewIndexerInformer(
390
376
return nil
391
377
},
392
378
}
393
- return clientState , New (cfg )
379
+ return New (cfg )
394
380
}
0 commit comments