I'm trying to write code that behaves like
kubectl get pods --watch.
This way I'm triggered every time the status of the pod changes.
I created a go project (that runs in the cluster) and added the following code:
podsWatcher, err := restAPIClient.CoreV1().Pods("").Watch(globalHTTPContext, metav1.ListOptions{Watch: true})
if err != nil {
// do something
}
podsChan := podsWatcher.ResultChan()
for event := range podsChan {
switch event.Type {
case watch.Added:
// do something
case watch.Modified:
// do something
case watch.Deleted:
// do something
case watch.Bookmark:
// do something
case watch.Error:
// do something
}
}
I receive an event every time I make a major change in the pod, but not for all of the events. (events).
How can I get a trigger of every change that happened in the status of the pods (like the --watch flag)?