[英]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?有没有更好的方法来列出属于特定 K8s Object 的 K8s 事件?
For example, if I wanted to list all events that belonged to a Pod named "podname", I'd do the following:例如,如果我想列出属于名为“podname”的 Pod 的所有事件,我会执行以下操作:
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)? Go 中是否有另一种/更惯用的方式来按 kube 对象的名称进行过滤(而不是在 FieldSelector 中使用类似 json 的字符串)?
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.