Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Migrating ./pkg/utils/openstack/loadbalancer.go to structured logging #1620

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pkg/cloud/services/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down