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 relatively new to Kubernetes, and they're described in terms much too complex to me, such that I'm still 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/Deletedevents;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
myHandlerobject will receiveOnAdd()/OnUpdate()/OnDelete()calls.To me, this seems more or less equivalent to the
ResultChanI got in (1.) above; one difference is that apparently now I get the "before" state of the resource as a bonus, whereas withResultChanI would only get its "after" state.Also, IIUC, this is actually somehow built on the
watch.Interfacementioned 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()— (uh wow, now those are a mouthful...) 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 subtle (?) differences between a "regular"NewInformervs.NewSharedInformervs.NewSharedIndexInformer...
Could someone please help me understand the differences between above APIs in the Kubernetes client-go package?