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?
I found answer in this github issue:
If resourceVersion differs between old and new, an actual update event was observed.