Skip to content

Commit

Permalink
fix: gateway route should stay still when node is pingable (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
lut777 committed Nov 10, 2022
1 parent f2bdb8e commit 2cab58d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ func (c *Controller) checkGatewayReady() error {
pinger.Interval = 1 * time.Second

success := false

pinger.OnRecv = func(p *goping.Packet) {
success = true
pinger.Stop()
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,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
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/subnet/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"os"
"os/exec"
"strings"
"time"

Expand Down Expand Up @@ -437,6 +438,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())
Expand Down

0 comments on commit 2cab58d

Please sign in to comment.