Skip to content

Commit

Permalink
Configure Loadbalancer back-end pool only for controlplane machines
Browse files Browse the repository at this point in the history
  • Loading branch information
carmal891 committed Oct 23, 2024
1 parent 7716671 commit d00e568
Show file tree
Hide file tree
Showing 3 changed files with 370 additions and 76 deletions.
2 changes: 1 addition & 1 deletion cloud/scope/powervs_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ func (m *PowerVSMachineScope) GetMachineInternalIP() string {
return ""
}

// CreateVPCLoadBalancerPoolMember creates a member in load balaner pool.
// CreateVPCLoadBalancerPoolMember creates a member in load balancer pool.
func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember() (*vpcv1.LoadBalancerPoolMember, error) { //nolint:gocyclo
loadBalancers := make([]infrav1beta2.VPCLoadBalancerSpec, 0)
if len(m.IBMPowerVSCluster.Spec.LoadBalancers) == 0 {
Expand Down
27 changes: 20 additions & 7 deletions controllers/ibmpowervsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ func (r *IBMPowerVSMachineReconciler) getOrCreate(scope *scope.PowerVSMachineSco
return instance, err
}

// handleLoadBalancerPoolMemberConfiguration handles loadbalancer pool member creation flow.
func (r *IBMPowerVSMachineReconciler) handleLoadBalancerPoolMemberConfiguration(machineScope *scope.PowerVSMachineScope) (ctrl.Result, error) {
poolMember, err := machineScope.CreateVPCLoadBalancerPoolMember()
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to create loadbalancer pool member %s: %w", machineScope.IBMPowerVSMachine.Name, err)
}
if poolMember != nil && *poolMember.ProvisioningStatus != string(infrav1beta2.VPCLoadBalancerStateActive) {
return ctrl.Result{RequeueAfter: 1 * time.Minute}, nil
}

return ctrl.Result{}, nil
}

func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerVSMachineScope) (ctrl.Result, error) {
machineScope.Info("Reconciling IBMPowerVSMachine")

Expand Down Expand Up @@ -286,15 +299,15 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerV
machineScope.Info("updating loadbalancer for machine", "name", machineScope.IBMPowerVSMachine.Name)
internalIP := machineScope.GetMachineInternalIP()
if internalIP == "" {
machineScope.Info("Unable to update the LoadBalancer, Machine internal IP not yet set", "machine name", machineScope.IBMPowerVSMachine.Name)
machineScope.Info("Unable to update the LoadBalancer, Machine internal IP not yet set", "machineName", machineScope.IBMPowerVSMachine.Name)
return ctrl.Result{}, nil
}
poolMember, err := machineScope.CreateVPCLoadBalancerPoolMember()
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed CreateVPCLoadBalancerPoolMember %s: %w", machineScope.IBMPowerVSMachine.Name, err)
}
if poolMember != nil && *poolMember.ProvisioningStatus != string(infrav1beta2.VPCLoadBalancerStateActive) {
return ctrl.Result{RequeueAfter: 1 * time.Minute}, nil

if util.IsControlPlaneMachine(machineScope.Machine) {
machineScope.Info("Configuring loadbalancer configuration for control plane machine", "machineName", machineScope.IBMPowerVSMachine.Name)
return r.handleLoadBalancerPoolMemberConfiguration(machineScope)
}
machineScope.Info("skipping loadbalancer configuration as it is not control plane machine", "machineName", machineScope.IBMPowerVSMachine.Name)

return ctrl.Result{}, nil
}
Loading

0 comments on commit d00e568

Please sign in to comment.