2

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.

Joe
  • 623
  • 7
  • 16

1 Answers1

0

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>",
})
Jeremy Beard
  • 2,727
  • 1
  • 20
  • 25