Skip to content

Commit

Permalink
Refactor events
Browse files Browse the repository at this point in the history
Signed-off-by: Aniruddha Basak <[email protected]>
  • Loading branch information
aniruddha2000 committed Oct 17, 2023
1 parent cb8f745 commit 291176e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/services/baremetal/remediation/remediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ 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)
}
record.Event(s.scope.BareMetalRemediation, "AnnotationAdded", "Reboot annotation is added to the BareMetalHost")

if err := patchHelper.Patch(ctx, &host); err != nil {
return fmt.Errorf("failed to patch: %s %s/%s %w", host.Kind, host.Namespace, host.Name, err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/services/hcloud/remediation/remediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,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++
Expand All @@ -119,8 +121,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++
Expand Down

0 comments on commit 291176e

Please sign in to comment.