@@ -1630,7 +1630,11 @@ func (lbaas *LbaasV2) updateServiceAnnotation(service *corev1.Service, key, valu
1630
1630
if service .ObjectMeta .Annotations == nil {
1631
1631
service .ObjectMeta .Annotations = map [string ]string {}
1632
1632
}
1633
- service .ObjectMeta .Annotations [key ] = value
1633
+ if value == "" {
1634
+ delete (service .ObjectMeta .Annotations , key )
1635
+ } else {
1636
+ service .ObjectMeta .Annotations [key ] = value
1637
+ }
1634
1638
}
1635
1639
1636
1640
// createLoadBalancerStatus creates the loadbalancer status from the different possible sources
@@ -1686,12 +1690,20 @@ func (lbaas *LbaasV2) ensureOctaviaLoadBalancer(ctx context.Context, clusterName
1686
1690
isLBOwner := false
1687
1691
createNewLB := false
1688
1692
1689
- // Check the load balancer in the Service annotation.
1690
1693
if svcConf .lbID != "" {
1691
1694
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 {
1693
1701
return nil , fmt .Errorf ("failed to get load balancer %s: %v" , svcConf .lbID , err )
1694
1702
}
1703
+ }
1704
+
1705
+ // Check the load balancer in the Service annotation.
1706
+ if svcConf .lbID != "" {
1695
1707
1696
1708
// Here we test for a clusterName that could have had changed in the deployment.
1697
1709
if lbHasOldClusterName (loadbalancer , clusterName ) {
@@ -2182,7 +2194,10 @@ func (lbaas *LbaasV2) ensureLoadBalancerDeleted(ctx context.Context, clusterName
2182
2194
return err
2183
2195
}
2184
2196
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 )
2186
2201
}
2187
2202
2188
2203
// GetLoadBalancerSourceRanges first try to parse and verify LoadBalancerSourceRanges field from a service.
0 commit comments