pkg/health/node.go
Rama main · réplica de lectura del repositorio original.
package health
import corev1 "k8s.io/api/core/v1"
// NodeHealth describes the health of a single node. It is richer than a Level
// (callers surface the individual signals), so Node returns the struct; map it
// to a Level at the call site if a coarse verdict is needed.
type NodeHealth struct {
Ready bool
Unschedulable bool
Pressures []string // "MemoryPressure", "DiskPressure", "PIDPressure"
Version string // kubelet version
Reason string // condition message if NotReady
}
// Node evaluates a node's conditions and spec.
func Node(node *corev1.Node) NodeHealth {
h := NodeHealth{
Unschedulable: node.Spec.Unschedulable,
Version: node.Status.NodeInfo.KubeletVersion,
}
for _, cond := range node.Status.Conditions {
switch cond.Type {
case corev1.NodeReady:
h.Ready = cond.Status == corev1.ConditionTrue
if !h.Ready && cond.Message != "" {
h.Reason = cond.Message
}
case corev1.NodeMemoryPressure:
if cond.Status == corev1.ConditionTrue {
h.Pressures = append(h.Pressures, "MemoryPressure")
}
case corev1.NodeDiskPressure:
if cond.Status == corev1.ConditionTrue {
h.Pressures = append(h.Pressures, "DiskPressure")
}
case corev1.NodePIDPressure:
if cond.Status == corev1.ConditionTrue {
h.Pressures = append(h.Pressures, "PIDPressure")
}
}
}
return h
}