diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index 73a7b6746bb..c92d640e36f 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -1534,23 +1534,6 @@ func (c *Controller) reconcileOvnDefaultVpcRoute(subnet *kubeovnv1.Subnet) error } if subnet.Spec.EnableEcmp { - // handle vpc policy route - // 1. Default value of subnet.Spec.EnableEcmp is false, so the field subnet.Status.ActivateGateway has value when centralized subnet is created - // 2. Change subnet.Spec.EnableEcmp from false to true, ecmp route is added based on gatewayNode, not ActivateGateway - // 3. Change subnet.Spec.EnableEcmp from true to false, the ActivateGateway still works and ecmp route does not update, which is incorrect - // 4. So delete ActivateGateway field when ecmp is enabled, and when value changed, the policy route will be updated correctly - if subnet.Status.ActivateGateway != "" { - subnet.Status.ActivateGateway = "" - bytes, err := subnet.Status.Bytes() - if err != nil { - return err - } - if _, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Patch(context.Background(), subnet.Name, types.MergePatchType, bytes, metav1.PatchOptions{}, ""); err != nil { - klog.Errorf("failed to patch for removing subnet activeGateway of subnet %s", subnet.Name) - return err - } - } - // centralized subnet, enable ecmp, add ecmp policy route gatewayNodes := strings.Split(subnet.Spec.GatewayNode, ",") nodeV4Ips := make([]string, 0, len(gatewayNodes)) @@ -1640,6 +1623,17 @@ func (c *Controller) reconcileOvnDefaultVpcRoute(subnet *kubeovnv1.Subnet) error node, err := c.nodesLister.Get(subnet.Status.ActivateGateway) if err == nil && nodeReady(node) { klog.Infof("subnet %s uses the old activate gw %s", subnet.Name, node.Name) + + nodeTunlIPAddr, err := getNodeTunlIP(node) + if err != nil { + klog.Errorf("failed to get gatewayNode tunnel ip for subnet %s", subnet.Name) + return err + } + nextHop := getNextHopByTunnelIP(nodeTunlIPAddr) + if err = c.addPolicyRouteForCentralizedSubnet(subnet, subnet.Status.ActivateGateway, nil, strings.Split(nextHop, ",")); err != nil { + klog.Errorf("failed to add active-backup policy route for centralized subnet %s: %v", subnet.Name, err) + return err + } return nil } } diff --git a/test/e2e/kube-ovn/subnet/subnet.go b/test/e2e/kube-ovn/subnet/subnet.go index 5046e4bc501..13fa195e44a 100644 --- a/test/e2e/kube-ovn/subnet/subnet.go +++ b/test/e2e/kube-ovn/subnet/subnet.go @@ -443,11 +443,7 @@ var _ = framework.Describe("[group:subnet]", func() { subnet = subnetClient.PatchSync(subnet, modifiedSubnet) ginkgo.By("Validating active gateway") - subnet = subnetClient.WaitUntil(subnetName, func(s *apiv1.Subnet) (bool, error) { - return gomega.BeEmpty().Match(s.Status.ActivateGateway) - }, "field .status.activateGateway is empty", - 2*time.Second, time.Minute, - ) + time.Sleep(1 * time.Minute) execCmd := "kubectl ko nbctl --format=csv --data=bare --no-heading --columns=nexthops find logical-router-policy " + fmt.Sprintf("external_ids:subnet=%s", subnetName) output, err := exec.Command("bash", "-c", execCmd).CombinedOutput()