上接 Kubernetes: client-go 源码剖析(一)
运行 informer 运行 informer 将 Reflector,informer 和 indexer 组件关联以实现 informer 流程图的流程。
Reflector List&Watch 运行 informer:
1informer.Run(stopCh) 2 3// client-go/tools/cache/shared_informer.go 4func (s *sharedIndexInformer) Run(stopCh <-chan struct{}) { 5 func() { 6 ... 7 // 创建 DeltaFIFO 队列 8 fifo := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ 9 KnownObjects: s.indexer, 10 EmitDeltaTypeReplaced: true, 11 Transformer: s.transform, 12 }) 13 14 cfg := &Config{ 15 Queue: fifo, 16 ListerWatcher: s.listerWatcher, 17 ObjectType: s.objectType, 18 ObjectDescription: s.objectDescription, 19 FullResyncPeriod: s.resyncCheckPeriod, 20 RetryOnError: false, 21 ShouldResync: s.processor.shouldResync, 22 Process: s.HandleDeltas, 23 WatchErrorHandler: s.watchErrorHandler, 24 } 25 26 // 根据 Config 创建 informer 的 controller 27 s.controller = New(cfg) 28 s.controller.(*controller).clock = s.clock 29 s.started = true 30 }() 31 32 ... 33 // goroutine 运行 processor 34 wg.StartWithChannel(processorStopCh, s.processor.run) 35 36 ... 37 // 运行 controller 38 s.controller.Run(stopCh) 39} 首先,创建队列 Delta FIFO:
...