From a5e6a127226dabafcc8edf9764f4f700b61a49fd Mon Sep 17 00:00:00 2001 From: kranurag7 <81210977+kranurag7@users.noreply.github.com> Date: Wed, 3 Apr 2024 16:40:57 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20log=20name=20of=20server=20and?= =?UTF-8?q?=20lb=20(#1242)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../hcloud/remediation/remediation.go | 4 ++-- pkg/services/hcloud/server/server.go | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/services/hcloud/remediation/remediation.go b/pkg/services/hcloud/remediation/remediation.go index 1d13cf9bd..b54e83a36 100644 --- a/pkg/services/hcloud/remediation/remediation.go +++ b/pkg/services/hcloud/remediation/remediation.go @@ -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") @@ -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") diff --git a/pkg/services/hcloud/server/server.go b/pkg/services/hcloud/server/server.go index 42ea873a0..92957c2ba 100644 --- a/pkg/services/hcloud/server/server.go +++ b/pkg/services/hcloud/server/server.go @@ -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 } @@ -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 } @@ -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 } @@ -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, @@ -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 @@ -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 }