Skip to content

Commit 1a287a0

Browse files
authored
Make sure LB status is updated immediately (kubernetes#2067)
`createFullyPopulatedOctaviaLoadBalancer()` ends with a call to `WaitLoadbalancerActive()`. It'll only exit without error if that function succeeded. But later on `ensureOctaviaLoadBalancer()` checks the LB's `ProvisioningStatus` again and exists if it's not ACTIVE. The problem is that the comparison is done on LB instance returned from POST call and not from one of the GET calls done in `WaitLoadbalancerActive()`, so it's always `PENDING_CREATE`. This means that for LB to be completely created, `ensureOctaviaLoadBalancer()` always needs to be called twice, increasing number of Octavia calls made, time for LBs to be created and user experience by creating false positive warning Event. In case multiple LBs are created in a short period - `Service.Status` of the first one will only be populated once all of them are created as events are processed in order. This increases the time needed to create LBs even more. This commit solves that by making sure `WaitLoadbalancerActive()` returns last instance of `LoadBalancer` struct it got from Octavia API and that that object is later used by `ensureLoadBalancer()` logic.
1 parent 52858db commit 1a287a0

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

pkg/openstack/loadbalancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ func (lbaas *LbaasV2) createFullyPopulatedOctaviaLoadBalancer(name, clusterName
549549
svcConf.lbMemberSubnetID = loadbalancer.VipSubnetID
550550
}
551551

552-
if err := openstackutil.WaitLoadbalancerActive(lbaas.lb, loadbalancer.ID); err != nil {
552+
if loadbalancer, err = openstackutil.WaitLoadbalancerActive(lbaas.lb, loadbalancer.ID); err != nil {
553553
return nil, err
554554
}
555555

pkg/util/openstack/loadbalancer.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,19 @@ func IsOctaviaFeatureSupported(client *gophercloud.ServiceClient, feature int, l
159159
return false
160160
}
161161

162-
func WaitLoadbalancerActive(client *gophercloud.ServiceClient, loadbalancerID string) error {
162+
func WaitLoadbalancerActive(client *gophercloud.ServiceClient, loadbalancerID string) (*loadbalancers.LoadBalancer, error) {
163163
klog.InfoS("Waiting for load balancer ACTIVE", "lbID", loadbalancerID)
164164
backoff := wait.Backoff{
165165
Duration: waitLoadbalancerInitDelay,
166166
Factor: waitLoadbalancerFactor,
167167
Steps: waitLoadbalancerActiveSteps,
168168
}
169169

170+
var loadbalancer *loadbalancers.LoadBalancer
170171
err := wait.ExponentialBackoff(backoff, func() (bool, error) {
171172
mc := metrics.NewMetricContext("loadbalancer", "get")
172-
loadbalancer, err := loadbalancers.Get(client, loadbalancerID).Extract()
173+
var err error
174+
loadbalancer, err = loadbalancers.Get(client, loadbalancerID).Extract()
173175
if mc.ObserveRequest(err) != nil {
174176
return false, err
175177
}
@@ -188,7 +190,7 @@ func WaitLoadbalancerActive(client *gophercloud.ServiceClient, loadbalancerID st
188190
err = fmt.Errorf("timeout waiting for the loadbalancer %s %s", loadbalancerID, activeStatus)
189191
}
190192

191-
return err
193+
return loadbalancer, err
192194
}
193195

194196
// GetLoadBalancers returns all the filtered load balancer.
@@ -254,7 +256,7 @@ func UpdateLoadBalancerTags(client *gophercloud.ServiceClient, lbID string, tags
254256
return err
255257
}
256258

257-
if err := WaitLoadbalancerActive(client, lbID); err != nil {
259+
if _, err := WaitLoadbalancerActive(client, lbID); err != nil {
258260
return fmt.Errorf("failed to wait for load balancer %s ACTIVE after updating: %v", lbID, err)
259261
}
260262

@@ -318,7 +320,7 @@ func UpdateListener(client *gophercloud.ServiceClient, lbID string, listenerID s
318320
return err
319321
}
320322

321-
if err := WaitLoadbalancerActive(client, lbID); err != nil {
323+
if _, err := WaitLoadbalancerActive(client, lbID); err != nil {
322324
return fmt.Errorf("failed to wait for load balancer %s ACTIVE after updating listener: %v", lbID, err)
323325
}
324326

@@ -333,7 +335,7 @@ func CreateListener(client *gophercloud.ServiceClient, lbID string, opts listene
333335
return nil, err
334336
}
335337

336-
if err := WaitLoadbalancerActive(client, lbID); err != nil {
338+
if _, err := WaitLoadbalancerActive(client, lbID); err != nil {
337339
return nil, fmt.Errorf("failed to wait for load balancer %s ACTIVE after creating listener: %v", lbID, err)
338340
}
339341

@@ -352,7 +354,7 @@ func DeleteListener(client *gophercloud.ServiceClient, listenerID string, lbID s
352354
}
353355
}
354356

355-
if err := WaitLoadbalancerActive(client, lbID); err != nil {
357+
if _, err := WaitLoadbalancerActive(client, lbID); err != nil {
356358
return fmt.Errorf("failed to wait for load balancer %s ACTIVE after deleting listener: %v", lbID, err)
357359
}
358360

@@ -419,7 +421,7 @@ func CreatePool(client *gophercloud.ServiceClient, opts pools.CreateOptsBuilder,
419421
return nil, err
420422
}
421423

422-
if err = WaitLoadbalancerActive(client, lbID); err != nil {
424+
if _, err = WaitLoadbalancerActive(client, lbID); err != nil {
423425
return nil, fmt.Errorf("failed to wait for load balancer ACTIVE after creating pool: %v", err)
424426
}
425427

@@ -549,7 +551,7 @@ func DeletePool(client *gophercloud.ServiceClient, poolID string, lbID string) e
549551
return fmt.Errorf("error deleting pool %s for load balancer %s: %v", poolID, lbID, err)
550552
}
551553
}
552-
if err := WaitLoadbalancerActive(client, lbID); err != nil {
554+
if _, err := WaitLoadbalancerActive(client, lbID); err != nil {
553555
return fmt.Errorf("failed to wait for load balancer %s ACTIVE after deleting pool: %v", lbID, err)
554556
}
555557

@@ -564,7 +566,7 @@ func BatchUpdatePoolMembers(client *gophercloud.ServiceClient, lbID string, pool
564566
return err
565567
}
566568

567-
if err := WaitLoadbalancerActive(client, lbID); err != nil {
569+
if _, err := WaitLoadbalancerActive(client, lbID); err != nil {
568570
return fmt.Errorf("failed to wait for load balancer %s ACTIVE after updating pool members for %s: %v", lbID, poolID, err)
569571
}
570572

@@ -600,7 +602,7 @@ func CreateL7Policy(client *gophercloud.ServiceClient, opts l7policies.CreateOpt
600602
return nil, err
601603
}
602604

603-
if err = WaitLoadbalancerActive(client, lbID); err != nil {
605+
if _, err = WaitLoadbalancerActive(client, lbID); err != nil {
604606
return nil, fmt.Errorf("failed to wait for load balancer ACTIVE after creating l7policy: %v", err)
605607
}
606608

@@ -614,7 +616,7 @@ func DeleteL7policy(client *gophercloud.ServiceClient, policyID string, lbID str
614616
return err
615617
}
616618

617-
if err := WaitLoadbalancerActive(client, lbID); err != nil {
619+
if _, err := WaitLoadbalancerActive(client, lbID); err != nil {
618620
return fmt.Errorf("failed to wait for load balancer %s ACTIVE after deleting l7policy: %v", lbID, err)
619621
}
620622

@@ -644,7 +646,7 @@ func CreateL7Rule(client *gophercloud.ServiceClient, policyID string, opts l7pol
644646
return err
645647
}
646648

647-
if err = WaitLoadbalancerActive(client, lbID); err != nil {
649+
if _, err = WaitLoadbalancerActive(client, lbID); err != nil {
648650
return fmt.Errorf("failed to wait for load balancer ACTIVE after creating l7policy rule: %v", err)
649651
}
650652

@@ -670,7 +672,7 @@ func DeleteHealthMonitor(client *gophercloud.ServiceClient, monitorID string, lb
670672
return mc.ObserveRequest(err)
671673
}
672674
_ = mc.ObserveRequest(nil)
673-
if err := WaitLoadbalancerActive(client, lbID); err != nil {
675+
if _, err := WaitLoadbalancerActive(client, lbID); err != nil {
674676
return fmt.Errorf("failed to wait for load balancer %s ACTIVE after deleting healthmonitor: %v", lbID, err)
675677
}
676678

@@ -685,7 +687,7 @@ func CreateHealthMonitor(client *gophercloud.ServiceClient, opts monitors.Create
685687
return nil, fmt.Errorf("failed to create healthmonitor: %v", err)
686688
}
687689

688-
if err := WaitLoadbalancerActive(client, lbID); err != nil {
690+
if _, err := WaitLoadbalancerActive(client, lbID); err != nil {
689691
return nil, fmt.Errorf("failed to wait for load balancer %s ACTIVE after creating healthmonitor: %v", lbID, err)
690692
}
691693

0 commit comments

Comments
 (0)