Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kubernetes-sigs/cluster-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7060f75fe81acb8ee858ee5dec3d6b53771417b6
Choose a base ref
..
head repository: kubernetes-sigs/cluster-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8b783c4f4137d7848d1514b88f125b43d90560ef
Choose a head ref
Showing with 27 additions and 22 deletions.
  1. +27 −22 controllers/machinehealthcheck_controller.go
49 changes: 27 additions & 22 deletions controllers/machinehealthcheck_controller.go
Original file line number Diff line number Diff line change
@@ -219,15 +219,6 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
healthy, unhealthy, nextCheckTimes := r.healthCheckTargets(targets, logger, *nodeStartupTimeout)
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)
if err != nil {
@@ -238,24 +229,29 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
var message string

if m.Spec.UnhealthyRange == nil {
logger.V(3).Info(
"Short-circuiting remediation",
"total target", totalTargets,
"max unhealthy", m.Spec.MaxUnhealthy,
"unhealthy targets", len(unhealthy),
)
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 {
logger.V(3).Info(
"Short-circuiting remediation",
"total target", totalTargets,
"unhealthy range", *m.Spec.UnhealthyRange,
"unhealthy targets", len(unhealthy),
)
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),
*m.Spec.UnhealthyRange)
}

logger.V(3).Info(
"Short-circuiting remediation",
"total target", totalTargets,
unhealthyLimitKey, unhealthyLimitValue,
"unhealthy targets", len(unhealthy),
)

// Remediation not allowed, the number of not started or unhealthy machines either exceeds maxUnhealthy (or) not within unhealthyRange
m.Status.RemediationsAllowed = 0
conditions.Set(m, &clusterv1.Condition{
@@ -285,12 +281,21 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
return reconcile.Result{Requeue: true}, nil
}

logger.V(3).Info(
"Remediations are allowed",
"total target", totalTargets,
unhealthyLimitKey, unhealthyLimitValue,
"unhealthy targets", len(unhealthy),
)
if m.Spec.UnhealthyRange == nil {
logger.V(3).Info(
"Remediations are allowed",
"total target", totalTargets,
"max unhealthy", m.Spec.MaxUnhealthy,
"unhealthy targets", len(unhealthy),
)
} else {
logger.V(3).Info(
"Remediations are allowed",
"total target", totalTargets,
"unhealthy range", *m.Spec.UnhealthyRange,
"unhealthy targets", len(unhealthy),
)
}

// Remediation is allowed so unhealthyMachineCount is within unhealthyRange (or) maxUnhealthy - unhealthyMachineCount >= 0
m.Status.RemediationsAllowed = remediationCount