From f312e2c01da35f2fec21ef52a21a943a2b0b6a5a Mon Sep 17 00:00:00 2001 From: Anastasiia Runova <105672564+anastaruno@users.noreply.github.com> Date: Mon, 24 Jul 2023 14:40:23 -0400 Subject: [PATCH] Migrating cluster-api-provider-openstack/pkg/utils/openstack/loadbalancer.go to structured logging. Fixing the format of the log messages and log parameters. --- .../services/loadbalancer/loadbalancer.go | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/cloud/services/loadbalancer/loadbalancer.go b/pkg/cloud/services/loadbalancer/loadbalancer.go index 0d7bb5b180..8095a8bbe8 100644 --- a/pkg/cloud/services/loadbalancer/loadbalancer.go +++ b/pkg/cloud/services/loadbalancer/loadbalancer.go @@ -48,7 +48,7 @@ const loadBalancerProvisioningStatusActive = "ACTIVE" func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackCluster, clusterName string, apiServerPort int) (bool, error) { loadBalancerName := getLoadBalancerName(clusterName) - s.scope.Logger().Info("Reconciling load balancer", "name", loadBalancerName) + s.scope.Logger().Info("Reconciling load balancer", "loadBalancerName", loadBalancerName) var fixedIPAddress string switch { @@ -169,7 +169,7 @@ func (s *Service) getOrCreateLoadBalancer(openStackCluster *infrav1.OpenStackClu return lb, nil } - s.scope.Logger().Info(fmt.Sprintf("Creating load balancer in subnet: %q", subnetID), "name", loadBalancerName) + s.scope.Logger().Info("Creating load balancer in subnet", "subnetID", subnetID, "loadBalancerName", loadBalancerName) lbCreateOpts := loadbalancers.CreateOpts{ Name: loadBalancerName, @@ -199,7 +199,7 @@ func (s *Service) getOrCreateListener(openStackCluster *infrav1.OpenStackCluster return listener, nil } - s.scope.Logger().Info("Creating load balancer listener", "name", listenerName, "lb-id", lbID) + s.scope.Logger().Info("Creating load balancer listener", "listenerName", listenerName, "loadBalancerID", lbID) listenerCreateOpts := listeners.CreateOpts{ Name: listenerName, @@ -316,7 +316,7 @@ func (s *Service) getOrCreatePool(openStackCluster *infrav1.OpenStackCluster, po return pool, nil } - s.scope.Logger().Info(fmt.Sprintf("Creating load balancer pool for listener %q", listenerID), "name", poolName, "lb-id", lbID) + s.scope.Logger().Info("Creating load balancer pool for listener", "listenerID", listenerID, "poolName", poolName, "loadBalancerID", lbID) method := pools.LBMethodRoundRobin @@ -356,7 +356,7 @@ func (s *Service) getOrCreateMonitor(openStackCluster *infrav1.OpenStackCluster, return nil } - s.scope.Logger().Info(fmt.Sprintf("Creating load balancer monitor for pool %q", poolID), "name", monitorName, "lb-id", lbID) + s.scope.Logger().Info("Creating load balancer monitor for pool", "poolID", poolID, "monitorName", monitorName, "loadBalancerID", lbID) monitorCreateOpts := monitors.CreateOpts{ Name: monitorName, @@ -400,7 +400,7 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac } loadBalancerName := getLoadBalancerName(clusterName) - s.scope.Logger().Info("Reconciling load balancer member", "name", loadBalancerName) + s.scope.Logger().Info("Reconciling load balancer member", "loadBalancerName", loadBalancerName) lbID := openStackCluster.Status.APIServerLoadBalancer.ID portList := []int{int(openStackCluster.Spec.ControlPlaneEndpoint.Port)} @@ -429,7 +429,7 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac continue } - s.scope.Logger().Info("Deleting load balancer member (because the IP of the machine changed)", "name", name) + s.scope.Logger().Info("Deleting load balancer member because the IP of the machine changed", "loadBalancerMemberName", name) // lb member changed so let's delete it so we can create it again with the correct IP err = s.waitForLoadBalancerActive(lbID) @@ -445,7 +445,7 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac } } - s.scope.Logger().Info("Creating load balancer member", "name", name) + s.scope.Logger().Info("Creating load balancer member", "loadBalancerMemberName", name) // if we got to this point we should either create or re-create the lb member lbMemberOpts := pools.CreateMemberOpts{ @@ -500,7 +500,7 @@ func (s *Service) DeleteLoadBalancer(openStackCluster *infrav1.OpenStackCluster, deleteOpts := loadbalancers.DeleteOpts{ Cascade: true, } - s.scope.Logger().Info("Deleting load balancer", "name", loadBalancerName, "cascade", deleteOpts.Cascade) + s.scope.Logger().Info("Deleting load balancer", "loadBalancerName", loadBalancerName, "cascade", deleteOpts.Cascade) err = s.loadbalancerClient.DeleteLoadBalancer(lb.ID, deleteOpts) if err != nil && !capoerrors.IsNotFound(err) { record.Warnf(openStackCluster, "FailedDeleteLoadBalancer", "Failed to delete load balancer %s with id %s: %v", lb.Name, lb.ID, err) @@ -539,7 +539,7 @@ func (s *Service) DeleteLoadBalancerMember(openStackCluster *infrav1.OpenStackCl return err } if pool == nil { - s.scope.Logger().Info("Load balancer pool does not exist", "name", lbPortObjectsName) + s.scope.Logger().Info("Load balancer pool does not exist", "poolName", lbPortObjectsName) continue } @@ -634,7 +634,7 @@ var backoff = wait.Backoff{ // Possible LoadBalancer states are documented here: https://docs.openstack.org/api-ref/load-balancer/v2/index.html#prov-status func (s *Service) waitForLoadBalancerActive(id string) error { - s.scope.Logger().Info("Waiting for load balancer", "id", id, "targetStatus", "ACTIVE") + s.scope.Logger().Info("Waiting for load balancer", "loadBalancerID", id, "targetStatus", "ACTIVE") return wait.ExponentialBackoff(backoff, func() (bool, error) { lb, err := s.loadbalancerClient.GetLoadBalancer(id) if err != nil { @@ -645,7 +645,7 @@ func (s *Service) waitForLoadBalancerActive(id string) error { } func (s *Service) waitForListener(id, target string) error { - s.scope.Logger().Info("Waiting for load balancer listener", "id", id, "targetStatus", target) + s.scope.Logger().Info("Waiting for load balancer listener", "listenerID", id, "targetStatus", target) return wait.ExponentialBackoff(backoff, func() (bool, error) { _, err := s.loadbalancerClient.GetListener(id) if err != nil {