# IT明星不是梦 # 图解kubernetes资源扩展机制实现(下)

2021-09-08 05:12

阅读:527

标签:对比   crash   struct   pdu   需要   ash   starting   自己的   控制器   昨天我们介绍了k8s中资源插件机制的核心关键组件,今天我们继续来看下各个组件是如何进行通信的,以及k8s中针对事件处理背后的关键设计 1.PluginManager PluginManager是一个上层组件,其内部包含了上篇文章中的关键组件,并且协调其内部数据流,而且还提供针对不同插件的具体的控制器 1.1 核心数据结构 核心结构里面其实就是按照数据流来进行设计的,首先需要一个感知插件desiredStateOfWorldPopulator用于感知后端服务的创建或者删除,然后将感知到的事件加入到desiredStateOfWorld期望状态缓存,由reconciler负责期进行底层的注册和下线,并且将结果存储到actualStateOfWorld实际状态缓存 type pluginManager struct { // 插件感知 desiredStateOfWorldPopulator *pluginwatcher.Watcher // 协调器插件 reconciler reconciler.Reconciler // 实际状态缓存 actualStateOfWorld cache.ActualStateOfWorld // 期望状态缓存 desiredStateOfWorld cache.DesiredStateOfWorld } 1.2 初始化 初始化中会将dsw和asw都交给reconciler用于进行事件的感知和更新对应的缓存 func NewPluginManager( sockDir string, recorder record.EventRecorder) PluginManager { asw := cache.NewActualStateOfWorld() dsw := cache.NewDesiredStateOfWorld() // 这里会将期望状态缓存和实际状态缓存,都交给reconciler reconciler := reconciler.NewReconciler( operationexecutor.NewOperationExecutor( operationexecutor.NewOperationGenerator( recorder, ), ), loopSleepDuration, dsw, asw, ) pm := &pluginManager{ // 启动一个watcher并且存储dsw期望状态缓存,后续reconciler就可以通过dsw感知到新的状态了 desiredStateOfWorldPopulator: pluginwatcher.NewWatcher( sockDir, dsw, ), reconciler: reconciler, desiredStateOfWorld: dsw, actualStateOfWorld: asw, } return pm } 1.3 启动插件管理器 插件管理器启动其实就是启动内部的desiredStateOfWorldPopulator就会讲watcher感知的事件,不断的修改自己的内部缓存这样reconciler就可以不断的通过期望状态缓存,进行对应grpc的调用从而满足期望状态 func (pm *pluginManager) Run(sourcesReady config.SourcesReady, stopCh


评论


亲,登录后才可以留言!