Skip to content

Commit

Permalink
ovs: add internal interface
Browse files Browse the repository at this point in the history
When creating a bridge with ovs-vsctl, an internal
interface is added by default.
The same behavior is added in this commit

ovs-vsctl code ref:
https://github.com/openvswitch/ovs/blob/main/utilities/ovs-vsctl.c#L1597

Signed-off-by: Fred Rolland <[email protected]>
  • Loading branch information
rollandf committed Jan 12, 2025
1 parent d62b546 commit 053fc75
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
9 changes: 9 additions & 0 deletions pkg/host/internal/bridge/ovs/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ func (o *ovs) CreateOVSBridge(ctx context.Context, conf *sriovnetworkv1.OVSConfi
funcLog.Error(err, "CreateOVSBridge(): failed to get bridge after creation")
return err
}
funcLog.V(2).Info("CreateOVSBridge(): add internal interface to the bridge")
if err := o.addInterface(ctx, dbClient, bridge, &InterfaceEntry{
Name: bridge.Name,

Check failure on line 153 in pkg/host/internal/bridge/ovs/ovs.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

File is not `gofmt`-ed with `-s` (gofmt)
UUID: uuid.NewString(),
Type: "internal",
}); err != nil {
funcLog.Error(err, "CreateOVSBridge(): failed to add internal interface to the bridge")
return err
}
funcLog.V(2).Info("CreateOVSBridge(): add uplink interface to the bridge")
if err := o.addInterface(ctx, dbClient, bridge, &InterfaceEntry{
Name: conf.Uplinks[0].Name,
Expand Down
29 changes: 25 additions & 4 deletions pkg/host/internal/bridge/ovs/ovs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,26 @@ func createInitialDBContent(ctx context.Context, c client.Client, expectedState
func validateDBConfig(dbContent *testDBEntries, conf *sriovnetworkv1.OVSConfigExt) {
Expect(dbContent.OpenVSwitch).To(HaveLen(1))
Expect(dbContent.Bridge).To(HaveLen(1))
Expect(dbContent.Interface).To(HaveLen(1))
Expect(dbContent.Port).To(HaveLen(1))
Expect(dbContent.Interface).To(HaveLen(2))
Expect(dbContent.Port).To(HaveLen(2))
ovs := dbContent.OpenVSwitch[0]
br := dbContent.Bridge[0]
port := dbContent.Port[0]
iface := dbContent.Interface[0]
var internalPort, port *PortEntry
var internalIface, iface *InterfaceEntry
for _, p := range dbContent.Port {
if p.Name == conf.Name {
internalPort = p
} else {
port = p
}
}
for _, ifc := range dbContent.Interface {
if ifc.Name == conf.Name {
internalIface = ifc
} else {
iface = ifc
}
}
Expect(ovs.Bridges).To(ContainElement(br.UUID))
Expect(br.Name).To(Equal(conf.Name))
Expect(br.DatapathType).To(Equal(conf.Bridge.DatapathType))
Expand All @@ -156,6 +170,13 @@ func validateDBConfig(dbContent *testDBEntries, conf *sriovnetworkv1.OVSConfigEx
Expect(iface.Type).To(Equal(conf.Uplinks[0].Interface.Type))
Expect(iface.OtherConfig).To(Equal(conf.Uplinks[0].Interface.OtherConfig))
Expect(iface.ExternalIDs).To(Equal(conf.Uplinks[0].Interface.ExternalIDs))
Expect(internalPort.Name).To(Equal(conf.Name))
Expect(internalPort.Interfaces).To(ContainElement(internalIface.UUID))
Expect(internalIface.Name).To(Equal(conf.Name))
Expect(internalIface.Options).To(BeNil())
Expect(internalIface.Type).To(Equal("internal"))
Expect(internalIface.OtherConfig).To(BeNil())
Expect(internalIface.ExternalIDs).To(BeNil())
}

var _ = Describe("OVS", func() {
Expand Down

0 comments on commit 053fc75

Please sign in to comment.