Skip to content

Commit 28e10fd

Browse files
authored
Merge pull request #2076 from k8s-infra-cherrypick-robot/cherry-pick-2074-to-release-0.10
[release-0.10] 🐛 Fix loadbalancer timeout panic
2 parents ab64794 + c7c2ef6 commit 28e10fd

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

pkg/cloud/services/loadbalancer/loadbalancer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
9292

9393
if lb.ProvisioningStatus != loadBalancerProvisioningStatusActive {
9494
var err error
95-
lb, err = s.waitForLoadBalancerActive(lb.ID)
95+
lbID := lb.ID
96+
lb, err = s.waitForLoadBalancerActive(lbID)
9697
if err != nil {
97-
return false, fmt.Errorf("load balancer %q with id %s is not active after timeout: %v", loadBalancerName, lb.ID, err)
98+
return false, fmt.Errorf("load balancer %q with id %s is not active after timeout: %v", loadBalancerName, lbID, err)
9899
}
99100
}
100101

pkg/cloud/services/loadbalancer/loadbalancer_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ func Test_ReconcileLoadBalancer(t *testing.T) {
4545
mockCtrl := gomock.NewController(t)
4646
defer mockCtrl.Finish()
4747

48+
// Shortcut wait timeout
49+
backoffDurationPrev := backoff.Duration
50+
backoff.Duration = 0
51+
defer func() {
52+
backoff.Duration = backoffDurationPrev
53+
}()
54+
4855
// Stub the call to net.LookupHost
4956
lookupHost = func(host string) (addrs *string, err error) {
5057
if net.ParseIP(host) != nil {
@@ -139,6 +146,27 @@ func Test_ReconcileLoadBalancer(t *testing.T) {
139146
},
140147
wantError: nil,
141148
},
149+
{
150+
name: "reconcile loadbalancer in non active state should timeout",
151+
expectNetwork: func(*mock.MockNetworkClientMockRecorder) {
152+
// add network api call results here
153+
},
154+
expectLoadBalancer: func(m *mock.MockLbClientMockRecorder) {
155+
pendingLB := loadbalancers.LoadBalancer{
156+
ID: "aaaaaaaa-bbbb-cccc-dddd-333333333333",
157+
Name: "k8s-clusterapi-cluster-AAAAA-kubeapi",
158+
ProvisioningStatus: "PENDING_CREATE",
159+
}
160+
161+
// return existing loadbalancer in non-active state
162+
lbList := []loadbalancers.LoadBalancer{pendingLB}
163+
m.ListLoadBalancers(loadbalancers.ListOpts{Name: pendingLB.Name}).Return(lbList, nil)
164+
165+
// wait for loadbalancer until it times out
166+
m.GetLoadBalancer("aaaaaaaa-bbbb-cccc-dddd-333333333333").Return(&pendingLB, nil).Return(&pendingLB, nil).AnyTimes()
167+
},
168+
wantError: fmt.Errorf("load balancer \"k8s-clusterapi-cluster-AAAAA-kubeapi\" with id aaaaaaaa-bbbb-cccc-dddd-333333333333 is not active after timeout: timed out waiting for the condition"),
169+
},
142170
}
143171
for _, tt := range lbtests {
144172
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)