k8s informer

本文深入探讨了Kubernetes中的Informer机制,以nodecontroller为例,详细介绍了如何创建和使用sharedInformers,以及Informer如何在nodecontroller、rccontroller等控制器中工作。Informer分为多个大类和细分子类,它们各自有特定的Lister和Informer函数。Informer的工作流程包括创建reflector,监听资源变化,将更新发送给处理器,并通过indexer进行筛选。Informer启动的三个主要组件包括controller、processor和cacheMutationDetector,分别负责处理资源、监听事件和检测缓存一致性。
摘要由CSDN通过智能技术生成

以nodecontroller为例:

一、先创建sharedInformers供所有controler使用,是一个工厂Informer.(sharedInformers := informers.NewSharedInformerFactory(versionedClient, ResyncPeriod(s)()))。其成员有[]sharedIndexInformer切片。

二、每次创建一个controler如node controler、rccontroler等,都会生成一个相应的sharedIndexInformer(namespaceInformer、podInformer等),每种sharedindexInformer中有对应的listwatch函数。

如pod index informer:

func newPodInformer(client clientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
   sharedIndexInformer := cache.NewSharedIndexInformer(
      &cache.ListWatch{
         ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
            return client.CoreV1().Pods(meta_v1.NamespaceAll).List(options)
         },
         WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
            return client.CoreV1().Pods(meta_v1.NamespaceAll).Watch(options)
         },
      },
      &api_v1.Pod{},
      resyncPeriod,
      cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
   )
   return sharedIndexInformer
}

三、podInformer通过向nodecontroler的taintManager进行更新、添加、删除。(所有的controler都差不多)

 

shareInformerFactory种类很多:大(组)类分为APP、autoScaling、core、Extensions、Storage等,每个组里再细分。

分为{group,version,resource}.(一下部分{,,}代表g,v,r,其中*代表下面的资源)所有资源的IndexInformer中都有Lister()(不同版本的lister()函数不一样,informer一样)、Informer()函数。不同版本成员lister watcher函数调用的不一样&

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值