What's the difference between a Watch and an informer?
See original GitHub issueWhat’s the difference between:
const watch = new k8s.Watch(kubeConfig);
watch.watch(
'/api/v1/namespaces/default/pods',
{},
(type, obj) => {
switch (type) {
case 'ADDED': console.log('added'); break;
case 'MODIFIED': console.log('modified'); break;
case 'DELETED': console.log('deleted'); break;
}
},
err => {
console.log('error');
}
);
and:
const listFn = () => k8sApi.listPodForAllNamespaces();
const informer = k8s.makeInformer(kc, '/api/v1/namespaces/default/pods', listFn);
informer.on('add', (obj: k8s.V1Pod) => { console.log(`Added: ${obj.metadata!.name}`); });
informer.on('update', (obj: k8s.V1Pod) => { console.log(`Updated: ${obj.metadata!.name}`); });
informer.on('delete', (obj: k8s.V1Pod) => { console.log(`Deleted: ${obj.metadata!.name}`); });
informer.start();
It seems like the informer is doing a lot more stuff. There’s a whole in-memory cache of all the Kubernetes objects being watched?
And why is there a listFn and a path in the informer case? In this example (which was taken from the official example, the list function is getting pods for all namespaces whereas the endpoint is only fetching pods in the default namespace, which seems wrong.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Kubernetes Informers vs Watch | Basics of client-go ... - YouTube
We also looked into the comparison of informers with watch and why we ... 00:38 What are custom controller 02:47 watch verb from...
Read more >A Deep Dive Into Kubernetes Informers - Farhan Aly
Writing Your Own Informers. kubediff is a Kubernetes resource diff watcher, with the ability to send event notifications to slack/webhooks.
Read more >A Chronicom VS Watcher VS The Watcher Informant
The watcher informant is someone who is both a watcher and a chronicom. ... There are a few key differences between a chronicom,...
Read more >Do 'informer' and 'informant' have the same meaning? - Quora
An informer is the person revealing confidential information (usually in return for money). So a police informer is an 'insider' in the target...
Read more >Introduction to Fabric8 Kubernetes Java Client Informer API
What's the benefit of using Informers over plain Watch? You are more prone to miss events (e.g. network problems) sometimes during plain Watch....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You are correct that example is wrong, It should be listing pods for the default namespace…
The main difference between a Watch and an Informer is that a Watch can disconnect (network problems, timeout, etc) whereas an Informer tries to re-list and re-watch to hide such failures from the caller.
The cache is also there so you can use list/get semantics instead of event-driven semantics if you prefer.
Also the informer API is a little more Javascript-y.
But the main difference is the re-list, re-watch in the presence of failures.
I’ll fix the example (and possibly document it a little more)
@brendanburns can you point me to where the re-watch logic is? Does it do some sort of dead peer detection at all or does it only detect clean disconnects? I wrote similar logic for a php client and ultimately had to just put a non-activity timeout on the socket and reconnect (keeping track of the last version received). Interested to see how it’s implemented here and additionally if it’s possible to add the logic to pure watches in addition to informers.