Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add policy route when use old active gateway node for centralized subnet #2722

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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