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

如何避免在同步时调用`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.

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

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料