Skip to content

Commit b6c3129

Browse files
AdirioIK-Adrian
authored andcommitted
Remove duplicate code
Signed-off-by: Adrián Orive <[email protected]>
1 parent 1af76ae commit b6c3129

File tree

1 file changed

+12
-40
lines changed

1 file changed

+12
-40
lines changed

staging/src/k8s.io/client-go/tools/cache/controller.go

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -285,45 +285,7 @@ func NewInformer(
285285
// This will hold the client state, as we know it.
286286
clientState := NewStore(DeletionHandlingMetaNamespaceKeyFunc)
287287

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)
327289
}
328290

329291
// NewIndexerInformer returns a Indexer and a controller for populating the index
@@ -352,6 +314,16 @@ func NewIndexerInformer(
352314
// This will hold the client state, as we know it.
353315
clientState := NewIndexer(DeletionHandlingMetaNamespaceKeyFunc, indexers)
354316

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 {
355327
// This will hold incoming changes. Note how we pass clientState in as a
356328
// KeyLister, that way resync operations will result in the correct set
357329
// of update/delete deltas.
@@ -390,5 +362,5 @@ func NewIndexerInformer(
390362
return nil
391363
},
392364
}
393-
return clientState, New(cfg)
365+
return New(cfg)
394366
}

0 commit comments

Comments
 (0)