英文:
Golang/Kubernetes: How to get/describe Node events
问题
我正在尝试通过Golang Kubernetes客户端获取特定节点的事件。
类似于当我运行 kubectl describe node <node-name>
时获取的事件的底部部分。
我能够获取Pod的事件,但不确定如何为节点执行相同的操作。
events, _ := coreClient.CoreV1().Events("spark").List(context.TODO(), metav1.ListOptions{FieldSelector: "involvedObject.name=spark-t2f59", TypeMeta: metav1.TypeMeta{Kind: "Pod"}})
更新:
我不确定是否可以使用.Get
来实现这个目标?我不确定下面的语法中期望的字符串是什么?
events, err := coreClient.CoreV1().Events(namespace).Get(context.TODO(), STRING-HERE, metav1.GetOptions{})
英文:
I am trying to get a specific node events through Golang Kubernetes client.
something similar to events we get when I run kubectl describe node <node-name>
the lower end part of events.
I am able to get pod events but not sure how to do the same for a node.
events, _ := coreClient.CoreV1().Events("spark").List(context.TODO(), metav1.ListOptions{FieldSelector: "involvedObject.name=spark-t2f59", TypeMeta: metav1.TypeMeta{Kind: "Pod"}})
Update:
I am not sure if using .Get can help with that? I am not sure what string is expected in below syntax ?
events, err := coreClient.CoreV1().Events(namespace).Get(context.TODO(), STRING-HERE, metav1.GetOptions{})
答案1
得分: 2
你应该能够像获取 Pod 的事件一样获取 Node 的事件,只需在查询中替换 "Kind" 选项:
namespace := "my-namespace"
nodeName := "my-node-71544c18-8wn3"
events, err := clientset.CoreV1().Events(namespace).List(context.TODO(), metav1.ListOptions{
TypeMeta: metav1.TypeMeta{
Kind: "Node",
},
FieldSelector: "involvedObject.name=" + nodeName,
})
英文:
You should be able to get the Node's events just as you did for a Pod, just by replacing the "Kind" option in your query:
namespace := "my-namespace"
nodeName := "my-node-71544c18-8wn3"
events, err := clientset.CoreV1().Events(namespace).List(context.TODO(), metav1.ListOptions{
TypeMeta: metav1.TypeMeta{
Kind: "Node",
},
FieldSelector: "involvedObject.name=" + nodeName,
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论