Go lang / client : How to describe a node using go/ client

huangapple go评论78阅读模式
英文:

Go lang / client : How to describe a node using go/ client

问题

我想使用Go客户端来描述一个节点,具体来说,我想列出节点的条件类型、状态和事件。

编辑:我已经能够描述节点并获取节点的条件,但无法获取事件或CPU/内存信息。

英文:

I want to use go client to describe a node, to be specific I want to list the node condition types and it's status and also events.

Edit: I was able to describe the node and get node condition but not events or cpu/memory.

答案1

得分: 1

我找到了以下代码来获取节点的条件和状态,但没有事件。

nodes, _ := clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})

for _, node := range nodes.Items {
    fmt.Printf("%s\n", node.Name)

    for _, condition := range node.Status.Conditions {
        fmt.Printf("\t%s: %s\n", condition.Type, condition.Status)
    }
}

这段代码可以列出节点的名称以及每个节点的条件和状态。

英文:

I found below to get node conditions and status but not events.

nodes, _ := clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})

for _, node := range nodes.Items {
fmt.Printf("%s\n", node.Name)
	
        for _, condition := range node.Status.Conditions {
		fmt.Printf("\t%s: %s\n", condition.Type, condition.Status)
	}
}

huangapple
  • 本文由 发表于 2022年5月17日 10:29:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/72267543.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定