MCPcopy
hub / github.com/kubernetes/client-go / newInformer

Function newInformer

tools/cache/controller.go:334–380  ·  view source on GitHub ↗

newInformer returns a controller for populating the store while also providing event notifications. Parameters * lw is list and watch functions for the source of the resource you want to be informed of. * objType is an object of the type that you expect to receive. * resyncPeriod: if non-zero, will

(
	lw ListerWatcher,
	objType runtime.Object,
	resyncPeriod time.Duration,
	h ResourceEventHandler,
	clientState Store,
)

Source from the content-addressed store, hash-verified

332// * clientState is the store you want to populate
333//
334func newInformer(
335 lw ListerWatcher,
336 objType runtime.Object,
337 resyncPeriod time.Duration,
338 h ResourceEventHandler,
339 clientState Store,
340) Controller {
341 // This will hold incoming changes. Note how we pass clientState in as a
342 // KeyLister, that way resync operations will result in the correct set
343 // of update/delete deltas.
344 fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, clientState)
345
346 cfg := &Config{
347 Queue: fifo,
348 ListerWatcher: lw,
349 ObjectType: objType,
350 FullResyncPeriod: resyncPeriod,
351 RetryOnError: false,
352
353 Process: func(obj interface{}) error {
354 // from oldest to newest
355 for _, d := range obj.(Deltas) {
356 switch d.Type {
357 case Sync, Added, Updated:
358 if old, exists, err := clientState.Get(d.Object); err == nil && exists {
359 if err := clientState.Update(d.Object); err != nil {
360 return err
361 }
362 h.OnUpdate(old, d.Object)
363 } else {
364 if err := clientState.Add(d.Object); err != nil {
365 return err
366 }
367 h.OnAdd(d.Object)
368 }
369 case Deleted:
370 if err := clientState.Delete(d.Object); err != nil {
371 return err
372 }
373 h.OnDelete(d.Object)
374 }
375 }
376 return nil
377 },
378 }
379 return New(cfg)
380}

Callers 2

NewInformerFunction · 0.85
NewIndexerInformerFunction · 0.85

Calls 9

NewDeltaFIFOFunction · 0.85
NewFunction · 0.70
GetMethod · 0.65
UpdateMethod · 0.65
OnUpdateMethod · 0.65
AddMethod · 0.65
OnAddMethod · 0.65
DeleteMethod · 0.65
OnDeleteMethod · 0.65

Tested by

no test coverage detected