-
Notifications
You must be signed in to change notification settings - Fork 84
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
Configure Loadbalancer back-end pool only for controlplane machines #2004
Conversation
|
Hi @carmal891. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
✅ Deploy Preview for kubernetes-sigs-cluster-api-ibmcloud ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
ded3687
to
f735079
Compare
/ok-to-test |
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about machineScope.handleLoadBalancerPoolMemberConfiguration()
? or just calling util.IsControlPlaneMachine(machineScope.Machine)
here itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Karthik-K-N The handleLoadBalancerPoolMemberConfiguration was introduced more on the lines of a helper func that handles 1. controlPlaneMachine check, 2. machineScope.CreateVPCLoadBalancerPoolMember and 3. check if poolmember provisioning status is not active. So may not be apt to add as a single responsibility function that is similar to the existing machineScope methods.
To your second question, we could go with something like this
if util.IsControlPlaneMachine(machineScope.Machine) { return r.handleLoadBalancerPoolMemberConfiguration(machineScope) }
because adding all the conditions on the parent will cause the current cyclomatic complexity to cross threshold. Let me know your opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated as discussed
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be lets use log.V(3) to log that we are skipping loadbalancer configuration as its not control plane machine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if !util.IsControlPlaneMachine(machineScope.Machine) { | ||
return ctrl.Result{}, nil | ||
} | ||
machineScope.Info("Configuring control plane machine to backend LoadBalancer pool", "machine name", machineScope.IBMPowerVSMachine.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its better use single name for key in logs, like machineName
instead of machine name
, It might be easy to filter out in observability tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
g := NewWithT(t) | ||
setup(t) | ||
t.Cleanup(teardown) | ||
secret := &corev1.Secret{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since secret, pvsmachine, machine used at multiple tests, can we move this to helper function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
|
||
mockclient := fake.NewClientBuilder().WithObjects([]client.Object{secret, pvsmachine, machine}...).Build() | ||
machineScope = &scope.PowerVSMachineScope{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we call NewPowerVSMachineScope()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I’m wrong, but based on issue #1937, it’s preferred for UT not to rely on the New functions, as their flow shouldn't be within the scope of the parent test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, It would be good if can reduce the number of duplicate lines if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduced overall lines of code
1948e33
to
36c6127
Compare
func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerVSMachineScope) (ctrl.Result, error) { | ||
ctx := context.Background() | ||
log := ctrl.LoggerFrom(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log := ctrl.LoggerFrom(ctx) | |
log := ctrl.LoggerFrom(context.Background()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerVSMachineScope) (ctrl.Result, error) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
return ctrl.Result{RequeueAfter: 1 * time.Minute}, nil | ||
|
||
if util.IsControlPlaneMachine(machineScope.Machine) { | ||
log.V(3).Info("skipping loadbalancer configuration as it is not control plane machine", "machineName", machineScope.IBMPowerVSMachine.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of control plane machines we are configuring LB, So lets log that here and move this out of if block for better debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misplaced the logging statement. Corrected
719512a
to
f7a9497
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
LGTM
/assign @Amulyam24 |
/easycla |
1 similar comment
/easycla |
Please squash the commits. LGTM from my side. Thank you. |
368001b
to
d00e568
Compare
done |
/lgtm /assign @Amulyam24 @Prajyot-Parab |
} | ||
machineScope.Info("skipping loadbalancer configuration as it is not control plane machine", "machineName", machineScope.IBMPowerVSMachine.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
machineScope.Info("skipping loadbalancer configuration as it is not control plane machine", "machineName", machineScope.IBMPowerVSMachine.Name) | |
machineScope.Info("skipping loadbalancer configuration for worker machine", "machineName", machineScope.IBMPowerVSMachine.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
d00e568
to
a469601
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: carmal891, Prajyot-Parab The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #1990