Skip to content

[WIP][improvement] : allow auto-allocation of NB backend ips #391

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rahulait
Copy link
Collaborator

@rahulait rahulait commented May 22, 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 May 22, 2025
Copy link

codecov bot commented May 22, 2025

Codecov Report

Attention: Patch coverage is 82.02247% with 16 lines in your changes missing coverage. Please review.

Project coverage is 74.54%. Comparing base (8d08bde) to head (1dff45a).

Files with missing lines Patch % Lines
cloud/linode/loadbalancers.go 86.95% 6 Missing and 3 partials ⚠️
cloud/linode/vpc.go 71.42% 3 Missing and 1 partial ⚠️
cloud/linode/cloud.go 50.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #391      +/-   ##
==========================================
+ Coverage   74.41%   74.54%   +0.12%     
==========================================
  Files          16       16              
  Lines        2865     2942      +77     
==========================================
+ Hits         2132     2193      +61     
- Misses        550      561      +11     
- Partials      183      188       +5     

☔ 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.

@rahulait rahulait changed the title [improvement][WIP] : allow auto-allocation of NB backend ips [improvement] : allow auto-allocation of NB backend ips May 27, 2025
@komer3 komer3 requested a review from Copilot May 27, 2025 17:49
Copy link

@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 adds support for auto-allocation of NodeBalancer backend IPs. Key changes include:

  • Adding new command-line flags for specifying the backend IPv4 subnet ID and name.
  • Updating e2e tests to incorporate VPC configuration retrieval and subnet ID auto-allocation.
  • Enhancing chart templates and cloud configuration logic to enforce mutual exclusion of subnet flags and annotations.

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
main.go Added CLI flags for NodeBalancer backend IPv4 subnet allocation.
e2e/test/lb-updated-with-nb-id/chainsaw-test.yaml Updated test script to retrieve and use the existing NB backend subnet.
e2e/test/lb-preserve-annotation-new-nb-specified/chainsaw-test.yaml Updated test script to support annotation-based subnet selection.
deploy/chart/values.yaml Documented new chart configuration options.
deploy/chart/templates/daemonset.yaml Added validation to prevent both subnet name and ID from being set.
cloud/linode/vpc.go Introduced getNodeBalancerBackendIPv4SubnetID to retrieve the subnet id from a name.
cloud/linode/loadbalancers_test.go Updated tests with consistent default subnet naming and new NB creation scenarios.
cloud/linode/loadbalancers.go Updated NB creation logic to leverage VPC create options based on flags/annotations.
cloud/linode/cloud.go Enforced mutual exclusion for subnet flags and set the backend subnet ID based on a provided name.
cloud/annotations/annotations.go Added constant for backend subnet ID annotation.
Files not reviewed (1)
  • go.mod: Language not supported
Comments suppressed due to low confidence (1)

deploy/chart/templates/daemonset.yaml:88

  • [nitpick] Consider using a consistent naming convention for template variables (e.g. use $nodeBalancerBackendIpv4SubnetName and $nodeBalancerBackendIpv4SubnetID) to align with the rest of the codebase.
{{- if and $nbvpcBackendIpv4SubnetName $nbvpcBackendIpv4SubnetID }}

Comment on lines +155 to +170
func getNodeBalancerBackendIPv4SubnetID(client client.Client) int {
vpcName := strings.Split(Options.VPCNames, ",")[0]
// Get the VPC ID from the name
vpcID, err := GetVPCID(context.TODO(), client, vpcName)
if err != nil {
klog.Errorf("failed to get vpc id for %s: %v", vpcName, err)
return 0
}
// Get the subnet ID from the name
subnetID, err := GetSubnetID(context.TODO(), client, vpcID, Options.NodeBalancerBackendIPv4SubnetName)
if err != nil {
klog.Errorf("failed to get subnet id for %s: %v", Options.NodeBalancerBackendIPv4SubnetName, err)
return 0
}

return subnetID
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

The function getNodeBalancerBackendIPv4SubnetID logs errors and returns 0 instead of propagating the error. Consider returning the error to enable better diagnostics and failure handling.

Suggested change
func getNodeBalancerBackendIPv4SubnetID(client client.Client) int {
vpcName := strings.Split(Options.VPCNames, ",")[0]
// Get the VPC ID from the name
vpcID, err := GetVPCID(context.TODO(), client, vpcName)
if err != nil {
klog.Errorf("failed to get vpc id for %s: %v", vpcName, err)
return 0
}
// Get the subnet ID from the name
subnetID, err := GetSubnetID(context.TODO(), client, vpcID, Options.NodeBalancerBackendIPv4SubnetName)
if err != nil {
klog.Errorf("failed to get subnet id for %s: %v", Options.NodeBalancerBackendIPv4SubnetName, err)
return 0
}
return subnetID
func getNodeBalancerBackendIPv4SubnetID(client client.Client) (int, error) {
vpcName := strings.Split(Options.VPCNames, ",")[0]
// Get the VPC ID from the name
vpcID, err := GetVPCID(context.TODO(), client, vpcName)
if err != nil {
return 0, fmt.Errorf("failed to get vpc id for %s: %w", vpcName, err)
}
// Get the subnet ID from the name
subnetID, err := GetSubnetID(context.TODO(), client, vpcID, Options.NodeBalancerBackendIPv4SubnetName)
if err != nil {
return 0, fmt.Errorf("failed to get subnet id for %s: %w", Options.NodeBalancerBackendIPv4SubnetName, err)
}
return subnetID, nil

Copilot uses AI. Check for mistakes.

// 3. NodeBalancerBackendIPv4SubnetID/NodeBalancerBackendIPv4SubnetName flag
// 4. NodeBalancerBackendIPv4Subnet flag
// 5. Default to using the subnet ID of the service's VPC
func (l *loadbalancers) getVPCCreateOptions(ctx context.Context, service *v1.Service) ([]linodego.NodeBalancerVPCOptions, error) {
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] The nested conditions in getVPCCreateOptions make the flow somewhat complex; consider refactoring to simplify the control flow for improved clarity and maintainability.

Copilot uses AI. Check for mistakes.

@rahulait rahulait changed the title [improvement] : allow auto-allocation of NB backend ips [WIP][improvement] : allow auto-allocation of NB backend ips May 27, 2025
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.

1 participant