client-go watch events for specific pods

1.4k Views Asked by At

I am watching events via clientset, but I want to watch events for a specific Pod, so I add lablelselector to filter them, unfortunately it doesn't work. Adding LabelSelector is a good way to watch pod status, but it doesn't work for events.

    watcher, err := clientset.CoreV1().Events(namespace).Watch(ctx, metav1.ListOptions{
        LabelSelector: labels, //it doesn't work
    })

I am wondering what is good way how to filter events so that I just want to view events that is only be related to specific lable selector.

1

There are 1 best solutions below

0
On

If you want to watch events for a Specific Pod you can use fieldselector

watcher, err := clientset.CoreV1().Events(namespace).Watch(ctx, metav1.ListOptions{
    FieldSelector: "involvedObject.kind=Pod,involvedObject.name=<pod-name>",
})