diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_targets.go b/internal/controllers/machinehealthcheck/machinehealthcheck_targets.go index bdd9c5861f2a..b02c27049c53 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_targets.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_targets.go @@ -120,6 +120,10 @@ func (t *healthCheckTarget) needsRemediation(logger logr.Logger, timeoutForMachi return false, 0 } + if conditions.Get(t.Cluster, clusterv1.ControlPlaneInitializedCondition) == nil { + return false, 0 + } + // Don't penalize any Machine/Node if the cluster infrastructure is not ready. if !conditions.IsTrue(t.Cluster, clusterv1.InfrastructureReadyCondition) { logger.V(3).Info("Not evaluating target health because the cluster infrastructure is not ready") @@ -135,18 +139,18 @@ func (t *healthCheckTarget) needsRemediation(logger logr.Logger, timeoutForMachi return false, 0 } - controlPlaneInitializedTime := conditions.GetLastTransitionTime(t.Cluster, clusterv1.ControlPlaneInitializedCondition).Time - clusterInfraReadyTime := conditions.GetLastTransitionTime(t.Cluster, clusterv1.InfrastructureReadyCondition).Time + controlPlaneInitialized := conditions.GetLastTransitionTime(t.Cluster, clusterv1.ControlPlaneInitializedCondition) + clusterInfraReady := conditions.GetLastTransitionTime(t.Cluster, clusterv1.InfrastructureReadyCondition) machineCreationTime := t.Machine.CreationTimestamp.Time // Use the latest of the 3 times comparisonTime := machineCreationTime - logger.V(3).Info("Determining comparison time", "machineCreationTime", machineCreationTime, "clusterInfraReadyTime", clusterInfraReadyTime, "controlPlaneInitializedTime", controlPlaneInitializedTime) - if controlPlaneInitializedTime.After(comparisonTime) { - comparisonTime = controlPlaneInitializedTime + logger.V(3).Info("Determining comparison time", "machineCreationTime", machineCreationTime, "clusterInfraReadyTime", clusterInfraReady, "controlPlaneInitializedTime", controlPlaneInitialized) + if controlPlaneInitialized != nil && controlPlaneInitialized.Time.After(comparisonTime) { + comparisonTime = controlPlaneInitialized.Time } - if clusterInfraReadyTime.After(comparisonTime) { - comparisonTime = clusterInfraReadyTime + if clusterInfraReady != nil && clusterInfraReady.Time.After(comparisonTime) { + comparisonTime = clusterInfraReady.Time } logger.V(3).Info("Using comparison time", "time", comparisonTime)