Skip to content

Commit

Permalink
fix: check ovn0 status
Browse files Browse the repository at this point in the history
When ovs restart, internal port like ovn0 will go down
and disconnect host and pod network. Check the link status
and ping gw status and restart kube-ovn-cni if the link goes
wrong.
  • Loading branch information
oilbeater committed Mar 27, 2021
1 parent 03956f1 commit a586231
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions dist/images/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ RUN --mount=type=bind,target=/packages,from=ovs-builder,source=/packages \
COPY *.sh /kube-ovn/
COPY 01-kube-ovn.conflist /kube-ovn/01-kube-ovn.conflist
COPY logrotate/* /etc/logrotate.d/
COPY grace_stop_ovn_controller /usr/share/ovn/scripts/grace_stop_ovn_controller

WORKDIR /kube-ovn

Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (c *Controller) setIPSet() error {
}

func (c *Controller) setIptables() error {
klog.Infoln("start to set up iptables")
klog.V(3).Infoln("start to set up iptables")
node, err := c.nodesLister.Get(c.config.NodeName)
if err != nil {
klog.Errorf("failed to get node %s, %v", c.config.NodeName, err)
Expand Down
54 changes: 43 additions & 11 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,38 +266,70 @@ func configureNodeNic(portName, ip, gw string, macAddr net.HardwareAddr, mtu int
return err
}

// ping gw to activate the flow
// ping ovn0 gw to activate the flow
output, err = ovn0Check(gw)
if err != nil {
klog.Errorf("failed to init ovn0 check, %v, %q", err, output)
return err
}
klog.Infof("ping gw result is: \n %s", output)

go loopOvn0Check(gw)
return nil
}

// If OVS restart, the ovn0 port will down and prevent host to pod network,
// Restart the kube-ovn-cni when this happens
func loopOvn0Check(gw string) {
for {
time.Sleep(5 * time.Second)
link, err := netlink.LinkByName(util.NodeNic)
if err != nil {
klog.Fatalf("failed to get ovn0 nic, %v", err)
}

if link.Attrs().OperState == netlink.OperDown {
klog.Fatalf("ovn0 nic is down")
}

if output, err := ovn0Check(gw); err != nil {
klog.Fatalf("failed to ping ovn0 gw %v, %q", gw, output)
}
}
}

func ovn0Check(gw string) ([]byte, error) {
protocol := util.CheckProtocol(gw)
if protocol == kubeovnv1.ProtocolDual {
gws := strings.Split(gw, ",")
output, err = exec.Command("ping", "-w", "10", gws[0]).CombinedOutput()
output, err := exec.Command("ping", "-w", "10", gws[0]).CombinedOutput()
klog.Infof("ping v4 gw result is: \n %s", output)
if err != nil {
klog.Errorf("ovn0 failed to ping gw %s, %v", gws[0], err)
return err
return output, err
}

output, err = exec.Command("ping6", "-w", "10", gws[1]).CombinedOutput()
if err != nil {
klog.Errorf("ovn0 failed to ping gw %s, %v", gws[1], err)
return err
return output, err
}
return output, nil
} else if protocol == kubeovnv1.ProtocolIPv4 {
output, err = exec.Command("ping", "-w", "10", gw).CombinedOutput()
output, err := exec.Command("ping", "-w", "10", gw).CombinedOutput()
if err != nil {
klog.Errorf("ovn0 failed to ping gw %s, %v", gw, err)
return err
return output, err
}
return output, nil
} else {
output, err = exec.Command("ping6", "-w", "10", gw).CombinedOutput()
output, err := exec.Command("ping6", "-w", "10", gw).CombinedOutput()
if err != nil {
klog.Errorf("ovn0 failed to ping gw %s, %v", gw, err)
return err
return output, err
}
return output, nil
}

klog.Infof("ping gw result is: \n %s", output)
return nil
}

func configureMirror(portName string, mtu int) error {
Expand Down

0 comments on commit a586231

Please sign in to comment.