fix: handle nil AWS ALB entries - #758
Conversation
WalkthroughThe AWS ALB resource listing now skips nil load balancer entries before field access. The related test includes a nil entry and updates its name and assertion message. ChangesALB nil-entry handling
Estimated code review effort: 1 (Trivial) | ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/providers/aws/alb_test.go`:
- Line 18: Update TestListELBV2Resources_NilLoadBalancer to exercise
listELBV2Resources through a mocked ELBv2 client instead of
processLoadBalancersForTest, so production nil handling is validated. Convert
the nil and incomplete load-balancer scenarios into table-driven inputs while
preserving coverage for nil entries and missing DNSName or LoadBalancerName.
In `@pkg/providers/aws/alb.go`:
- Line 77: Update the guard in the load balancer processing loop to reject both
nil and empty pointed-to DNSName values before constructing the resource.
Preserve the existing LoadBalancerName validation and ensure emitted resources
never contain an empty DNSName.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b00c2757-3c03-496c-a72e-62d4c5b4b56a
📒 Files selected for processing (2)
pkg/providers/aws/alb.gopkg/providers/aws/alb_test.go
| list := schema.NewResources() | ||
| for _, lb := range lbs { | ||
| if lb.DNSName == nil || lb.LoadBalancerName == nil { | ||
| if lb == nil || lb.DNSName == nil || lb.LoadBalancerName == nil { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Exercise the production listing path.
processLoadBalancersForTest duplicates the filtering logic, and TestListELBV2Resources_NilLoadBalancer invokes that helper instead of listELBV2Resources. The test can pass even if the production method still dereferences a nil lb.
Use a mocked ELBv2 client to call the production method, or extract the shared filtering logic into a production helper. Express the nil and incomplete cases as table-driven inputs.
As per coding guidelines, provider tests should prefer mocked cloud provider clients and use table-driven tests for resource parsing.
Also applies to: 44-48
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/providers/aws/alb_test.go` at line 18, Update
TestListELBV2Resources_NilLoadBalancer to exercise listELBV2Resources through a
mocked ELBv2 client instead of processLoadBalancersForTest, so production nil
handling is validated. Convert the nil and incomplete load-balancer scenarios
into table-driven inputs while preserving coverage for nil entries and missing
DNSName or LoadBalancerName.
Source: Coding guidelines
|
|
||
| for _, lb := range loadBalancers { | ||
| if lb.DNSName == nil || lb.LoadBalancerName == nil { | ||
| if lb == nil || lb.DNSName == nil || lb.LoadBalancerName == nil { |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Reject empty DNS values, not only nil pointers.
The guard on Line 77 only checks whether DNSName is non-nil. aws.String("") is non-nil. If LoadBalancerName is populated, the loop emits a resource with an empty DNSName.
Check the pointed-to DNS value before constructing the resource.
Proposed fix
- if lb == nil || lb.DNSName == nil || lb.LoadBalancerName == nil {
+ if lb == nil || lb.DNSName == nil || *lb.DNSName == "" || lb.LoadBalancerName == nil {As per coding guidelines, each emitted resource must have at least one of IP or DNS populated; empty resources are invalid.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if lb == nil || lb.DNSName == nil || lb.LoadBalancerName == nil { | |
| if lb == nil || lb.DNSName == nil || *lb.DNSName == "" || lb.LoadBalancerName == nil { |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/providers/aws/alb.go` at line 77, Update the guard in the load balancer
processing loop to reject both nil and empty pointed-to DNSName values before
constructing the resource. Preserve the existing LoadBalancerName validation and
ensure emitted resources never contain an empty DNSName.
Source: Coding guidelines
Summary
Follow-up to #743, which guards nil ALB fields but still dereferences the load-balancer pointer before checking it.
Test
go test ./pkg/providers/awsSummary by CodeRabbit
Bug Fixes
Tests