I need my Go app to monitor some resources in a Kubernetes cluster and react to their changes. Based on numerous articles and examples, I seem to have found a few ways to do it; however, I'm unable to grasp the difference between them — and thus, to know which one to use, so that I don't get some unexpected behaviors. Specifically:
watch.Interface.ResultChan()
— (acquired through e.g.rest.Request.Watch()
) — this already seems to let me react to changes happening to a resource, by providingAdded
/Modified
/Deleted
events;cache.NewInformer()
— when I implement acache.ResourceEventHandler
, I can pass it as last argument in:cache.NewInformer( cache.NewListWatchFromClient(clientset.Batch().RESTClient(), "jobs", ...), &batchv1.Job{}, 0, myHandler)
then, the
myHandler
object will receiveOnAdd()
/OnUpdate()
/OnDelete()
calls.To me, this seems more or less equivalent to the
ResultChan
I got in (1.) above; one difference is that apparently now I get the "before" state of the resource as a bonus, whereas withResultChan
I would only get its "after" state.Also, IIUC, this is actually somehow built on the
watch.Interface
mentioned above (throughNewListWatchFromClient
) — so I guess it brings some value over it, and/or fixes some (what?) deficiencies of a rawwatch.Interface
?cache.NewSharedInformer()
andcache.NewSharedIndexInformer()
— I tried to dig through the godocs, but I feel completely overloaded with terminology I don't understand, such that I don't seem to be able to grasp the differences between a "regular"NewInformer
vs.NewSharedInformer
vs.NewSharedIndexInformer
.
What are the differences between above APIs in the Kubernetes client-go package?