Skip to content

Commit 663a3eb

Browse files
author
Sedef
committed
Address comments
1 parent b184ddd commit 663a3eb

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

api/v1alpha3/condition_consts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const (
117117
)
118118

119119
const (
120-
// MachineOwnerRemediatedCondition is set on machines that have failed a healthcheck by the Machine's owner controller.
120+
// MachineOwnerRemediatedCondition is set on machines that have failed a healthcheck by the MachineHealthCheck controller.
121121
// MachineOwnerRemediatedCondition is set to False after a health check fails, but should be changed to True by the owning controller after remediation succeeds.
122122
MachineOwnerRemediatedCondition ConditionType = "OwnerRemediated"
123123

controllers/machine_controller_node.go

+19-18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/pkg/errors"
2424
apicorev1 "k8s.io/api/core/v1"
25+
kerrors "k8s.io/apimachinery/pkg/util/errors"
2526
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
2627
"sigs.k8s.io/cluster-api/controllers/noderefutil"
2728
capierrors "sigs.k8s.io/cluster-api/errors"
@@ -91,33 +92,33 @@ func (r *MachineReconciler) reconcileNode(ctx context.Context, cluster *clusterv
9192
}
9293

9394
// Do the remaining node health checks, then set the node health to true if all checks pass.
94-
if !checkNodeConditions(node) {
95-
conditions.MarkFalse(machine, clusterv1.MachineNodeHealthyCondition, clusterv1.NodeConditionsFailedReason, clusterv1.ConditionSeverityWarning, "")
95+
if err := hasHealthyNodeConditions(node); err != nil {
96+
conditions.MarkFalse(machine, clusterv1.MachineNodeHealthyCondition, clusterv1.NodeConditionsFailedReason, clusterv1.ConditionSeverityWarning, "Unhealthy conditions: %s", err.Error())
9697
return nil
9798
}
98-
conditions.MarkTrue(machine, clusterv1.MachineNodeHealthyCondition)
9999

100+
conditions.MarkTrue(machine, clusterv1.MachineNodeHealthyCondition)
100101
return nil
101102
}
102103

103-
// checkNodeConditions checks if a Node is healthy and does not have any semantically negative Conditions.
104-
// Returns true if NodeMemoryPressure, NodeDiskPressure, or NodePIDPressure Conditions are false or Ready Condition is true.
105-
func checkNodeConditions(node *apicorev1.Node) bool {
104+
// hasHealthyNodeConditions checks if a Node is healthy and does not have any semantically negative Conditions.
105+
// Returns error if NodeMemoryPressure, NodeDiskPressure, or NodePIDPressure Conditions are false or Ready Condition is true.
106+
func hasHealthyNodeConditions(node *apicorev1.Node) error {
107+
errList := []error{}
108+
106109
for _, condition := range node.Status.Conditions {
107-
if condition.Type == apicorev1.NodeMemoryPressure && condition.Status == apicorev1.ConditionTrue {
108-
return false
109-
}
110-
if condition.Type == apicorev1.NodeDiskPressure && condition.Status == apicorev1.ConditionTrue {
111-
return false
112-
}
113-
if condition.Type == apicorev1.NodePIDPressure && condition.Status == apicorev1.ConditionTrue {
114-
return false
115-
}
116-
if condition.Type == apicorev1.NodeReady && condition.Status == apicorev1.ConditionFalse {
117-
return false
110+
switch condition.Type {
111+
case apicorev1.NodeMemoryPressure, apicorev1.NodeDiskPressure, apicorev1.NodePIDPressure:
112+
if condition.Status == apicorev1.ConditionTrue {
113+
errList = append(errList, errors.Errorf("Condition %s is true on Node: %s", condition.Type, node.Name))
114+
}
115+
case apicorev1.NodeReady:
116+
if condition.Status == apicorev1.ConditionFalse {
117+
errList = append(errList, errors.Errorf("Condition %s is false on Node: %s", condition.Type, node.Name))
118+
}
118119
}
119120
}
120-
return true
121+
return kerrors.NewAggregate(errList)
121122
}
122123

123124
func (r *MachineReconciler) getNode(c client.Reader, providerID *noderefutil.ProviderID) (*apicorev1.Node, error) {

controllers/machine_controller_node_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,20 @@ func TestGetNodeReference(t *testing.T) {
108108
providerID, err := noderefutil.NewProviderID(test.providerID)
109109
gt.Expect(err).NotTo(HaveOccurred(), "Expected no error parsing provider id %q, got %v", test.providerID, err)
110110

111-
reference, err := r.getNode(client, providerID)
111+
node, err := r.getNode(client, providerID)
112112
if test.err == nil {
113113
g.Expect(err).To(BeNil())
114114
} else {
115115
gt.Expect(err).NotTo(BeNil())
116116
gt.Expect(err).To(Equal(test.err), "Expected error %v, got %v", test.err, err)
117117
}
118118

119-
if test.expected == nil && reference == nil {
119+
if test.expected == nil && node == nil {
120120
return
121121
}
122122

123-
gt.Expect(reference.Name).To(Equal(test.expected.Name), "Expected NodeRef's name to be %v, got %v", reference.Name, test.expected.Name)
124-
gt.Expect(reference.Namespace).To(Equal(test.expected.Namespace), "Expected NodeRef's namespace to be %v, got %v", reference.Namespace, test.expected.Namespace)
123+
gt.Expect(node.Name).To(Equal(test.expected.Name), "Expected NodeRef's name to be %v, got %v", node.Name, test.expected.Name)
124+
gt.Expect(node.Namespace).To(Equal(test.expected.Namespace), "Expected NodeRef's namespace to be %v, got %v", node.Namespace, test.expected.Namespace)
125125
})
126126

127127
}

0 commit comments

Comments
 (0)