From 516eedcc385268dee4d93cac1f69ce883a99b43f Mon Sep 17 00:00:00 2001 From: fabriziopandini Date: Thu, 16 Jan 2025 12:55:46 +0100 Subject: [PATCH] Improve Machine remediation logs --- .../machinehealthcheck/machinehealthcheck_controller.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go index fefdeb86860d..34356c025e07 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go @@ -428,10 +428,11 @@ func (r *Reconciler) patchUnhealthyTargets(ctx context.Context, logger logr.Logg // mark for remediation errList := []error{} for _, t := range unhealthy { + logger := logger.WithValues("Machine", klog.KObj(t.Machine), "Node", klog.KObj(t.Node)) condition := conditions.Get(t.Machine, clusterv1.MachineHealthCheckSucceededCondition) if annotations.IsPaused(cluster, t.Machine) { - logger.Info("Machine has failed health check, but machine is paused so skipping remediation", "target", t.string(), "reason", condition.Reason, "message", condition.Message) + logger.Info("Machine has failed health check, but machine is paused so skipping remediation", "reason", condition.Reason, "message", condition.Message) } else { if m.Spec.RemediationTemplate != nil { // If external remediation request already exists, @@ -482,7 +483,7 @@ func (r *Reconciler) patchUnhealthyTargets(ctx context.Context, logger logr.Logg // the same Machine, users are in charge of setting health checks and remediation properly. to.SetName(t.Machine.Name) - logger.Info("Target has failed health check, creating an external remediation request", "remediation request name", to.GetName(), "target", t.string(), "reason", condition.Reason, "message", condition.Message) + logger.Info("Machine has failed health check, creating an external remediation request", "remediation request name", to.GetName(), condition.Reason, "message", condition.Message) // Create the external clone. if err := r.Client.Create(ctx, to); err != nil { conditions.MarkFalse(m, clusterv1.ExternalRemediationRequestAvailableCondition, clusterv1.ExternalRemediationRequestCreationFailedReason, clusterv1.ConditionSeverityError, err.Error()) @@ -503,7 +504,7 @@ func (r *Reconciler) patchUnhealthyTargets(ctx context.Context, logger logr.Logg Reason: clusterv1.MachineExternallyRemediatedWaitingForRemediationV1Beta2Reason, }) } else if t.Machine.DeletionTimestamp.IsZero() { // Only setting the OwnerRemediated conditions when machine is not already in deletion. - logger.Info("Target has failed health check, marking for remediation", "target", t.string(), "reason", condition.Reason, "message", condition.Message) + logger.Info("Machine has failed health check, marking for remediation", "reason", condition.Reason, "message", condition.Message) // NOTE: MHC is responsible for creating MachineOwnerRemediatedCondition if missing or to trigger another remediation if the previous one is completed; // instead, if a remediation is in already progress, the remediation owner is responsible for completing the process and MHC should not overwrite the condition. if !conditions.Has(t.Machine, clusterv1.MachineOwnerRemediatedCondition) || conditions.IsTrue(t.Machine, clusterv1.MachineOwnerRemediatedCondition) {