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.

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

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用