Skip to content

Commit

Permalink
fix bug: dpdk场景下添加删除ProviderNetwork失败 (#4466)
Browse files Browse the repository at this point in the history
* fix bug: dpdk场景下添加删除ProviderNetwork失败

Signed-off-by: wangs <[email protected]>

* fix err log

Signed-off-by: wangs <[email protected]>

* fix err log

Signed-off-by: wangs <[email protected]>

* fix link set error

Signed-off-by: wangs <[email protected]>

* fix del bridge err

Signed-off-by: wangs <[email protected]>

---------

Signed-off-by: wangs <[email protected]>
  • Loading branch information
wangwangyusur288 authored Sep 6, 2024
1 parent 1104627 commit ff2300b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 45 deletions.
28 changes: 19 additions & 9 deletions pkg/daemon/gateway_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,12 @@ func (c *Controller) setExGateway() error {
klog.Errorf("failed to get node, %v", err)
return err
}
var isUserspaceDP bool
isUserspaceDP, err = ovs.IsUserspaceDataPath()
if err != nil {
klog.Error(err)
return err
}
enable := node.Labels[util.ExGatewayLabel]
externalBridge := util.ExternalBridgeName(c.config.ExternalGatewaySwitch)
if enable == "true" {
Expand All @@ -1437,15 +1443,19 @@ func (c *Controller) setExGateway() error {
klog.Error(err)
return err
}
link, err := netlink.LinkByName(linkName)
if err != nil {
klog.Errorf("failed to get nic %s, %v", linkName, err)
return err
}
if err := netlink.LinkSetUp(link); err != nil {
klog.Errorf("failed to set gateway nic %s up, %v", linkName, err)
return err

if !isUserspaceDP {
link, err := netlink.LinkByName(linkName)
if err != nil {
klog.Errorf("failed to get nic %s, %v", linkName, err)
return err
}
if err := netlink.LinkSetUp(link); err != nil {
klog.Errorf("failed to set gateway nic %s up, %v", linkName, err)
return err
}
}

externalBrReady := false
// if external nic already attached into another bridge
if existBr, err := ovs.Exec("port-to-br", linkName); err == nil {
Expand Down Expand Up @@ -1513,7 +1523,7 @@ func (c *Controller) setExGateway() error {
}
}

if !keepExternalSubnet {
if !isUserspaceDP && !keepExternalSubnet {
klog.Infof("delete external bridge %s", externalBridge)
if _, err := ovs.Exec(
ovs.IfExists, "del-br", externalBridge); err != nil {
Expand Down
70 changes: 40 additions & 30 deletions pkg/daemon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,43 +159,53 @@ func (c *Controller) ovsCleanProviderNetwork(provider string) error {
return nil
}

// get host nic
if output, err = ovs.Exec("list-ports", brName); err != nil {
return fmt.Errorf("failed to list ports of OVS bridge %s, %w: %q", brName, err, output)
isUserspaceDP, err := ovs.IsUserspaceDataPath()
if err != nil {
klog.Error(err)
return err
}

// remove host nic from the external bridge
if output != "" {
for _, port := range strings.Split(output, "\n") {
// patch port created by ovn-controller has an external ID ovn-localnet-port=localnet.<SUBNET>
if output, err = ovs.Exec("--data=bare", "--no-heading", "--columns=_uuid", "find", "port", "name="+port, `external-ids:ovn-localnet-port!=""`); err != nil {
return fmt.Errorf("failed to find ovs port %s, %w: %q", port, err, output)
}
if output != "" {
continue
}
klog.V(3).Infof("removing ovs port %s from bridge %s", port, brName)
if err = c.removeProviderNic(port, brName); err != nil {
errMsg := fmt.Errorf("failed to remove port %s from external bridge %s: %w", port, brName, err)
klog.Error(errMsg)
return errMsg
}
klog.V(3).Infof("ovs port %s has been removed from bridge %s", port, brName)
if !isUserspaceDP {
// get host nic
if output, err = ovs.Exec("list-ports", brName); err != nil {
klog.Errorf("failed to list ports of OVS bridge %s, %v: %q", brName, err, output)
return err
}
}

// remove OVS bridge
klog.Infof("delete external bridge %s", brName)
if output, err = ovs.Exec(ovs.IfExists, "del-br", brName); err != nil {
return fmt.Errorf("failed to remove OVS bridge %s, %w: %q", brName, err, output)
}
klog.V(3).Infof("ovs bridge %s has been deleted", brName)
// remove host nic from the external bridge
if output != "" {
for _, port := range strings.Split(output, "\n") {
// patch port created by ovn-controller has an external ID ovn-localnet-port=localnet.<SUBNET>
if output, err = ovs.Exec("--data=bare", "--no-heading", "--columns=_uuid", "find", "port", "name="+port, `external-ids:ovn-localnet-port!=""`); err != nil {
klog.Errorf("failed to find ovs port %s, %v: %q", port, err, output)
return err
}
if output != "" {
continue
}
klog.Infof("removing ovs port %s from bridge %s", port, brName)
if err = c.removeProviderNic(port, brName); err != nil {
klog.Errorf("failed to remove port %s from external bridge %s: %v", port, brName, err)
return err
}
klog.Infof("ovs port %s has been removed from bridge %s", port, brName)
}
}

if br := util.ExternalBridgeName(provider); br != brName {
if _, err = c.changeProvideNicName(br, brName); err != nil {
klog.Errorf("failed to change provider nic name from %s to %s: %v", br, brName, err)
// remove OVS bridge
klog.Infof("delete external bridge %s", brName)
if output, err = ovs.Exec(ovs.IfExists, "del-br", brName); err != nil {
klog.Errorf("failed to remove OVS bridge %s, %v: %q", brName, err, output)
return err
}
klog.Infof("ovs bridge %s has been deleted", brName)

if br := util.ExternalBridgeName(provider); br != brName {
if _, err = c.changeProvideNicName(br, brName); err != nil {
klog.Errorf("failed to change provider nic name from %s to %s: %v", br, brName, err)
return err
}
}
}

if err := removeOvnMapping("ovn-chassis-mac-mappings", provider); err != nil {
Expand Down
25 changes: 19 additions & 6 deletions pkg/daemon/ovs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,16 +1345,29 @@ func (c *Controller) transferAddrsAndRoutes(nicName, brName string, delNonExiste
// Add host nic to external bridge
// Mac address, MTU, IP addresses & routes will be copied/transferred to the external bridge
func (c *Controller) configProviderNic(nicName, brName string, trunks []string) (int, error) {
mtu, err := c.transferAddrsAndRoutes(nicName, brName, false)
isUserspaceDP, err := ovs.IsUserspaceDataPath()
if err != nil {
return 0, fmt.Errorf("failed to transfer addresses and routes from %s to %s: %w", nicName, brName, err)
klog.Error(err)
return 0, err
}

if _, err = ovs.Exec(ovs.MayExist, "add-port", brName, nicName,
"--", "set", "port", nicName, "trunks="+strings.Join(trunks, ","), "external_ids:vendor="+util.CniTypeName); err != nil {
return 0, fmt.Errorf("failed to add %s to OVS bridge %s: %w", nicName, brName, err)
var mtu int
if !isUserspaceDP {
mtu, err = c.transferAddrsAndRoutes(nicName, brName, false)
if err != nil {
klog.Errorf("failed to transfer addresses and routes from %s to %s: %v", nicName, brName, err)
return 0, err
}

if _, err = ovs.Exec(ovs.MayExist, "add-port", brName, nicName,
"--", "set", "port", nicName, "trunks="+strings.Join(trunks, ","), "external_ids:vendor="+util.CniTypeName); err != nil {
klog.Errorf("failed to add %s to OVS bridge %s: %v", nicName, brName, err)
return 0, err
}
klog.V(3).Infof("ovs port %s has been added to bridge %s", nicName, brName)
} else {
mtu = c.config.MTU
}
klog.V(3).Infof("ovs port %s has been added to bridge %s", nicName, brName)

return mtu, nil
}
Expand Down

0 comments on commit ff2300b

Please sign in to comment.