Skip to content

Commit

Permalink
🌱 log name of server and lb (#1242)
Browse files Browse the repository at this point in the history
log name of server and lb

till now we only used numeric ID in logs which becomes sometimes hard
during debugging as things needs to cross checked.

Signed-off-by: kranurag7 <[email protected]>
  • Loading branch information
kranurag7 authored Apr 3, 2024
1 parent e7940d5 commit a5e6a12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/services/hcloud/remediation/remediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *Service) handlePhaseRunning(ctx context.Context, server *hcloud.Server)
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 reconcile.Result{}, fmt.Errorf("failed to reboot server %v: %w", server.ID, err)
return reconcile.Result{}, fmt.Errorf("failed to reboot server %s with ID %d: %w", server.Name, server.ID, err)
}
record.Event(s.scope.HCloudRemediation, "ServerRebooted", "Server has been rebooted")

Expand Down Expand Up @@ -124,7 +124,7 @@ func (s *Service) handlePhaseRunning(ctx context.Context, server *hcloud.Server)
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 reconcile.Result{}, fmt.Errorf("failed to reboot server %v: %w", server.ID, err)
return reconcile.Result{}, fmt.Errorf("failed to reboot server %s with ID %d: %w", server.Name, server.ID, err)
}
record.Event(s.scope.HCloudRemediation, "ServerRebooted", "Server has been rebooted")

Expand Down
20 changes: 10 additions & 10 deletions pkg/services/hcloud/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (s *Service) reconcileLoadBalancerAttachment(ctx context.Context, server *h
// remove server from load balancer if it's being deleted
if conditions.Has(s.scope.Machine, clusterv1.PreDrainDeleteHookSucceededCondition) {
if err := s.deleteServerOfLoadBalancer(ctx, server); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to delete server %d from loadbalancer: %w", server.ID, err)
return reconcile.Result{}, fmt.Errorf("failed to delete server %s with ID %d from loadbalancer: %w", server.Name, server.ID, err)
}
return reconcile.Result{}, nil
}
Expand Down Expand Up @@ -310,14 +310,14 @@ func (s *Service) reconcileLoadBalancerAttachment(ctx context.Context, server *h
if hcloud.IsError(err, hcloud.ErrorCodeTargetAlreadyDefined) {
return reconcile.Result{}, nil
}
return reconcile.Result{}, fmt.Errorf("failed to add server %d as target to load balancer: %w", server.ID, err)
return reconcile.Result{}, fmt.Errorf("failed to add server %s with ID %d as target to load balancer: %w", server.Name, server.ID, err)
}

record.Eventf(
s.scope.HetznerCluster,
"AddedAsTargetToLoadBalancer",
"Added new server with id %d to the loadbalancer %v",
server.ID, s.scope.HetznerCluster.Status.ControlPlaneLoadBalancer.ID)
"Added new server %s with ID %d to the loadbalancer %s with ID %d",
server.Name, server.ID, s.scope.HetznerCluster.Spec.ControlPlaneLoadBalancer.Name, s.scope.HetznerCluster.Status.ControlPlaneLoadBalancer.ID)

return reconcile.Result{}, nil
}
Expand Down Expand Up @@ -454,7 +454,7 @@ func (s *Service) createServer(ctx context.Context) (*hcloud.Server, error) {
}

conditions.MarkTrue(s.scope.HCloudMachine, infrav1.ServerCreateSucceededCondition)
record.Eventf(s.scope.HCloudMachine, "SuccessfulCreate", "Created new server with id %d", server.ID)
record.Eventf(s.scope.HCloudMachine, "SuccessfulCreate", "Created new server %s with ID %d", server.Name, server.ID)
return server, nil
}

Expand Down Expand Up @@ -507,7 +507,7 @@ func (s *Service) getServerImage(ctx context.Context) (*hcloud.Image, error) {
images = append(images, imagesByName...)

if len(images) > 1 {
err := fmt.Errorf("image is ambiguous - %v images have name %s", len(images), s.scope.HCloudMachine.Spec.ImageName)
err := fmt.Errorf("image is ambiguous - %d images have name %s", len(images), s.scope.HCloudMachine.Spec.ImageName)
record.Warnf(s.scope.HCloudMachine, "ImageNameAmbiguous", err.Error())
conditions.MarkFalse(s.scope.HCloudMachine,
infrav1.ServerCreateSucceededCondition,
Expand Down Expand Up @@ -631,13 +631,13 @@ func (s *Service) deleteServerOfLoadBalancer(ctx context.Context, server *hcloud
if strings.Contains(err.Error(), "load_balancer_target_not_found") {
return nil
}
return fmt.Errorf("failed to delete server %v as target of load balancer %v: %w", server.ID, lb.ID, err)
return fmt.Errorf("failed to delete server %s with ID %d as target of load balancer %s with ID %d: %w", server.Name, server.ID, lb.Name, lb.ID, err)
}
record.Eventf(
s.scope.HetznerCluster,
"DeletedTargetOfLoadBalancer",
"Deleted new server with id %d of the loadbalancer %v",
server.ID, lb.ID,
"Deleted new server %s with ID %d of the loadbalancer %s with ID %d",
server.Name, server.ID, lb.Name, lb.ID,
)

return nil
Expand Down Expand Up @@ -673,7 +673,7 @@ func (s *Service) findServer(ctx context.Context) (*hcloud.Server, error) {
}

if len(servers) > 1 {
err := fmt.Errorf("found %v servers with name %s", len(servers), s.scope.Name())
err := fmt.Errorf("found %d servers with name %s", len(servers), s.scope.Name())
record.Warnf(s.scope.HCloudMachine, "MultipleInstances", err.Error())
return nil, err
}
Expand Down

0 comments on commit a5e6a12

Please sign in to comment.