Skip to content

Commit

Permalink
add policy route when use old active gateway node for centralized sub…
Browse files Browse the repository at this point in the history
…net (#2722)
  • Loading branch information
hongzhen-ma committed May 3, 2023
1 parent 66615b6 commit 7eed834
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
28 changes: 11 additions & 17 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
}
Expand Down
6 changes: 1 addition & 5 deletions test/e2e/kube-ovn/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7eed834

Please sign in to comment.