k8s 事件监听

资源监听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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值