From 9cbb07a61c3c59f4a4d0ffa31221314f1cd74876 Mon Sep 17 00:00:00 2001 From: lut777 Date: Thu, 10 Nov 2022 00:15:13 +0800 Subject: [PATCH] fix: gateway route should stay still when node is pingable (#2011) --- pkg/controller/node.go | 1 + pkg/controller/subnet.go | 1 - test/e2e/subnet/normal.go | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pkg/controller/node.go b/pkg/controller/node.go index 57ccb64d2cd..588535b5777 100644 --- a/pkg/controller/node.go +++ b/pkg/controller/node.go @@ -752,6 +752,7 @@ func (c *Controller) checkGatewayReady() error { pinger.Interval = 1 * time.Second success := false + pinger.OnRecv = func(p *goping.Packet) { success = true pinger.Stop() diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index 2ce43df9f79..40fe9f5fa1a 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -1083,7 +1083,6 @@ func (c *Controller) reconcileOvnRoute(subnet *kubeovnv1.Subnet) error { if newActivateNode == "" { klog.Warningf("all subnet %s gws are not ready", subnet.Name) subnet.Status.ActivateGateway = newActivateNode - subnet.Status.NotReady("NoReadyGateway", "") bytes, err := subnet.Status.Bytes() if err != nil { return err diff --git a/test/e2e/subnet/normal.go b/test/e2e/subnet/normal.go index 84173a52d7f..2a9ed2ada5f 100644 --- a/test/e2e/subnet/normal.go +++ b/test/e2e/subnet/normal.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "os/exec" "strings" "time" @@ -422,6 +423,45 @@ var _ = Describe("[Subnet]", func() { Expect(stdout).To(HavePrefix(routePrefix)) } + By("dis-ready gateway node") + gwNodesResult, err := f.OvnClientSet.KubeovnV1().Subnets().Get(context.Background(), name, metav1.GetOptions{}) + Expect(err).NotTo(HaveOccurred()) + gatewayNodes = strings.Split(gwNodesResult.Spec.GatewayNode, ",") + + cmd := "docker exec -i " + gatewayNodes[0] + " systemctl stop kubelet" + _, err = exec.Command("bash", "-c", cmd).CombinedOutput() + Expect(err).NotTo(HaveOccurred()) + + time.Sleep(time.Second * 10) + for _, pod := range ovsPods.Items { + if nodeIPs[pod.Status.HostIP] == "" || pod.Spec.NodeName == gatewayNodes[0] { + continue + } + + stdout, _, err := f.ExecToPodThroughAPI(fmt.Sprintf("ip -%d rule show", af), "openvswitch", pod.Name, pod.Namespace, nil) + Expect(err).NotTo(HaveOccurred()) + + var found bool + rules := strings.Split(stdout, "\n") + for _, rule := range rules { + if strings.HasPrefix(rule, rulePrefix) && strings.HasSuffix(rule, ruleSuffix) { + found = true + break + } + } + Expect(found).To(BeTrue()) + + stdout, _, err = f.ExecToPodThroughAPI(fmt.Sprintf("ip -%d route show table %d", af, tableID), "openvswitch", pod.Name, pod.Namespace, nil) + Expect(err).NotTo(HaveOccurred()) + Expect(stdout).To(HavePrefix(routePrefix)) + } + + cmd = "docker exec -i " + gatewayNodes[0] + " systemctl restart kubelet" + _, err = exec.Command("bash", "-c", cmd).CombinedOutput() + Expect(err).NotTo(HaveOccurred()) + + time.Sleep(time.Second * 30) + By("delete subnet") err = f.OvnClientSet.KubeovnV1().Subnets().Delete(context.Background(), name, metav1.DeleteOptions{}) Expect(err).NotTo(HaveOccurred())