sharedIndexInformer的run函数解析
func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()
fifo := cache.NewDeltaFIFO(cache.MetaNamespaceKeyFunc, nil, s.indexer)
cfg := &Config{
Queue: fifo,
ListerWatcher: s.listerWatcher,
ObjectType: s.objectType,
FullResyncPeriod: s.fullResyncPeriod,
RetryOnError: false,
Process: s.HandleDeltas,
}
func() {
s.startedLock.Lock()
defer s.startedLock.Unlock()
s.controller = New(cfg)
s.started = true
}()
s.processor.run(stopCh)
s.controller.Run(stopCh)
}
//controler中的run回新建一个watcher用于监听资源,并将监听到的资源存入reflector的store里面c.config.Queue
func (c *Controller) Run(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()
r := cache.NewReflector(
c.config.ListerWatcher,
c.config.ObjectType,
c.config.Queue,
c.config.FullResyncPeriod,
)
c.reflectorM

本文详细解析了k8s sharedIndexInformer的run函数,阐述了其内部工作机制。通过创建watcher监听资源变化,更新到reflector的store中,进一步将事件放入controller的queue。indexer作为主要的资源存储,而controller的store实则是queue,接收watch事件并传递给informer。informer再将资源分发给已注册的listener进行处理。
最低0.47元/天 解锁文章

1509

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



