Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)?

like image 626
Daniel W Avatar asked Dec 21 '25 18:12

Daniel W


1 Answers

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)
like image 173
Nycodym Achuprynkin Avatar answered Dec 24 '25 08:12

Nycodym Achuprynkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!