Skip to content

Commit bfb8679

Browse files
author
Timo Reimann
committed
Overwrite service load-balancer ID on mismatch
This change causes the service load-balancer ID annotation to be overwritten if it does not match the given load-balancer ID. It is required to properly handle the case where the load-balancer is deleted manually: in that case, CCM won't be able to look up the load-balancer and create a new one. Without updating the ID, however, subsequent reconciliations will continue to use the old ID, fail to find one, try to create a new but fail because a load-balancer with the given name (based on the service UUID) already exists. At this point, the reconciliation attempt will loop endlessly. We need to break the cycle by annotating the ID of the newly created load-balancer.
1 parent 58a3698 commit bfb8679

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## unreleased
44

5+
### Changed
6+
7+
* Overwrite service load-balancer ID on mismatch (@timoreimann)
8+
59
## v0.1.18 (beta) - Aug 9th 2019
610

711
### Changed

cloud-controller-manager/do/loadbalancers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func (l *loadBalancers) retrieveLoadBalancer(ctx context.Context, service *v1.Se
361361
}
362362

363363
func (l *loadBalancers) ensureLoadBalancerIDAnnot(service *v1.Service, lbID string) error {
364-
if val := getLoadBalancerID(service); val != "" {
364+
if val := getLoadBalancerID(service); val == lbID {
365365
return nil
366366
}
367367

cloud-controller-manager/do/loadbalancers_test.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,16 +3412,17 @@ func Test_GetLoadBalancer(t *testing.T) {
34123412

34133413
func Test_EnsureLoadBalancer(t *testing.T) {
34143414
testcases := []struct {
3415-
name string
3416-
droplets []godo.Droplet
3417-
getFn func(context.Context, string) (*godo.LoadBalancer, *godo.Response, error)
3418-
listFn func(context.Context, *godo.ListOptions) ([]godo.LoadBalancer, *godo.Response, error)
3419-
createFn func(context.Context, *godo.LoadBalancerRequest) (*godo.LoadBalancer, *godo.Response, error)
3420-
updateFn func(ctx context.Context, lbID string, lbr *godo.LoadBalancerRequest) (*godo.LoadBalancer, *godo.Response, error)
3421-
service *v1.Service
3422-
nodes []*v1.Node
3423-
lbStatus *v1.LoadBalancerStatus
3424-
err error
3415+
name string
3416+
droplets []godo.Droplet
3417+
getFn func(context.Context, string) (*godo.LoadBalancer, *godo.Response, error)
3418+
listFn func(context.Context, *godo.ListOptions) ([]godo.LoadBalancer, *godo.Response, error)
3419+
createFn func(context.Context, *godo.LoadBalancerRequest) (*godo.LoadBalancer, *godo.Response, error)
3420+
updateFn func(ctx context.Context, lbID string, lbr *godo.LoadBalancerRequest) (*godo.LoadBalancer, *godo.Response, error)
3421+
service *v1.Service
3422+
newLoadBalancerID string
3423+
nodes []*v1.Node
3424+
lbStatus *v1.LoadBalancerStatus
3425+
err error
34253426
}{
34263427
{
34273428
name: "successfully ensured loadbalancer by name, already exists",
@@ -3666,7 +3667,9 @@ func Test_EnsureLoadBalancer(t *testing.T) {
36663667
return nil, newFakeNotOKResponse(), errors.New("list should not have been invoked")
36673668
},
36683669
createFn: func(context.Context, *godo.LoadBalancerRequest) (*godo.LoadBalancer, *godo.Response, error) {
3669-
return createLB(), newFakeOKResponse(), nil
3670+
lb := createLB()
3671+
lb.ID = "other-load-balancer-id"
3672+
return lb, newFakeOKResponse(), nil
36703673
},
36713674
updateFn: func(ctx context.Context, lbID string, lbr *godo.LoadBalancerRequest) (*godo.LoadBalancer, *godo.Response, error) {
36723675
return nil, newFakeNotOKResponse(), errors.New("update should not have been invoked")
@@ -3691,6 +3694,7 @@ func Test_EnsureLoadBalancer(t *testing.T) {
36913694
},
36923695
},
36933696
},
3697+
newLoadBalancerID: "other-load-balancer-id",
36943698
nodes: []*v1.Node{
36953699
{
36963700
ObjectMeta: metav1.ObjectMeta{
@@ -3821,6 +3825,9 @@ func Test_EnsureLoadBalancer(t *testing.T) {
38213825

38223826
gotLoadBalancerID := svc.Annotations[annoDOLoadBalancerID]
38233827
wantLoadBalancerID := "load-balancer-id"
3828+
if test.newLoadBalancerID != "" {
3829+
wantLoadBalancerID = test.newLoadBalancerID
3830+
}
38243831
if gotLoadBalancerID != wantLoadBalancerID {
38253832
t.Errorf("got load-balancer ID %q, want %q", gotLoadBalancerID, wantLoadBalancerID)
38263833
}

0 commit comments

Comments
 (0)