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

标签 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

最佳答案

我找到了答案 in this github issue :

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

关于go - 如何避免在同步时调用 `updateFunc`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53803992/

相关文章:

javascript - 变量未定义 : AngularJS

java - 如何在 Spring MVC 中没有 ModelAttribute 的情况下处理/显示错误?

redis - 列出 kubectl pod 的节点

git - 可以在git命令的go程序中设置ssh Key吗?

go - 在 Go 中遍历多维数组

google-app-engine - Go 中的 _post_put_hook

ruby-on-rails - Rails 5.1 如何在 format.json 中呈现无内容响应

kubernetes - 普罗米修斯数据源: client_error: client error: 403

tensorflow - 在本地分发 Tensorflow 训练的最简单方法?

php - 如何在不减慢响应速度的情况下调用微服务?