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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.