使用 Kubernetes client-go 如何以编程方式检查 Node 是否为 "Ready"?

Using Kubernetes client-go how to check programatically if Node is "Ready"?

看来我可能需要遍历v1.Node->NodeStatus->Conditions[]分片,按过渡时间排序,看最近的定时条件是不是NodeConditionType == "Ready"。我想知道是否有更好的方法或者该方法是否有缺陷?

在我的情况下,我启用了 TaintBasedEvictions and TaintNodesByCondition 特性门,k8s 节点控制器会自动在节点上添加一些污点(例如 node.kubernetes.io/not-readynode.kubernetes.io/unreachable),我只需要观察节点,并检查污点。

您找对地方了,但条件可能并不完全按照您的问题所暗示的方式工作。条件不应被视为基于时间的事件,而是当前状态。引用 API conventions documentation:

Conditions represent the latest available observations of an object's state.

因此,不必查找最新的条件,而是查找您有兴趣观察的状态类型的条件。应该只有一个 NodeConditionTypeReady,但是你需要检查 NodeCondition 上的 .Status 字段来确认它的值是否是 TrueFalseUnknown.