以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函数调用的不一样&

本文深入探讨了Kubernetes中的Informer机制,以nodecontroller为例,详细介绍了如何创建和使用sharedInformers,以及Informer如何在nodecontroller、rccontroller等控制器中工作。Informer分为多个大类和细分子类,它们各自有特定的Lister和Informer函数。Informer的工作流程包括创建reflector,监听资源变化,将更新发送给处理器,并通过indexer进行筛选。Informer启动的三个主要组件包括controller、processor和cacheMutationDetector,分别负责处理资源、监听事件和检测缓存一致性。
最低0.47元/天 解锁文章
1382

被折叠的 条评论
为什么被折叠?



