Skip to content

Commit

Permalink
Report VF representor name in the status field
Browse files Browse the repository at this point in the history
Add support for reporting VF representor
name when the NIC is in switchev mode

Signed-off-by: Yury Kulazhenkov <ykulazhenkov@nvidia.com>
  • Loading branch information
ykulazhenkov committed May 3, 2024
1 parent 3ed45fe commit 7ac48ee
Show file tree
Hide file tree
Showing 36 changed files with 2,504 additions and 77 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/jaypipes/ghw v0.9.0
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
github.com/k8snetworkplumbingwg/sriov-network-device-plugin v0.0.0-20221127172732-a5a7395122e3
github.com/k8snetworkplumbingwg/sriovnet v1.2.0
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.10
github.com/openshift-kni/k8sreporter v1.0.4
Expand Down Expand Up @@ -115,7 +116,7 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/afero v1.9.4 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace // indirect
github.com/stretchr/objx v0.5.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0 h1:V
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0/go.mod h1:nqCI7aelBJU61wiBeeZWJ6oi4bJy5nrjkM6lWIMA4j0=
github.com/k8snetworkplumbingwg/sriov-network-device-plugin v0.0.0-20221127172732-a5a7395122e3 h1:hIHzF4vNTCFb9UMngrcJAMvdNslCekaSvNbfQt21CUw=
github.com/k8snetworkplumbingwg/sriov-network-device-plugin v0.0.0-20221127172732-a5a7395122e3/go.mod h1:b0YSmUuNOy6CkEmV27XfmZ3a7njs2pjxHoFAvfLbUII=
github.com/k8snetworkplumbingwg/sriovnet v1.2.0 h1:6ELfAxCB1dvosGUy3DVRmfH+HWTzmPD3W67HKQvMR1M=
github.com/k8snetworkplumbingwg/sriovnet v1.2.0/go.mod h1:jyWzGe6ZtYiPq6ih6aXCOy6mZ49Y9mNyBOLBBXnli+k=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
Expand Down Expand Up @@ -398,8 +400,8 @@ github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFR
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU=
github.com/spf13/afero v1.4.1/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk=
github.com/spf13/afero v1.9.3/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
github.com/spf13/afero v1.9.4 h1:Sd43wM1IWz/s1aVXdOBkjJvuP8UdyqioeE4AmM0QsBs=
github.com/spf13/afero v1.9.4/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
Expand Down
15 changes: 0 additions & 15 deletions pkg/helper/mock/mock_helper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions pkg/host/internal/lib/sriovnet/mock/mock_sriovnet.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions pkg/host/internal/lib/sriovnet/sriovnet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sriovnet

import (
"github.com/k8snetworkplumbingwg/sriovnet"
)

func New() SriovnetLib {
return &libWrapper{}
}

//go:generate ../../../../../bin/mockgen -destination mock/mock_sriovnet.go -source sriovnet.go
type SriovnetLib interface {
// GetVfRepresentor returns representor name for VF device
GetVfRepresentor(uplink string, vfIndex int) (string, error)
}

type libWrapper struct{}

// GetVfRepresentor returns representor name for VF device
func (w *libWrapper) GetVfRepresentor(pfName string, vfIndex int) (string, error) {
return sriovnet.GetVfRepresentor(pfName, vfIndex)
}
37 changes: 25 additions & 12 deletions pkg/host/internal/sriov/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
dputilsPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/dputils"
netlinkPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/netlink"
sriovnetPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/sriovnet"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/store"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/types"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils"
Expand All @@ -38,6 +39,7 @@ type sriov struct {
vdpaHelper types.VdpaInterface
netlinkLib netlinkPkg.NetlinkLib
dputilsLib dputilsPkg.DPUtilsLib
sriovnetLib sriovnetPkg.SriovnetLib
}

func New(utilsHelper utils.CmdInterface,
Expand All @@ -46,14 +48,16 @@ func New(utilsHelper utils.CmdInterface,
udevHelper types.UdevInterface,
vdpaHelper types.VdpaInterface,
netlinkLib netlinkPkg.NetlinkLib,
dputilsLib dputilsPkg.DPUtilsLib) types.SriovInterface {
dputilsLib dputilsPkg.DPUtilsLib,
sriovnetLib sriovnetPkg.SriovnetLib) types.SriovInterface {
return &sriov{utilsHelper: utilsHelper,
kernelHelper: kernelHelper,
networkHelper: networkHelper,
udevHelper: udevHelper,
vdpaHelper: vdpaHelper,
netlinkLib: netlinkLib,
dputilsLib: dputilsLib,
sriovnetLib: sriovnetLib,
}
}

Expand Down Expand Up @@ -108,26 +112,35 @@ func (s *sriov) ResetSriovDevice(ifaceStatus sriovnetworkv1.InterfaceExt) error
return nil
}

func (s *sriov) GetVfInfo(pciAddr string, devices []*ghw.PCIDevice) sriovnetworkv1.VirtualFunction {
driver, err := s.dputilsLib.GetDriverName(pciAddr)
func (s *sriov) getVfInfo(vfAddr string, pfName string, eswitchMode string, devices []*ghw.PCIDevice) sriovnetworkv1.VirtualFunction {
driver, err := s.dputilsLib.GetDriverName(vfAddr)
if err != nil {
log.Log.Error(err, "getVfInfo(): unable to parse device driver", "device", pciAddr)
log.Log.Error(err, "getVfInfo(): unable to parse device driver", "device", vfAddr)
}
id, err := s.dputilsLib.GetVFID(pciAddr)
id, err := s.dputilsLib.GetVFID(vfAddr)
if err != nil {
log.Log.Error(err, "getVfInfo(): unable to get VF index", "device", pciAddr)
log.Log.Error(err, "getVfInfo(): unable to get VF index", "device", vfAddr)
}
vf := sriovnetworkv1.VirtualFunction{
PciAddress: pciAddr,
PciAddress: vfAddr,
Driver: driver,
VfID: id,
VdpaType: s.vdpaHelper.DiscoverVDPAType(pciAddr),
VdpaType: s.vdpaHelper.DiscoverVDPAType(vfAddr),
}

if name := s.networkHelper.TryGetInterfaceName(pciAddr); name != "" {
if eswitchMode == sriovnetworkv1.ESwithModeSwitchDev {
repName, err := s.sriovnetLib.GetVfRepresentor(pfName, id)
if err != nil {
log.Log.Error(err, "getVfInfo(): failed to get VF representor name", "device", vfAddr)
} else {
vf.RepresentorName = repName
}
}

if name := s.networkHelper.TryGetInterfaceName(vfAddr); name != "" {
link, err := s.netlinkLib.LinkByName(name)
if err != nil {
log.Log.Error(err, "getVfInfo(): unable to get VF Link Object", "name", name, "device", pciAddr)
log.Log.Error(err, "getVfInfo(): unable to get VF Link Object", "name", name, "device", vfAddr)
} else {
vf.Name = name
vf.Mtu = link.Attrs().MTU
Expand All @@ -136,7 +149,7 @@ func (s *sriov) GetVfInfo(pciAddr string, devices []*ghw.PCIDevice) sriovnetwork
}

for _, device := range devices {
if pciAddr == device.Address {
if vfAddr == device.Address {
vf.Vendor = device.Vendor.ID
vf.DeviceID = device.Product.ID
break
Expand Down Expand Up @@ -291,7 +304,7 @@ func (s *sriov) DiscoverSriovDevices(storeManager store.ManagerInterface) ([]sri
continue
}
for _, vf := range vfs {
instance := s.GetVfInfo(vf, devices)
instance := s.getVfInfo(vf, pfNetName, iface.EswitchMode, devices)
iface.VFs = append(iface.VFs, instance)
}
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/host/internal/sriov/sriov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
dputilsMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/dputils/mock"
netlinkMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/netlink/mock"
sriovnetMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/sriovnet/mock"
hostMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/mock"
hostStoreMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/store/mock"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/types"
Expand All @@ -27,6 +28,7 @@ var _ = Describe("SRIOV", func() {
s types.SriovInterface
netlinkLibMock *netlinkMockPkg.MockNetlinkLib
dputilsLibMock *dputilsMockPkg.MockDPUtilsLib
sriovnetLibMock *sriovnetMockPkg.MockSriovnetLib
hostMock *hostMockPkg.MockHostManagerInterface
storeManagerMode *hostStoreMockPkg.MockManagerInterface

Expand All @@ -38,10 +40,12 @@ var _ = Describe("SRIOV", func() {
testCtrl = gomock.NewController(GinkgoT())
netlinkLibMock = netlinkMockPkg.NewMockNetlinkLib(testCtrl)
dputilsLibMock = dputilsMockPkg.NewMockDPUtilsLib(testCtrl)
sriovnetLibMock = sriovnetMockPkg.NewMockSriovnetLib(testCtrl)

hostMock = hostMockPkg.NewMockHostManagerInterface(testCtrl)
storeManagerMode = hostStoreMockPkg.NewMockManagerInterface(testCtrl)

s = New(nil, hostMock, hostMock, hostMock, hostMock, netlinkLibMock, dputilsLibMock)
s = New(nil, hostMock, hostMock, hostMock, hostMock, netlinkLibMock, dputilsLibMock, sriovnetLibMock)
})

AfterEach(func() {
Expand Down
4 changes: 3 additions & 1 deletion pkg/host/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/dputils"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/ethtool"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/netlink"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/sriovnet"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/network"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/service"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/sriov"
Expand Down Expand Up @@ -40,12 +41,13 @@ func NewHostManager(utilsInterface utils.CmdInterface) HostManagerInterface {
dpUtils := dputils.New()
netlinkLib := netlink.New()
ethtoolLib := ethtool.New()
sriovnetLib := sriovnet.New()
k := kernel.New(utilsInterface)
n := network.New(utilsInterface, dpUtils, netlinkLib, ethtoolLib)
sv := service.New(utilsInterface)
u := udev.New(utilsInterface)
v := vdpa.New(k, netlinkLib)
sr := sriov.New(utilsInterface, k, n, u, v, netlinkLib, dpUtils)
sr := sriov.New(utilsInterface, k, n, u, v, netlinkLib, dpUtils, sriovnetLib)

return &hostManager{
utilsInterface,
Expand Down
15 changes: 0 additions & 15 deletions pkg/host/mock/mock_host.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions pkg/host/types/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"github.com/jaypipes/ghw"
"github.com/vishvananda/netlink"

sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
Expand Down Expand Up @@ -130,8 +129,6 @@ type SriovInterface interface {
// SetSriovNumVfs changes the number of virtual functions allocated for a specific
// physical function base on pci address
SetSriovNumVfs(pciAddr string, numVfs int) error
// GetVfInfo returns the virtual function information is the operator struct from the host information
GetVfInfo(pciAddr string, devices []*ghw.PCIDevice) sriovnetworkv1.VirtualFunction
// SetVfGUID sets the GUID for a virtual function
SetVfGUID(vfAddr string, pfLink netlink.Link) error
// VFIsReady returns the interface virtual function if the device is ready
Expand Down
Loading

0 comments on commit 7ac48ee

Please sign in to comment.