3

Is there a better way to list K8s Events that belong to a specific K8s Object?

For example, if I wanted to list all events that belonged to a Pod named "podname", I'd do the following:

opts := metav1.ListOptions{
    TypeMeta:      metav1.TypeMeta{Kind: "Pod"},
    FieldSelector: "involvedObject.name=podname",
}
    
events, err := clientSet.CoreV1().Events(namespace).List(opts)

Is there a alternative/more idiomatic way in Go to filter by the kube object's name (instead of using a json-like string in FieldSelector)?

Daniel W
  • 31
  • 3
  • Json like filed selector seems like the most elegant solution. Trying to find alternate solution for that would be an bit over engineering. – acid_fuji Jan 15 '21 at 09:44

1 Answers1

1

No, but a little bit better way is:

fieldSelector, _ := fields.ParseSelector("involvedObject.name=podname,involvedObject.kind=Pod")
opts := metav1.ListOptions{FieldSelector: fieldSelector.String()}

events, err := clientSet.CoreV1().Events(namespace).List(opts)