SharedInformer has a shared data cache, and is able to distribute notifications for changes to the cache to multiple listeners who have registered to it. SharedInformer is also a "Producer-Consumer" framework, using Controller as Producer to produce the Events (, or changes to the cache).
The interface SharedInformer enables users to provide customer ResourceEventHandler via the AddEventHandler function. The concrete implementation of this interface sharedIndexInformer, provides a way to better understand this interface.
This struct has two main components:- Controller : which is the producer. Indexer, ListerWatcher, and objectType are all for it.
- sharedProcessor :
- manage the customer Listeners (or EventHandlers);
- distribute Events to the Listeners.
CacheMutationDetector is not necessary from logical, because it just checked whether the cached content has beed modified illegally. If it detects some illegal modifition, it will just panic.
When sharedIndexInformer starts to run, it will first creates a Controller, and start the Controller. It will also start the sharedProcessor. It is should be noted that HandleDeltas function, which is used by the Controller, will call sharedProcessor.distribute().
The struct of sharedProcessor is simple, its main content is an array of Listeners(processorListeners). The struct of processorListener is more complicated than the sharedProcessor. The field pendingNotifications are the Events received from sharedProcessor.distribute(); and the field ResourceEventHandler is provided by users, and is to consume the Events.
sharedProcessor manages the Listeners via function addListener(), and distribute the Events via function distribute().
User can register their ResourceEventHandler at any time, before the sharedInformer is running, or while it is running. sharedInformer will then generate a Listener with that ResourceEventHandler.