概述中主要梳理整体关系,具体方法与源码细节对照详细文档阅读
主要实体对象
store&indexer
DeltaFIFO
Reflector
Config&controller
sharedProcessor
sharedIndexInformer
类的定位与使用关系
store&indexer
- Indexer在整个informer中作为本地缓存使用,对所有从api-server中获得的资源都根据keyFunc生成的id,保存在Indexr中
-
DeltaFIFO
DeltaFIFO在infromer中作为储存Delta(从api-server中取出的表示资源变化类型的对象)的队列,
-
Reflector
Reflector在infromer中作为获取数据来源的工具,从api-server中获取指定资源的变化情况,构建为Delta放入DeltaFIFO中。
-
Config&controller
controller使用Reflector获取数据并调用processLoop用把数据放入指定sharedProcessor中;controller中创建并启动Reflector用以获取数据,并定时调用自身的processLoop方法把DeltasFIFO中的数据取出并放入指定的sharedProcessor中存储;
-
sharedProcessor
sharedProcessor是一组processorListener的集合,sharedIndexInformer中调用Reflector,从DeltaFIFO中取出的数据,放入到sharedProcessor中,
- 调用processorListener.run方法,使用processorListener.handler中存放的方法,自定义处理当前放入的notification
-
sharedIndexInformer
informer的主体类,创建Config并使用Config创建controller,启动controller,开始采集数据,并使用processorListener.handler处理notification
总流程图示
NewSharedInformer
sharedIndexInformer.Run