Skip to content

Commit 2b9cda1

Browse files
Use internal error reason more consistently
# Conflicts: # api/v1beta1/machine_types.go
1 parent a4ff378 commit 2b9cda1

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

api/v1beta1/machine_types.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ const (
9898
// MachineWaitingForMinReadySecondsV1Beta2Reason surfaces when a machine is ready for less than MinReadySeconds (and thus not yet available).
9999
MachineWaitingForMinReadySecondsV1Beta2Reason = "WaitingForMinReadySeconds"
100100

101-
// MachineReadyNotYetReportedV1Beta2Reason surfaces when a machine ready is not reported yet.
102-
// Note: this should never happen and it is a signal of some internal error.
103-
MachineReadyNotYetReportedV1Beta2Reason = "ReadyNotYetReported"
104-
105101
// MachineAvailableV1Beta2Reason surfaces when a machine is ready for at least MinReadySeconds.
106102
// Note: MinReadySeconds is assumed 0 until it will be implemented in v1beta2 API.
107103
MachineAvailableV1Beta2Reason = AvailableV1Beta2Reason
104+
105+
// MachineAvailableInternalErrorV1Beta2Reason surfaces unexpected error when computing the Available condition.
106+
MachineAvailableInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
108107
)
109108

110109
// Machine's Ready condition and corresponding reasons that will be used in v1Beta2 API version.
@@ -115,9 +114,8 @@ const (
115114
// these conditions must be true as well.
116115
MachineReadyV1Beta2Condition = ReadyV1Beta2Condition
117116

118-
// MachineErrorComputingReadyV1Beta2Reason surfaces when there was an error computing the ready condition.
119-
// Note: this should never happen and it is a signal of some internal error.
120-
MachineErrorComputingReadyV1Beta2Reason = "ErrorComputingReady"
117+
// MachineReadyInternalErrorV1Beta2Reason surfaces unexpected error when computing the Ready condition.
118+
MachineReadyInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
121119
)
122120

123121
// Machine's UpToDate condition and corresponding reasons that will be used in v1Beta2 API version.

internal/controllers/machine/machine_controller_status.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func setBootstrapReadyCondition(_ context.Context, machine *clusterv1.Machine, b
114114
Status: metav1.ConditionUnknown,
115115
Reason: clusterv1.MachineBootstrapConfigInternalErrorV1Beta2Reason,
116116
Message: "Please check controller logs for errors",
117+
// NOTE: the error is logged by reconcileBootstrap.
117118
})
118119
return
119120
}
@@ -169,6 +170,7 @@ func setInfrastructureReadyCondition(_ context.Context, machine *clusterv1.Machi
169170
Status: metav1.ConditionUnknown,
170171
Reason: clusterv1.MachineInfrastructureInternalErrorV1Beta2Reason,
171172
Message: "Please check controller logs for errors",
173+
// NOTE: the error is logged by reconcileInfrastructure.
172174
})
173175
return
174176
}
@@ -276,13 +278,15 @@ func setNodeHealthyAndReadyConditions(ctx context.Context, machine *clusterv1.Ma
276278
Status: metav1.ConditionUnknown,
277279
Reason: clusterv1.MachineNodeInternalErrorV1Beta2Reason,
278280
Message: "Please check controller logs for errors",
281+
// NOTE: the error is logged by reconcileNode.
279282
})
280283

281284
v1beta2conditions.Set(machine, metav1.Condition{
282285
Type: clusterv1.MachineNodeHealthyV1Beta2Condition,
283286
Status: metav1.ConditionUnknown,
284287
Reason: clusterv1.MachineNodeInternalErrorV1Beta2Reason,
285288
Message: "Please check controller logs for errors",
289+
// NOTE: the error is logged by reconcileNode.
286290
})
287291
return
288292
}
@@ -592,14 +596,14 @@ func setReadyCondition(ctx context.Context, machine *clusterv1.Machine) {
592596
}
593597

594598
readyCondition, err := v1beta2conditions.NewSummaryCondition(machine, clusterv1.MachineReadyV1Beta2Condition, summaryOpts...)
595-
if err != nil || readyCondition == nil {
599+
if err != nil {
596600
// Note, this could only happen if we hit edge cases in computing the summary, which should not happen due to the fact
597601
// that we are passing a non empty list of ForConditionTypes.
598-
log.Error(err, "Failed to set ready condition")
602+
log.Error(err, "Failed to set Ready condition")
599603
readyCondition = &metav1.Condition{
600604
Type: clusterv1.MachineReadyV1Beta2Condition,
601605
Status: metav1.ConditionUnknown,
602-
Reason: clusterv1.MachineErrorComputingReadyV1Beta2Reason,
606+
Reason: clusterv1.MachineReadyInternalErrorV1Beta2Reason,
603607
Message: "Please check controller logs for errors",
604608
}
605609
}
@@ -650,16 +654,18 @@ func calculateDeletingConditionForSummary(machine *clusterv1.Machine) v1beta2con
650654
}
651655
}
652656

653-
func setAvailableCondition(_ context.Context, machine *clusterv1.Machine) {
657+
func setAvailableCondition(ctx context.Context, machine *clusterv1.Machine) {
658+
log := ctrl.LoggerFrom(ctx)
654659
readyCondition := v1beta2conditions.Get(machine, clusterv1.MachineReadyV1Beta2Condition)
655660

656661
if readyCondition == nil {
657662
// NOTE: this should never happen given that setReadyCondition is called before this method and
658663
// it always add a ready condition.
664+
log.Error(errors.New("Ready condition must be set before setting the available condition"), "Failed to set Available condition")
659665
v1beta2conditions.Set(machine, metav1.Condition{
660666
Type: clusterv1.MachineAvailableV1Beta2Condition,
661667
Status: metav1.ConditionUnknown,
662-
Reason: clusterv1.MachineReadyNotYetReportedV1Beta2Reason,
668+
Reason: clusterv1.MachineAvailableInternalErrorV1Beta2Reason,
663669
Message: "Please check controller logs for errors",
664670
})
665671
return

util/conditions/v1beta2/summary.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func NewSummaryCondition(sourceObj Getter, targetConditionType string, opts ...S
146146
Reason: reason,
147147
Message: message,
148148
// NOTE: LastTransitionTime and ObservedGeneration will be set when this condition is added to an object by calling Set.
149-
}, err
149+
}, nil
150150
}
151151

152152
// SetSummaryCondition is a convenience method that calls NewSummaryCondition to create a summary condition from the source object,

0 commit comments

Comments
 (0)