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

Allow multiple physical interface support for secondary network bridge #5959

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions cmd/antrea-agent/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,8 @@ func (o *Options) validateSecondaryNetworkConfig() error {
if brConfig.BridgeName == "" {
return fmt.Errorf("bridge name is not provided for the secondary network OVS bridge")
}
if len(brConfig.PhysicalInterfaces) > 1 {
return fmt.Errorf("at most one physical interface can be specified for the secondary network OVS bridge")
if len(brConfig.PhysicalInterfaces) > 8 {
return fmt.Errorf("at most eight physical interfaces can be specified for the secondary network OVS bridge")
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/antrea-agent/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ func TestOptionsValidateSecondaryNetworkConfig(t *testing.T) {
name: "two interfaces",
featureGateValue: true,
ovsBridges: []string{"br1"},
physicalInterfaces: []string{"eth1", "eth2"},
expectedErr: "at most one physical interface can be specified for the secondary network OVS bridge",
physicalInterfaces: []string{"eth1", "eth2", "eth3", "eth4", "eth5", "eth6", "eth7", "eth8", "eth9"},
expectedErr: "at most eight physical interfaces can be specified for the secondary network OVS bridge",
},
}
for _, tc := range tests {
Expand Down
4 changes: 2 additions & 2 deletions docs/secondary-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ data:
```

At the moment, Antrea supports only a single OVS bridge for secondary networks,
and supports only a single physical interface on the bridge. The physical
interface cannot be the Node's management interface, otherwise the Node's
and supports upto eight physical interfaces on the bridge. The physical
interfaces cannot be the Node's management interface, otherwise the Node's
management network connectivity can be broken after `antrea-agent` creates the
OVS bridge and moves the management interface to the bridge.

Expand Down
28 changes: 11 additions & 17 deletions pkg/agent/secondarynetwork/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

var (
// Funcs which will be orridden with mock funcs in tests.
// Funcs which will be overridden with mock funcs in tests.
aroradaman marked this conversation as resolved.
Show resolved Hide resolved
interfaceByNameFn = net.InterfaceByName
newOVSBridgeFn = ovsconfig.NewOVSBridge
)
Expand Down Expand Up @@ -82,9 +82,7 @@ func createOVSBridge(bridges []agentconfig.OVSBridgeConfig, ovsdb *ovsdb.OVSDB)
// Only one OVS bridge is supported.
bridgeConfig := bridges[0]

phyInterface := ""
if len(bridgeConfig.PhysicalInterfaces) > 0 {
phyInterface = bridgeConfig.PhysicalInterfaces[0]
for _, phyInterface := range bridgeConfig.PhysicalInterfaces {
if _, err := interfaceByNameFn(phyInterface); err != nil {
return nil, fmt.Errorf("failed to get interface %s: %v", phyInterface, err)
}
Expand All @@ -96,21 +94,17 @@ func createOVSBridge(bridges []agentconfig.OVSBridgeConfig, ovsdb *ovsdb.OVSDB)
}
klog.InfoS("OVS bridge created", "bridge", bridgeConfig.BridgeName)

if phyInterface == "" {
return ovsBridgeClient, nil
}

if _, err := ovsBridgeClient.GetOFPort(phyInterface, false); err == nil {
klog.V(2).InfoS("Physical interface already connected to OVS bridge, skip the configuration", "device", phyInterface, "bridge", bridgeConfig.BridgeName)
return ovsBridgeClient, nil
}
for i, phyInterface := range bridgeConfig.PhysicalInterfaces {
if _, err := ovsBridgeClient.GetOFPort(phyInterface, false); err == nil {
klog.V(2).InfoS("Physical interface already connected to OVS bridge, skip the configuration", "device", phyInterface, "bridge", bridgeConfig.BridgeName)
continue
}

_, err := ovsBridgeClient.CreateUplinkPort(phyInterface, 0, map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaUplink})
if err != nil {
return nil, fmt.Errorf("failed to create OVS uplink port %s: %v", phyInterface, err)
if _, err := ovsBridgeClient.CreateUplinkPort(phyInterface, int32(i), map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaUplink}); err != nil {
return nil, fmt.Errorf("failed to create OVS uplink port %s: %v", phyInterface, err)
}
klog.InfoS("Physical interface added to OVS bridge", "device", phyInterface, "bridge", bridgeConfig.BridgeName)
}
klog.InfoS("Physical interface added to OVS bridge", "device", phyInterface, "bridge", bridgeConfig.BridgeName)

return ovsBridgeClient, nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/secondarynetwork/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func TestCreateOVSBridge(t *testing.T) {
m.EXPECT().Create().Return(nil)
m.EXPECT().GetOFPort("eth1", false).Return(int32(0), ovsconfig.InvalidArgumentsError("port not found"))
m.EXPECT().CreateUplinkPort("eth1", int32(0), map[string]interface{}{"antrea-type": "uplink"}).Return("", nil)
m.EXPECT().GetOFPort("eth2", false).Return(int32(1), ovsconfig.InvalidArgumentsError("port not found"))
m.EXPECT().CreateUplinkPort("eth2", int32(1), map[string]interface{}{"antrea-type": "uplink"}).Return("", nil)
},
},
{
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ type SecondaryNetworkConfig struct {

type OVSBridgeConfig struct {
BridgeName string `yaml:"bridgeName"`
// Names of physical interfaces to be connected to the bridge. At the moment,
// only a single physical interface is supported.
// Names of physical interfaces to be connected to the bridge.
PhysicalInterfaces []string `yaml:"physicalInterfaces,omitempty"`
}
Loading