Skip to content

Conversation

komer3
Copy link
Contributor

@komer3 komer3 commented Aug 6, 2025

General:

  • Have you removed all sensitive information, including but not limited to access keys and passwords?
  • Have you checked to ensure there aren't other open or closed Pull Requests for the same bug/feature/question?

Pull Request Guidelines:

  1. Does your submission pass tests?
  2. Have you added tests?
  3. Are you addressing a single feature in this PR?
  4. Are your commits atomic, addressing one change per commit?
  5. Are you following the conventions of the language?
  6. Have you saved your large formatting changes for a different PR, so we can focus on your work?
  7. Have you explained your rationale for why this feature is needed?
  8. Have you linked your PR to an open issue

@github-actions github-actions bot added the improvement for improvements in existing functionality in the changelog. label Aug 6, 2025
@komer3 komer3 requested a review from Copilot August 6, 2025 14:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the load balancer implementation to support external exports while improving code structure and adding functionality for load balancers without backend nodes.

  • Exports the Loadbalancers struct and related constructors to enable external usage
  • Adds support for empty NodeBalancer backends through a new command-line flag
  • Restructures global Options variable to improve testability and configuration management

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
main.go Adds new command-line flag for allowing empty NodeBalancer backends
cloud/linode/loadbalancers.go Major refactoring: exports Loadbalancers struct, adds Options field, implements support for empty backends
cloud/linode/service_controller.go Updates type references to use exported Loadbalancers type
cloud/linode/cloud.go Converts global Options to typed structure and updates constructor calls
cloud/linode/loadbalancers_test.go Updates all test code to use new exported types and constructors
cloud/linode/service_controller_test.go Updates test code to use new exported types
cloud/linode/cloud_test.go Updates test code to use new exported constructor
cloud/linode/cilium_loadbalancers_test.go Updates test instantiation to include Options field
cloud/linode/cilium_loadbalancers.go Updates method receivers to use exported Loadbalancers type

ctx context.Context,
clusterName string,
service *v1.Service,
nodes []*v1.Node,
nb *linodego.NodeBalancer,
) (err error) {
if len(nodes) == 0 {
if len(nodes) == 0 && !l.Options.AllowEmptyNodeBalancerBackends {
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

The condition should check if AllowEmptyNodeBalancerBackends is false before returning an error, but the logic seems reversed. If AllowEmptyNodeBalancerBackends is true, we should allow empty nodes; if false, we should return an error. The current logic appears correct but could be clearer with explicit boolean comparison.

Suggested change
if len(nodes) == 0 && !l.Options.AllowEmptyNodeBalancerBackends {
if len(nodes) == 0 && l.Options.AllowEmptyNodeBalancerBackends == false {

Copilot uses AI. Check for mistakes.

if len(nodes) == 0 && l.Options.AllowEmptyNodeBalancerBackends {
klog.Warningf("Creating NodeBalancer for service (%s) without backend nodes - load balancer will be non-functional until nodes are added", getServiceNn(service))
}

Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

This validation logic is duplicated between updateNodeBalancer and buildLoadBalancerRequest methods. Consider extracting this into a helper method to avoid code duplication and ensure consistent behavior.

Suggested change
if err := l.validateNodeBalancerNodes(nodes, clusterName, service); err != nil {
return nil, err
}

Copilot uses AI. Check for mistakes.

svc.Status.LoadBalancer = *makeLoadBalancerStatus(svc, nb1)
svcAnn.Status.LoadBalancer = *makeLoadBalancerStatus(svcAnn, nb1)
lb, assertion := newLoadbalancers(client, region).(*loadbalancers)
lb, assertion := NewLoadbalancers(client, region).(*Loadbalancers)
if !assertion {
t.Error("type assertion failed")
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

The order of operations changed here - NewLoadbalancers is called before makeLoadBalancerStatus, but makeLoadBalancerStatus needs the lb instance to call the method. This could cause issues if the constructor behavior changes.

Suggested change
t.Error("type assertion failed")
lbIface := NewLoadbalancers(client, region)
lb, assertion := lbIface.(*Loadbalancers)
if !assertion {
t.Error("type assertion failed")
return

Copilot uses AI. Check for mistakes.

Copy link

codecov bot commented Aug 6, 2025

Codecov Report

❌ Patch coverage is 88.12500% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.37%. Comparing base (b0bf52f) to head (c5d4e69).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
cloud/linode/loadbalancers.go 86.11% 6 Missing and 9 partials ⚠️
cloud/linode/cilium_loadbalancers.go 93.87% 3 Missing ⚠️
cloud/linode/cloud.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #432      +/-   ##
==========================================
- Coverage   72.44%   72.37%   -0.07%     
==========================================
  Files          19       19              
  Lines        3498     3511      +13     
==========================================
+ Hits         2534     2541       +7     
- Misses        733      737       +4     
- Partials      231      233       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@rahulait rahulait left a comment

Choose a reason for hiding this comment

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

Overall, looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement for improvements in existing functionality in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants