From f21c9c308df1b065db0e2529d62dbf5c91859c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A5=96=E5=BB=BA?= Date: Thu, 11 Jul 2024 11:48:02 +0800 Subject: [PATCH] fix ovn lb not updated due to service update failure (#4280) Signed-off-by: zhangzujian --- pkg/controller/endpoint.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/controller/endpoint.go b/pkg/controller/endpoint.go index 67b353376c3..058cdfda103 100644 --- a/pkg/controller/endpoint.go +++ b/pkg/controller/endpoint.go @@ -190,17 +190,6 @@ func (c *Controller) handleUpdateEndpoint(key string) error { return err } - if svcVpc = svc.Annotations[util.VpcAnnotation]; svcVpc != vpcName { - if svc.Annotations == nil { - svc.Annotations = make(map[string]string, 1) - } - svc.Annotations[util.VpcAnnotation] = vpcName - if _, err = c.config.KubeClient.CoreV1().Services(namespace).Update(context.Background(), svc, metav1.UpdateOptions{}); err != nil { - klog.Errorf("failed to update service %s: %v", key, err) - return err - } - } - tcpLb, udpLb, sctpLb := vpc.Status.TCPLoadBalancer, vpc.Status.UDPLoadBalancer, vpc.Status.SctpLoadBalancer oldTCPLb, oldUDPLb, oldSctpLb := vpc.Status.TCPSessionLoadBalancer, vpc.Status.UDPSessionLoadBalancer, vpc.Status.SctpSessionLoadBalancer if svc.Spec.SessionAffinity == v1.ServiceAffinityClientIP { @@ -267,6 +256,18 @@ func (c *Controller) handleUpdateEndpoint(key string) error { } } } + + if svcVpc = svc.Annotations[util.VpcAnnotation]; svcVpc != vpcName { + if svc.Annotations == nil { + svc.Annotations = make(map[string]string, 1) + } + svc.Annotations[util.VpcAnnotation] = vpcName + if _, err = c.config.KubeClient.CoreV1().Services(namespace).Update(context.Background(), svc, metav1.UpdateOptions{}); err != nil { + klog.Errorf("failed to update service %s: %v", key, err) + return err + } + } + return nil }