From d223a02fa02192a6ac8d53d9ca1d3413e068fee0 Mon Sep 17 00:00:00 2001 From: 234u34k <234u34k@users.noreply.github.com> Date: Sun, 1 Mar 2026 16:46:10 +0000 Subject: [PATCH] occm: skip LB rename for shared load balancers from other clusters When a Service references a shared load balancer via annotation, the OCCM rename logic (added in #2552) sees a different cluster name in the LB name and renames it. This breaks multi-cluster shared LB setups because the owning cluster loses its LB name and tags. Before renaming, verify that the LB's namespace and service name components match the current Service. This distinguishes a legitimate cluster-name change (same service, new cluster name) from a cross-cluster shared LB access (different service entirely). --- pkg/openstack/loadbalancer.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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) + } } }