Skip to content

Commit a3f81d7

Browse files
committed
[occm]: remove k8s annotations after LB is deleted
Signed-off-by: Cedric <[email protected]>
1 parent 7c95815 commit a3f81d7

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

pkg/openstack/loadbalancer.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,11 @@ func (lbaas *LbaasV2) updateServiceAnnotation(service *corev1.Service, key, valu
16301630
if service.ObjectMeta.Annotations == nil {
16311631
service.ObjectMeta.Annotations = map[string]string{}
16321632
}
1633-
service.ObjectMeta.Annotations[key] = value
1633+
if value == "" {
1634+
delete(service.ObjectMeta.Annotations, key)
1635+
} else {
1636+
service.ObjectMeta.Annotations[key] = value
1637+
}
16341638
}
16351639

16361640
// createLoadBalancerStatus creates the loadbalancer status from the different possible sources
@@ -1686,12 +1690,20 @@ func (lbaas *LbaasV2) ensureOctaviaLoadBalancer(ctx context.Context, clusterName
16861690
isLBOwner := false
16871691
createNewLB := false
16881692

1689-
// Check the load balancer in the Service annotation.
16901693
if svcConf.lbID != "" {
16911694
loadbalancer, err = openstackutil.GetLoadbalancerByID(lbaas.lb, svcConf.lbID)
1692-
if err != nil {
1695+
// The referenced LB doesn't exist anymore. Clean up annotations and proceed as if no LB were set.
1696+
if err != nil && cpoerrors.IsNotFound(err) {
1697+
svcConf.lbID = ""
1698+
lbaas.updateServiceAnnotation(service, ServiceAnnotationLoadBalancerID, "")
1699+
lbaas.updateServiceAnnotation(service, ServiceAnnotationLoadBalancerAddress, "")
1700+
} else if err != nil {
16931701
return nil, fmt.Errorf("failed to get load balancer %s: %v", svcConf.lbID, err)
16941702
}
1703+
}
1704+
1705+
// Check the load balancer in the Service annotation.
1706+
if svcConf.lbID != "" {
16951707

16961708
// Here we test for a clusterName that could have had changed in the deployment.
16971709
if lbHasOldClusterName(loadbalancer, clusterName) {
@@ -2182,7 +2194,10 @@ func (lbaas *LbaasV2) ensureLoadBalancerDeleted(ctx context.Context, clusterName
21822194
return err
21832195
}
21842196

2185-
return nil
2197+
patcher := newServicePatcher(lbaas.kclient, service)
2198+
lbaas.updateServiceAnnotation(patcher.updated, ServiceAnnotationLoadBalancerID, "")
2199+
lbaas.updateServiceAnnotation(patcher.updated, ServiceAnnotationLoadBalancerAddress, "")
2200+
return patcher.Patch(ctx, err)
21862201
}
21872202

21882203
// GetLoadBalancerSourceRanges first try to parse and verify LoadBalancerSourceRanges field from a service.

0 commit comments

Comments
 (0)