Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[occm]: remove k8s annotations after LB is deleted #2752

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions pkg/openstack/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,11 @@ func (lbaas *LbaasV2) updateServiceAnnotation(service *corev1.Service, key, valu
if service.ObjectMeta.Annotations == nil {
service.ObjectMeta.Annotations = map[string]string{}
}
service.ObjectMeta.Annotations[key] = value
if value == "" {
delete(service.ObjectMeta.Annotations, key)
} else {
service.ObjectMeta.Annotations[key] = value
}
}

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

// Check the load balancer in the Service annotation.
if svcConf.lbID != "" {
loadbalancer, err = openstackutil.GetLoadbalancerByID(lbaas.lb, svcConf.lbID)
if err != nil {
// The referenced LB doesn't exist anymore. Clean up annotations and proceed as if no LB were set.
if err != nil && cpoerrors.IsNotFound(err) {
svcConf.lbID = ""
lbaas.updateServiceAnnotation(service, ServiceAnnotationLoadBalancerID, "")
lbaas.updateServiceAnnotation(service, ServiceAnnotationLoadBalancerAddress, "")
} else if err != nil {
return nil, fmt.Errorf("failed to get load balancer %s: %v", svcConf.lbID, err)
}
}

// Check the load balancer in the Service annotation.
if svcConf.lbID != "" {

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

return nil
patcher := newServicePatcher(lbaas.kclient, service)
lbaas.updateServiceAnnotation(patcher.updated, ServiceAnnotationLoadBalancerID, "")
lbaas.updateServiceAnnotation(patcher.updated, ServiceAnnotationLoadBalancerAddress, "")
return patcher.Patch(ctx, err)
}

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