Skip to content

Commit 0eb1f7d

Browse files
committed
Explicitly return a found NB instead of looping
1 parent f8b4472 commit 0eb1f7d

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

cloud/linode/loadbalancers.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,11 @@ func (l *loadbalancers) getNodeBalancerByIPv4(ctx context.Context, service *v1.S
455455
if err != nil {
456456
return nil, err
457457
}
458-
for _, lb := range lbs {
459-
if *lb.IPv4 == ipv4 {
460-
klog.V(2).Infof("found NodeBalancer (%d) for service (%s) via IPv4 (%s)", lb.ID, getServiceNn(service), ipv4)
461-
return &lb, nil
462-
}
458+
if len(lbs) == 0 {
459+
return nil, lbNotFoundError{serviceNn: getServiceNn(service)}
463460
}
464-
return nil, lbNotFoundError{serviceNn: getServiceNn(service)}
461+
klog.V(2).Infof("found NodeBalancer (%d) for service (%s) via IPv4 (%s)", lbs[0].ID, getServiceNn(service), ipv4)
462+
return &lbs[0], nil
465463
}
466464

467465
func (l *loadbalancers) getNodeBalancerByID(ctx context.Context, service *v1.Service, id int) (*linodego.NodeBalancer, error) {

0 commit comments

Comments
 (0)