Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(network): support bond nic #766

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pkg/util/machine/network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"syscall"

"github.com/vishvananda/netns"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/kubewharf/katalyst-core/pkg/config/agent/global"
"github.com/kubewharf/katalyst-core/pkg/util/general"
Expand All @@ -44,6 +45,7 @@ const (
const (
nicPathNameDeviceFormatPCI = "devices/pci"
nicPathNAMEBaseDir = "class/net"
bondingMasterPath = "bonding_masters"
)

const (
Expand Down Expand Up @@ -160,6 +162,8 @@ func getNSNetworkHardwareTopology(nsName, netNSDirAbsPath string) ([]InterfaceIn
return nil, err
}

bondingNICs := getBondingNetworkInterfaces(path.Join(nicsBaseDirPath, bondingMasterPath))

nicsAddrMap, err := getInterfaceAddr()
if err != nil {
return nil, err
Expand All @@ -176,7 +180,7 @@ func getNSNetworkHardwareTopology(nsName, netNSDirAbsPath string) ([]InterfaceIn
}

// only return PCI NIC
if !strings.Contains(devPath, nicPathNameDeviceFormatPCI) {
if !strings.Contains(devPath, nicPathNameDeviceFormatPCI) && !bondingNICs.Has(nicName) {
general.Warningf("skip nic: %s with devPath: %s which isn't pci device", nicName, devPath)
continue
}
Expand Down Expand Up @@ -294,3 +298,18 @@ func getInterfaceAddr() (map[string]*IfaceAddr, error) {

return ias, nil
}

func getBondingNetworkInterfaces(bondingMasterPath string) sets.String {
bondingNICs := sets.String{}
lines, err := general.ReadFileIntoLines(bondingMasterPath)
if err != nil {
return bondingNICs
}
for _, line := range lines {
nics := strings.Split(line, " ")
for _, nic := range nics {
bondingNICs.Insert(nic)
}
}
return bondingNICs
}