以nodecontroller为例:
一、先创建sharedInformers供所有controler使用,是一个工厂Informer.(sharedInformers := informers.NewSharedInformerFactory(versionedClient, ResyncPeriod(s)()))。其成员有[]sharedIndexInformer切片。
二、每次创建一个controler如node controler、rccontroler等,都会生成一个相应的sharedIndexInformer(namespaceInformer、podInformer等),每种sharedindexInformer中有对应的listwatch函数。
如pod index informer:
func newPodInformer(client clientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
sharedIndexInformer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return client.CoreV1().Pods(meta_v1.NamespaceAll).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return client.CoreV1().Pods(meta_v1.NamespaceAll).Watch(options)
},
},
&api_v1.Pod{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
return sharedIndexInformer
}
三、podInformer通过向nodecontroler的taintManager进行更新、添加、删除。(所有的controler都差不多)
shareInformerFactory种类很多:大(组)类分为APP、autoScaling、core、Extensions、Storage等,每个组里再细分。
分为{group,version,resource}.(一下部分{,,}代表g,v,r,其中*代表下面的资源)所有资源的IndexInformer中都有Lister()(不同版本的lister()函数不一样,informer一样)、Informer()函数。不同版本成员lister watcher函数调用的不一样&