Skip to content

Commit

Permalink
Set unhealthyLimitKey for logging always
Browse files Browse the repository at this point in the history
Without this the controller is panicking as the logger expect every key to be a string
  • Loading branch information
enxebre committed Aug 18, 2021
1 parent 20ad71d commit 7060f75
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions controllers/machinehealthcheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
m.Status.CurrentHealthy = int32(len(healthy))

var unhealthyLimitKey, unhealthyLimitValue interface{}
if m.Spec.UnhealthyRange == nil {
unhealthyLimitKey = "max unhealthy"
unhealthyLimitValue = m.Spec.MaxUnhealthy
} else {
unhealthyLimitKey = "unhealthy range"
unhealthyLimitValue = *m.Spec.UnhealthyRange
}

// check MHC current health against MaxUnhealthy
remediationAllowed, remediationCount, err := isAllowedRemediation(m)
Expand All @@ -231,15 +238,11 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
var message string

if m.Spec.UnhealthyRange == nil {
unhealthyLimitKey = "max unhealthy"
unhealthyLimitValue = m.Spec.MaxUnhealthy
message = fmt.Sprintf("Remediation is not allowed, the number of not started or unhealthy machines exceeds maxUnhealthy (total: %v, unhealthy: %v, maxUnhealthy: %v)",
totalTargets,
len(unhealthy),
m.Spec.MaxUnhealthy)
} else {
unhealthyLimitKey = "unhealthy range"
unhealthyLimitValue = *m.Spec.UnhealthyRange
message = fmt.Sprintf("Remediation is not allowed, the number of not started or unhealthy machines does not fall within the range (total: %v, unhealthy: %v, unhealthyRange: %v)",
totalTargets,
len(unhealthy),
Expand Down

0 comments on commit 7060f75

Please sign in to comment.