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)?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With