Skip to content

Commit

Permalink
only use loadbalaner reference if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jichenjc committed Sep 1, 2021
1 parent 4e178f0 commit da1f9f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
21 changes: 11 additions & 10 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ func reconcileDelete(ctx context.Context, log logr.Logger, client client.Client,
return reconcile.Result{}, err
}

loadBalancerService, err := loadbalancer.NewService(osProviderClient, clientOpts, log)
if err != nil {
return reconcile.Result{}, err
}

clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name)

if openStackCluster.Spec.ManagedAPIServerLoadBalancer {
loadBalancerService, err := loadbalancer.NewService(osProviderClient, clientOpts, log)
if err != nil {
return reconcile.Result{}, err
}

if err = loadBalancerService.DeleteLoadBalancer(openStackCluster, clusterName); err != nil {
handleUpdateOSCError(openStackCluster, errors.Errorf("failed to delete load balancer: %v", err))
return reconcile.Result{}, errors.Errorf("failed to delete load balancer: %v", err)
Expand Down Expand Up @@ -365,18 +365,14 @@ func reconcileBastion(log logr.Logger, osProviderClient *gophercloud.ProviderCli
}

func reconcileNetworkComponents(log logr.Logger, osProviderClient *gophercloud.ProviderClient, clientOpts *clientconfig.ClientOpts, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) error {
var loadBalancerService *loadbalancer.Service
clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name)

networkingService, err := networking.NewService(osProviderClient, clientOpts, log)
if err != nil {
return err
}

loadBalancerService, err := loadbalancer.NewService(osProviderClient, clientOpts, log)
if err != nil {
return err
}

log.Info("Reconciling network components")

err = networkingService.ReconcileExternalNetwork(openStackCluster)
Expand Down Expand Up @@ -468,6 +464,11 @@ func reconcileNetworkComponents(log logr.Logger, osProviderClient *gophercloud.P
}

if openStackCluster.Spec.ManagedAPIServerLoadBalancer {
loadBalancerService, err = loadbalancer.NewService(osProviderClient, clientOpts, log)
if err != nil {
return err
}

err = loadBalancerService.ReconcileLoadBalancer(openStackCluster, clusterName)
if err != nil {
handleUpdateOSCError(openStackCluster, errors.Errorf("failed to reconcile load balancer: %v", err))
Expand Down
9 changes: 5 additions & 4 deletions controllers/openstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,12 @@ func (r *OpenStackMachineReconciler) reconcileDelete(ctx context.Context, logger
return ctrl.Result{}, err
}

loadBalancerService, err := loadbalancer.NewService(osProviderClient, clientOpts, logger)
if err != nil {
return ctrl.Result{}, err
}
if openStackCluster.Spec.ManagedAPIServerLoadBalancer {
loadBalancerService, err := loadbalancer.NewService(osProviderClient, clientOpts, logger)
if err != nil {
return ctrl.Result{}, err
}

err = loadBalancerService.DeleteLoadBalancerMember(openStackCluster, machine, openStackMachine, clusterName)
if err != nil {
return ctrl.Result{}, err
Expand Down

0 comments on commit da1f9f3

Please sign in to comment.