Skip to content

Commit

Permalink
refactor: reuse waitNetworkReady to check ovn0 and slightly improve t…
Browse files Browse the repository at this point in the history
…he installation speed
  • Loading branch information
oilbeater committed Sep 9, 2021
1 parent 7c5eaa3 commit f59aff2
Showing 1 changed file with 4 additions and 41 deletions.
45 changes: 4 additions & 41 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
Expand Down Expand Up @@ -340,12 +339,10 @@ func configureNodeNic(portName, ip, gw string, macAddr net.HardwareAddr, mtu int
}

// 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)
if err := waitNetworkReady(gw); err != nil {
klog.Errorf("failed to init ovn0 check: %v", err)
return err
}
klog.Infof("ping gw result is: \n %s", output)

return nil
}
Expand All @@ -368,42 +365,8 @@ func (c *Controller) loopOvn0Check() {
return
}
gw := node.Annotations[util.GatewayAnnotation]
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()
klog.V(3).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 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 output, err
}
return output, nil
} else if protocol == kubeovnv1.ProtocolIPv4 {
output, err := exec.Command("ping", "-w", "10", gw).CombinedOutput()
if err != nil {
klog.Errorf("ovn0 failed to ping gw %s: %v", gw, err)
return output, err
}
return output, nil
} else {
output, err := exec.Command("ping6", "-w", "10", gw).CombinedOutput()
if err != nil {
klog.Errorf("ovn0 failed to ping gw %s: %v", gw, err)
return output, err
}
return output, nil
if err := waitNetworkReady(gw); err != nil {
klog.Fatalf("failed to ping ovn0 gw: %s, %v", gw, err)
}
}

Expand Down

0 comments on commit f59aff2

Please sign in to comment.