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 13, 2024
1 parent 7716671 commit f735079
Show file tree
Hide file tree
Showing 3 changed files with 453 additions and 8 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: 21 additions & 6 deletions controllers/ibmpowervsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ 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) {
if !util.IsControlPlaneMachine(machineScope.Machine) {
return ctrl.Result{}, nil
}
machineScope.Info("Configuring control plane machine to backend LoadBalancer pool", "machine name", machineScope.IBMPowerVSMachine.Name)
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
}

return ctrl.Result{}, nil
}

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

Expand Down Expand Up @@ -289,12 +306,10 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerV
machineScope.Info("Unable to update the LoadBalancer, Machine internal IP not yet set", "machine name", 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 poolMemberReconcileResult, err := r.handleLoadBalancerPoolMemberConfiguration(machineScope); err != nil || poolMemberReconcileResult.RequeueAfter > 0 {
return poolMemberReconcileResult, err
}

return ctrl.Result{}, nil
}
Loading

0 comments on commit f735079

Please sign in to comment.