【问题标题】:how to use client-go to get the Node status如何使用 client-go 获取 Node 状态
【发布时间】:2021-08-10 07:23:38
【问题描述】:

我这里目前有一个节点(node *corev1.Node),我想获取节点的状态以知道是否异常,所以我就这样做了

for _, statu := range node.Status.Conditions {
  if ! (statu.Type == corev1.NodeReady && statu.Status == corev1.ConditionTrue) {
    return errors.Errorf("Unavailable node")
  }
}

我不知道这是对的。如果是,有没有更好的办法解决?

【问题讨论】:

    标签: go kubernetes kubernetes-go-client


    【解决方案1】:

    您可以使用https://github.com/kubernetes/apimachinery/blob/c7322e8491689a1f601c606757b87a0cccfd2048/pkg/api/meta/conditions.go#L85中的助手

    IsStatusConditionTrue(node.Status.Conditions, corev1.NodeReady)
    

    【讨论】:

      猜你喜欢
      • 2019-05-20
      • 2020-11-22
      • 2019-12-09
      • 2019-11-08
      • 2017-11-03
      • 2018-11-27
      • 2015-11-17
      • 2019-01-29
      • 1970-01-01
      相关资源
      最近更新 更多