Skip to content

Commit

Permalink
fix underlay networking on node reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Aug 12, 2021
1 parent 379bcce commit 324dce2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func CmdMain() {

klog.Infof(versions.String())
daemon.InitMetrics()
if err := daemon.InitOVSBridges(); err != nil {
klog.Fatalf("failed to initialize OVS bridges: %v", err)
}

config, err := daemon.ParseFlags()
if err != nil {
klog.Fatalf("parse config failed %v", err)
Expand Down
40 changes: 40 additions & 0 deletions pkg/daemon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,53 @@ import (
"strings"
"time"

"github.com/vishvananda/netlink"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog"

"github.com/kubeovn/kube-ovn/pkg/ovs"
"github.com/kubeovn/kube-ovn/pkg/util"
)

// InitOVSBridges initializes OVS bridges
func InitOVSBridges() error {
bridges, err := ovs.Bridges()
if err != nil {
return err
}

for _, brName := range bridges {
bridge, err := netlink.LinkByName(brName)
if err != nil {
return fmt.Errorf("failed to get bridge by name %s: %v", brName, err)
}
if err = netlink.LinkSetUp(bridge); err != nil {
return fmt.Errorf("failed to set OVS bridge %s up: %v", brName, err)
}

output, err := ovs.Exec("list-ports", brName)
if err != nil {
return fmt.Errorf("failed to list ports of OVS birdge %s, %v: %q", brName, err, output)
}

if output != "" {
for _, port := range strings.Split(output, "\n") {
ok, err := ovs.ValidatePortVendor(port)
if err != nil {
return fmt.Errorf("failed to check vendor of port %s: %v", port, err)
}
if ok {
if _, err = configProviderNic(port, brName); err != nil {
return err
}
}
}
}
}

return nil
}

// InitNodeGateway init ovn0
func InitNodeGateway(config *Configuration) error {
var portName, ip, cidr, macAddr, gw, ipAddr string
Expand Down
5 changes: 5 additions & 0 deletions pkg/ovs/ovs-vsctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func ovsClear(table, record string, columns ...string) error {
return err
}

// Bridges returns bridges created by Kube-OVN
func Bridges() ([]string, error) {
return ovsFind("bridge", "name", fmt.Sprintf("external-ids:vendor=%s", util.CniTypeName))
}

// ClearPodBandwidth remove qos related to this pod. Only used when remove pod.
func ClearPodBandwidth(podName, podNamespace string) error {
qosList, err := ovsFind("qos", "_uuid", fmt.Sprintf(`external-ids:iface-id="%s.%s"`, podName, podNamespace))
Expand Down

0 comments on commit 324dce2

Please sign in to comment.