-
Notifications
You must be signed in to change notification settings - Fork 69
[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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
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.
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 }}
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 |
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.
The function getNodeBalancerBackendIPv4SubnetID logs errors and returns 0 instead of propagating the error. Consider returning the error to enable better diagnostics and failure handling.
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) { |
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.
[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.
General:
Pull Request Guidelines: