如何避免在同步时调用`updateFunc`?

时间:2018-12-16 16:08:22

标签: go controller kubernetes

根据我的了解(和经验)-kubernetes通知程序将updateFunc调用其缓存的每个“同步”事件-从我收集的信息来看,这是由于this令人讨厌的代码和平。

通知者定义示例:

informer:= NewInformer(
&cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
  return kubeClient.Batch().Jobs(api.NamespaceAll).List(options)
},
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
  return kubeClient.Batch().Jobs(api.NamespaceAll).Watch(options)
},....)

...

informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
    AddFunc: func(obj interface{}){},
    // Make this function be called *only* on update. 
    UpdateFunc: func(old, current interface{}){},
    DeleteFunc: func(current interface{}){},
})

但是对于我的用例-调用updateFunc仅应在资源更新时才真正发生(例如,我每次更新或进入I / O时都要进行大量计算)。

我一直在流浪,有没有办法仅在更新时致电updateFunc

1 个答案:

答案 0 :(得分:1)

我找到了答案in this github issue

  

如果resourceVersion在新旧版本之间不同,则会观察到实际的更新事件。