概述中主要梳理整体关系,具体方法与源码细节对照详细文档阅读

主要实体对象

store&indexer

1,Store&Indexer

DeltaFIFO

2,DeltaFIFO

Reflector

3,Reflector

Config&controller

4,Config&Controller

sharedProcessor

5,SharedProcessor

sharedIndexInformer

6,SharedIndexInformer

类的定位与使用关系

store&indexer

  • Indexer在整个informer中作为本地缓存使用,对所有从api-server中获得的资源都根据keyFunc生成的id,保存在Indexr中
  • 被DeltaFIFO使用

    DeltaFIFO

  • DeltaFIFO在infromer中作为储存Delta(从api-server中取出的表示资源变化类型的对象)的队列,

  • 被Reflector作为Queue使用

    Reflector

  • Reflector在infromer中作为获取数据来源的工具,从api-server中获取指定资源的变化情况,构建为Delta放入DeltaFIFO中。

  • 被controller使用

    Config&controller

  • controller使用Reflector获取数据并调用processLoop用把数据放入指定sharedProcessor中;controller中创建并启动Reflector用以获取数据,并定时调用自身的processLoop方法把DeltasFIFO中的数据取出并放入指定的sharedProcessor中存储;

  • 被sharedIndexInformer直接使用

    sharedProcessor

  • sharedProcessor是一组processorListener的集合,sharedIndexInformer中调用Reflector,从DeltaFIFO中取出的数据,放入到sharedProcessor中,

  • 调用processorListener.run方法,使用processorListener.handler中存放的方法,自定义处理当前放入的notification
  • 被sharedIndexInformer直接使用

    sharedIndexInformer

  • informer的主体类,创建Config并使用Config创建controller,启动controller,开始采集数据,并使用processorListener.handler处理notification

    总流程图示

    NewSharedInformer

    概述 - 图1

    sharedIndexInformer.Run

    概述 - 图2