Skip to content

Commit

Permalink
Refine v1beta2 NodeHealthy condition
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Nov 28, 2024
1 parent 721b6cf commit d8fd3b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 10 additions & 0 deletions internal/controllers/machine/machine_controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -426,6 +427,8 @@ func summarizeNodeV1Beta2Conditions(_ context.Context, node *corev1.Node) (metav
semanticallyFalseStatus := 0
unknownStatus := 0

conditionCount := 0
conditionMessages := sets.Set[string]{}
messages := []string{}
for _, conditionType := range []corev1.NodeConditionType{corev1.NodeReady, corev1.NodeMemoryPressure, corev1.NodeDiskPressure, corev1.NodePIDPressure} {
var condition *corev1.NodeCondition
Expand All @@ -447,6 +450,8 @@ func summarizeNodeV1Beta2Conditions(_ context.Context, node *corev1.Node) (metav
if m == "" {
m = fmt.Sprintf("Condition is %s", condition.Status)
}
conditionCount++
conditionMessages.Insert(m)
messages = append(messages, fmt.Sprintf("* Node.%s: %s", condition.Type, m))
if condition.Status == corev1.ConditionUnknown {
unknownStatus++
Expand All @@ -461,6 +466,8 @@ func summarizeNodeV1Beta2Conditions(_ context.Context, node *corev1.Node) (metav
if m == "" {
m = fmt.Sprintf("Condition is %s", condition.Status)
}
conditionCount++
conditionMessages.Insert(m)
messages = append(messages, fmt.Sprintf("* Node.%s: %s", condition.Type, m))
if condition.Status == corev1.ConditionUnknown {
unknownStatus++
Expand All @@ -471,6 +478,9 @@ func summarizeNodeV1Beta2Conditions(_ context.Context, node *corev1.Node) (metav
}
}

if conditionCount > 1 && len(conditionMessages) == 1 {
messages = []string{fmt.Sprintf("* Node.AllConditions: %s", conditionMessages.UnsortedList()[0])}
}
message := strings.Join(messages, "\n")
if semanticallyFalseStatus > 0 {
return metav1.ConditionFalse, clusterv1.MachineNodeNotHealthyV1Beta2Reason, message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,9 @@ func TestSummarizeNodeV1Beta2Conditions(t *testing.T) {
{Type: corev1.NodeDiskPressure, Status: corev1.ConditionUnknown, Message: "Node is not reporting status"},
{Type: corev1.NodePIDPressure, Status: corev1.ConditionUnknown, Message: "Node is not reporting status"},
},
expectedStatus: metav1.ConditionUnknown,
expectedReason: clusterv1.MachineNodeHealthUnknownV1Beta2Reason,
expectedMessage: "* Node.Ready: Node is not reporting status\n" +
"* Node.MemoryPressure: Node is not reporting status\n" +
"* Node.DiskPressure: Node is not reporting status\n" +
"* Node.PIDPressure: Node is not reporting status",
expectedStatus: metav1.ConditionUnknown,
expectedReason: clusterv1.MachineNodeHealthUnknownV1Beta2Reason,
expectedMessage: "* Node.AllConditions: Node is not reporting status",
},
{
name: "multiple semantically failed condition",
Expand Down

0 comments on commit d8fd3b5

Please sign in to comment.