From 053fc7519a51b466e00b31a919558ca3f11a9d89 Mon Sep 17 00:00:00 2001 From: Fred Rolland Date: Sun, 12 Jan 2025 14:36:23 +0200 Subject: [PATCH] ovs: add internal interface 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 --- pkg/host/internal/bridge/ovs/ovs.go | 9 ++++++++ pkg/host/internal/bridge/ovs/ovs_test.go | 29 ++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/pkg/host/internal/bridge/ovs/ovs.go b/pkg/host/internal/bridge/ovs/ovs.go index 7ad8a3e8c..c586ae1c4 100644 --- a/pkg/host/internal/bridge/ovs/ovs.go +++ b/pkg/host/internal/bridge/ovs/ovs.go @@ -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, + 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, diff --git a/pkg/host/internal/bridge/ovs/ovs_test.go b/pkg/host/internal/bridge/ovs/ovs_test.go index 666fe9218..77623d525 100644 --- a/pkg/host/internal/bridge/ovs/ovs_test.go +++ b/pkg/host/internal/bridge/ovs/ovs_test.go @@ -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)) @@ -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() {