diff --git a/pkg/openstack/loadbalancer.go b/pkg/openstack/loadbalancer.go index c67ba1f1b4..38a9aed302 100644 --- a/pkg/openstack/loadbalancer.go +++ b/pkg/openstack/loadbalancer.go @@ -1695,13 +1695,20 @@ func (lbaas *LbaasV2) ensureOctaviaLoadBalancer(ctx context.Context, clusterName } // Here we test for a clusterName that could have had changed in the deployment. + // Only rename when the LB was originally created for this Service (i.e. the + // namespace and service name components match). Without this guard, a shared + // LB from a different cluster gets incorrectly renamed. if lbHasOldClusterName(loadbalancer, clusterName) { - msg := "Loadbalancer %s has a name of %s with incorrect cluster-name component. Renaming it to %s." - klog.Infof(msg, loadbalancer.ID, loadbalancer.Name, lbName) - lbaas.eventRecorder.Eventf(service, corev1.EventTypeWarning, eventLBRename, msg, loadbalancer.ID, loadbalancer.Name, lbName) - loadbalancer, err = renameLoadBalancer(ctx, lbaas.lb, loadbalancer, lbName, clusterName) - if err != nil { - return nil, fmt.Errorf("failed to update load balancer %s with an updated name: %w", svcConf.lbID, err) + oldClusterName := getClusterName("", loadbalancer.Name) + expectedOldName := cpoutil.Sprintf255(lbFormat, servicePrefix, oldClusterName, service.Namespace, service.Name) + if loadbalancer.Name == expectedOldName { + msg := "Loadbalancer %s has a name of %s with incorrect cluster-name component. Renaming it to %s." + klog.Infof(msg, loadbalancer.ID, loadbalancer.Name, lbName) + lbaas.eventRecorder.Eventf(service, corev1.EventTypeWarning, eventLBRename, msg, loadbalancer.ID, loadbalancer.Name, lbName) + loadbalancer, err = renameLoadBalancer(ctx, lbaas.lb, loadbalancer, lbName, clusterName) + if err != nil { + return nil, fmt.Errorf("failed to update load balancer %s with an updated name: %w", svcConf.lbID, err) + } } }