Skip to content

Commit 1b68b7d

Browse files
authored
fix(lb): remove region loop on get lb by name (#57) (#59)
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent 55e3bdc commit 1b68b7d

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

scaleway/loadbalancers.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -406,27 +406,21 @@ func (l *loadbalancers) getLoadbalancerByName(ctx context.Context, service *v1.S
406406
name := l.GetLoadBalancerName(ctx, "", service)
407407

408408
var loadbalancer *scwlb.LB
409-
for _, region := range scw.AllRegions {
410-
resp, err := l.api.ListLBs(&scwlb.ListLBsRequest{
411-
Name: &name,
412-
Region: region,
413-
}, scw.WithAllPages())
414-
if err != nil {
415-
if is404Error(err) {
416-
continue
417-
}
418-
return nil, err
419-
}
420-
421-
for _, lb := range resp.LBs {
422-
if lb.Name == name {
423-
if loadbalancer != nil {
424-
klog.Errorf("more than one loadbalancing matching the name %s", name)
425-
return nil, LoadBalancerDuplicated
426-
}
409+
resp, err := l.api.ListLBs(&scwlb.ListLBsRequest{
410+
Name: &name,
411+
}, scw.WithAllPages())
412+
if err != nil {
413+
return nil, err
414+
}
427415

428-
loadbalancer = lb
416+
for _, lb := range resp.LBs {
417+
if lb.Name == name {
418+
if loadbalancer != nil {
419+
klog.Errorf("more than one loadbalancing matching the name %s", name)
420+
return nil, LoadBalancerDuplicated
429421
}
422+
423+
loadbalancer = lb
430424
}
431425
}
432426

0 commit comments

Comments
 (0)