Home > OS >  Golang/Kubernetes: How to get/describe Node events
Golang/Kubernetes: How to get/describe Node events

Time:05-25

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{})

CodePudding user response:

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,
    })
  • Related