Skip to content

Commit feedaca

Browse files
committed
fix IP/route transfer on node reboot
1 parent 5406d70 commit feedaca

File tree

2 files changed

+30
-54
lines changed

2 files changed

+30
-54
lines changed

pkg/daemon/init.go

+17-25
Original file line numberDiff line numberDiff line change
@@ -64,36 +64,28 @@ func InitVlan(config *Configuration) error {
6464
panic("provider should not be empty")
6565
}
6666

67-
//create patch port
68-
exists, err := providerBridgeExists()
69-
if err != nil {
70-
errMsg := fmt.Errorf("check provider bridge exists failed, %v", err)
67+
ifName := config.getInterfaceName()
68+
if ifName == "" {
69+
errMsg := fmt.Errorf("failed get host nic to add ovs %s", util.UnderlayBridge)
7170
klog.Error(errMsg)
72-
return err
71+
return errMsg
7372
}
7473

75-
if !exists {
76-
//create br-provider
77-
if err = configProviderPort(config.DefaultProviderName); err != nil {
78-
errMsg := fmt.Errorf("configure patch port %s failed %v", util.UnderlayBridge, err)
79-
klog.Error(errMsg)
80-
return errMsg
81-
}
82-
83-
//add a host nic to br-provider
84-
ifName := config.getInterfaceName()
85-
if ifName == "" {
86-
errMsg := fmt.Errorf("failed get host nic to add ovs %s", util.UnderlayBridge)
87-
klog.Error(errMsg)
88-
return errMsg
89-
}
74+
// create and configure external bridge
75+
brName := util.UnderlayBridge
76+
if err := configExternalBridge(config.DefaultProviderName, brName); err != nil {
77+
errMsg := fmt.Errorf("failed to create and configure external bridge %s: %v", brName, err)
78+
klog.Error(errMsg)
79+
return errMsg
80+
}
9081

91-
if err = configProviderNic(ifName); err != nil {
92-
errMsg := fmt.Errorf("add nic %s to port %s failed %v", ifName, util.UnderlayBridge, err)
93-
klog.Error(errMsg)
94-
return errMsg
95-
}
82+
// add host nic to the external bridge
83+
if err := configProviderNic(ifName, brName); err != nil {
84+
errMsg := fmt.Errorf("failed to add nic %s to external bridge %s: %v", ifName, brName, err)
85+
klog.Error(errMsg)
86+
return errMsg
9687
}
88+
9789
return nil
9890
}
9991

pkg/daemon/ovs.go

+13-29
Original file line numberDiff line numberDiff line change
@@ -482,49 +482,33 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int) error {
482482
return nil
483483
}
484484

485-
func configProviderPort(providerInterfaceName string) error {
486-
output, err := ovs.Exec(ovs.MayExist, "add-br", util.UnderlayBridge)
485+
func configExternalBridge(provider, bridge string) error {
486+
output, err := ovs.Exec(ovs.MayExist, "add-br", bridge)
487487
if err != nil {
488-
return fmt.Errorf("failed to create bridge %s, %v: %q", util.UnderlayBridge, err, output)
488+
return fmt.Errorf("failed to create bridge %s, %v: %q", bridge, err, output)
489489
}
490490
output, err = ovs.Exec(ovs.IfExists, "get", "open", ".", "external-ids:ovn-bridge-mappings")
491491
if err != nil {
492492
return fmt.Errorf("failed to get external-ids, %v", err)
493493
}
494-
bridgeMappings := fmt.Sprintf("%s:%s", providerInterfaceName, util.UnderlayBridge)
495-
if output != "" && !util.IsStringIn(bridgeMappings, strings.Split(output, ",")) {
494+
495+
bridgeMappings := fmt.Sprintf("%s:%s", provider, bridge)
496+
if util.IsStringIn(bridgeMappings, strings.Split(output, ",")) {
497+
return nil
498+
}
499+
if output != "" {
496500
bridgeMappings = fmt.Sprintf("%s,%s", output, bridgeMappings)
497501
}
498-
499-
output, err = ovs.Exec("set", "open", ".", fmt.Sprintf("external-ids:ovn-bridge-mappings=%s", bridgeMappings))
500-
if err != nil {
502+
if output, err = ovs.Exec("set", "open", ".", "external-ids:ovn-bridge-mappings="+bridgeMappings); err != nil {
501503
return fmt.Errorf("failed to set bridge-mappings, %v: %q", err, output)
502504
}
503505

504506
return nil
505507
}
506508

507-
func providerBridgeExists() (bool, error) {
508-
output, err := ovs.Exec("list-br")
509-
if err != nil {
510-
klog.Errorf("failed to list bridge %v", err)
511-
return false, err
512-
}
513-
514-
lines := strings.Split(output, "\n")
515-
for _, l := range lines {
516-
if l == util.UnderlayBridge {
517-
return true, nil
518-
}
519-
}
520-
521-
return false, nil
522-
}
523-
524-
// Add host nic to br-provider
525-
// MAC, MTU, IP addresses & routes will be copied/transferred to br-provider
526-
func configProviderNic(nicName string) error {
527-
brName := util.UnderlayBridge
509+
// Add host nic to external bridge
510+
// Mac address, MTU, IP addresses & routes will be copied/transferred to the external bridge
511+
func configProviderNic(nicName, brName string) error {
528512
nic, err := netlink.LinkByName(nicName)
529513
if err != nil {
530514
return fmt.Errorf("failed to get nic by name %s: %v", nicName, err)

0 commit comments

Comments
 (0)