资源监听client
client-go/tools/cache/sharedIndexInformer::Run
client-go/tools/cache/controller::Run
list watcher 变化的event
Queue : event 队列
Process : 处理event
cfg := &Config{
Queue: fifo,
ListerWatcher: s.listerWatcher,
ObjectType: s.objectType,
FullResyncPeriod: s.resyncCheckPeriod,
RetryOnError: false,
ShouldResync: s.processor.shouldResync,
Process: s.HandleDeltas,
WatchErrorHandler: s.watchErrorHandler,
}
事件监听器 controller
client-go/toos/cache/controller.go
type controller struct {
config Config
reflector *Reflector
reflectorMutex sync.RWMutex
clock clock.Clock
}
2.1 controller::Run 逻辑
2.1.1 reflector::Run ListAndWatch 监听的event 放到queue里
2.1.2 controller::processLoop 从queue中 取出事件 sharedIndexInformer::OnAdd, OnUpdate, OnDelete
(sharedProcessor::distribute 发布 resource event 资源事件 到ReplicaSetController的队列中)
2.1.3 ReplicaSetController 处理event,放入workqueue.RateLimitingInterface 类型的queue
2.1.4 ReplicaSetController 从queue中取出并处理watch的event
sharedIndexInformer
从控制器controller中索引资源信息,并将event交给 ReplicaSetController 处理
type sharedIndexInformer struct {
indexer Indexer
controller Controller
processor *sharedProcessor
listerWatcher ListerWatcher
.....
}
indexer :an indexed local cache
controller : objects/notifications using the ListerWatcher and pushes them into a DeltaFIFO
sharedProcessor : relaying those notifications to each of the informer's clients
监听事件处理器 ReplicaSetController
pkg/controller/replicaset/replica_set.go
ReplicaSetController::Run