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 }