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

Configure Loadbalancer back-end pool only for controlplane machines #2004

Merged
Merged
Show file tree
Hide file tree
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
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create another issue for refactoring these functions to accept the context from caller, like reconcileNormal(ctx context.Context, machineScope *scope.PowerVSMachineScope)
We are not fully utilizing the contextual logging, May be this can be the first step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue created - #2018.
Updated portions using machinescope.Info to contextual logging

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

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 for worker machine", "machineName", machineScope.IBMPowerVSMachine.Name)

return ctrl.Result{}, nil
}
Loading