diff --git a/pkg/services/baremetal/remediation/remediation.go b/pkg/services/baremetal/remediation/remediation.go index bbc14b4df..fda58aa73 100644 --- a/pkg/services/baremetal/remediation/remediation.go +++ b/pkg/services/baremetal/remediation/remediation.go @@ -60,7 +60,7 @@ func (s *Service) Reconcile(ctx context.Context) (res reconcile.Result, err erro record.Warn(s.scope.BareMetalRemediation, "FailedSettingConditionOnMachine", err.Error()) return res, err } - record.Eventf(s.scope.BareMetalRemediation, "ExitRemediation", "exit remediation because bare metal machine has no host annotation") + record.Event(s.scope.BareMetalRemediation, "ExitRemediation", "exit remediation because bare metal machine has no host annotation") return res, nil } @@ -158,6 +158,7 @@ func (s *Service) remediate(ctx context.Context, host infrav1.HetznerBareMetalHo // add annotation to host so that it reboots host.Annotations, err = addRebootAnnotation(host.Annotations) if err != nil { + record.Warn(s.scope.BareMetalRemediation, "FailedAddingRebootAnnotation", err.Error()) return fmt.Errorf("failed to add reboot annotation: %w", err) } @@ -165,6 +166,8 @@ func (s *Service) remediate(ctx context.Context, host infrav1.HetznerBareMetalHo return fmt.Errorf("failed to patch: %s %s/%s %w", host.Kind, host.Namespace, host.Name, err) } + record.Event(s.scope.BareMetalRemediation, "AnnotationAdded", "Reboot annotation is added to the BareMetalHost") + // update status of BareMetalRemediation object now := metav1.Now() s.scope.BareMetalRemediation.Status.LastRemediated = &now @@ -191,6 +194,7 @@ func (s *Service) handlePhaseWaiting(ctx context.Context) (res reconcile.Result, record.Warn(s.scope.BareMetalRemediation, "FailedSettingConditionOnMachine", err.Error()) return res, err } + record.Event(s.scope.BareMetalRemediation, "SetOwnerRemediatedCondition", "because retryLimit is reached and reboot timed out") return res, nil } diff --git a/pkg/services/hcloud/remediation/remediation.go b/pkg/services/hcloud/remediation/remediation.go index 74102cd41..f78e12d01 100644 --- a/pkg/services/hcloud/remediation/remediation.go +++ b/pkg/services/hcloud/remediation/remediation.go @@ -58,8 +58,10 @@ func (s *Service) Reconcile(ctx context.Context) (res reconcile.Result, err erro s.scope.HCloudRemediation.Status.Phase = infrav1.PhaseDeleting if err := s.setOwnerRemediatedCondition(ctx); err != nil { + record.Warn(s.scope.HCloudRemediation, "FailedSettingConditionOnMachine", err.Error()) return res, fmt.Errorf("failed to set conditions on CAPI machine: %w", err) } + record.Warn(s.scope.HCloudRemediation, "ExitRemediation", "exit remediation because bare metal server does not exist") return res, nil } @@ -93,8 +95,10 @@ func (s *Service) handlePhaseRunning(ctx context.Context, server *hcloud.Server) if s.scope.HCloudRemediation.Status.LastRemediated == nil { if err := s.scope.HCloudClient.RebootServer(ctx, server); err != nil { hcloudutil.HandleRateLimitExceeded(s.scope.HCloudMachine, err, "RebootServer") + record.Warn(s.scope.HCloudRemediation, "FailedRebootServer", err.Error()) return res, fmt.Errorf("failed to reboot server %v: %w", server.ID, err) } + record.Event(s.scope.HCloudRemediation, "ServerRebooted", "Server has been rebooted") s.scope.HCloudRemediation.Status.LastRemediated = &now s.scope.HCloudRemediation.Status.RetryCount++ @@ -119,8 +123,10 @@ func (s *Service) handlePhaseRunning(ctx context.Context, server *hcloud.Server) // remediate now if err := s.scope.HCloudClient.RebootServer(ctx, server); err != nil { hcloudutil.HandleRateLimitExceeded(s.scope.HCloudMachine, err, "RebootServer") + record.Warn(s.scope.HCloudRemediation, "FailedRebootServer", err.Error()) return res, fmt.Errorf("failed to reboot server %v: %w", server.ID, err) } + record.Event(s.scope.HCloudRemediation, "ServerRebooted", "Server has been rebooted") s.scope.HCloudRemediation.Status.LastRemediated = &now s.scope.HCloudRemediation.Status.RetryCount++ @@ -143,8 +149,10 @@ func (s *Service) handlePhaseWaiting(ctx context.Context) (res reconcile.Result, s.scope.HCloudRemediation.Status.Phase = infrav1.PhaseDeleting if err := s.setOwnerRemediatedCondition(ctx); err != nil { + record.Warn(s.scope.HCloudRemediation, "FailedSettingConditionOnMachine", err.Error()) return res, fmt.Errorf("failed to set conditions on CAPI machine: %w", err) } + record.Event(s.scope.HCloudRemediation, "SetOwnerRemediatedCondition", "exit remediation because because retryLimit is reached and reboot timed out") return res, nil }