@@ -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,16 @@ 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
+ func newInformer (
321
+ lw ListerWatcher ,
322
+ objType runtime.Object ,
323
+ resyncPeriod time.Duration ,
324
+ h ResourceEventHandler ,
325
+ clientState Store ,
326
+ ) Controller {
355
327
// This will hold incoming changes. Note how we pass clientState in as a
356
328
// KeyLister, that way resync operations will result in the correct set
357
329
// of update/delete deltas.
@@ -390,5 +362,5 @@ func NewIndexerInformer(
390
362
return nil
391
363
},
392
364
}
393
- return clientState , New (cfg )
365
+ return New (cfg )
394
366
}
0 commit comments