dook0034 2018-12-16 16:08
浏览 47
已采纳

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

From what I understand (and experience) - kubernetes informers calls updateFunc each "sync" event of its cache - From what I gather it is due to this annoying peace of code.

An example informer definition:

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{}){},
})

But for my use case - calling updateFunc should really happen only when that resource is updated (e.g. I am doing some intense computation on each update or going to I/O).

I was wandering is there a way to call updateFunc only on update?

  • 写回答

1条回答 默认 最新

  • doutuan9357 2018-12-16 18:12
    关注

    I found answer in this github issue:

    If resourceVersion differs between old and new, an actual update event was observed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失