Skip to content

Commit

Permalink
Merge pull request #690 from ykulazhenkov/pr-report-representor
Browse files Browse the repository at this point in the history
[software-bridges 2/x] report VF representor name in SriovNetworkNodeState.Status field
  • Loading branch information
adrianchiris authored Jun 25, 2024
2 parents 42bd6a5 + 808907f commit 19b4cb6
Show file tree
Hide file tree
Showing 38 changed files with 2,815 additions and 79 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/jaypipes/ghw v0.9.0
github.com/jaypipes/pcidb v1.0.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 @@ -93,7 +95,6 @@ require (
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jaypipes/pcidb v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/k8snetworkplumbingwg/govdpa v0.1.4 // indirect
Expand All @@ -120,7 +121,7 @@ require (
github.com/robfig/cron v1.2.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 @@ -299,6 +299,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 @@ -403,8 +405,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.

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

import (
"github.com/jaypipes/ghw"
)

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

//go:generate ../../../../../bin/mockgen -destination mock/mock_ghw.go -source ghw.go
type GHWLib interface {
// PCI returns a pointer to an Info that provide methods to access info about devices
PCI() (Info, error)
}

// Info interface provide methods to access info about devices
type Info interface {
// ListDevices returns a list of pointers to Device structs present on the
// host system
ListDevices() []*ghw.PCIDevice
}

type libWrapper struct{}

// PCI returns a pointer to an Info that provide methods to access info about devices
func (w *libWrapper) PCI() (Info, error) {
return ghw.PCI()
}
88 changes: 88 additions & 0 deletions pkg/host/internal/lib/ghw/mock/mock_ghw.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)
}
43 changes: 30 additions & 13 deletions pkg/host/internal/sriov/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
dputilsPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/dputils"
ghwPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/ghw"
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 +40,8 @@ type sriov struct {
vdpaHelper types.VdpaInterface
netlinkLib netlinkPkg.NetlinkLib
dputilsLib dputilsPkg.DPUtilsLib
sriovnetLib sriovnetPkg.SriovnetLib
ghwLib ghwPkg.GHWLib
}

func New(utilsHelper utils.CmdInterface,
Expand All @@ -46,14 +50,18 @@ 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,
ghwLib ghwPkg.GHWLib) types.SriovInterface {
return &sriov{utilsHelper: utilsHelper,
kernelHelper: kernelHelper,
networkHelper: networkHelper,
udevHelper: udevHelper,
vdpaHelper: vdpaHelper,
netlinkLib: netlinkLib,
dputilsLib: dputilsLib,
sriovnetLib: sriovnetLib,
ghwLib: ghwLib,
}
}

Expand Down Expand Up @@ -108,26 +116,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 @@ -137,7 +154,7 @@ func (s *sriov) GetVfInfo(pciAddr string, devices []*ghw.PCIDevice) sriovnetwork
vf.GUID = s.networkHelper.GetNetDevNodeGUID(pciAddr)

Check failure on line 154 in pkg/host/internal/sriov/sriov.go

View workflow job for this annotation

GitHub Actions / build

undefined: pciAddr) (typecheck)

Check failure on line 154 in pkg/host/internal/sriov/sriov.go

View workflow job for this annotation

GitHub Actions / build

undefined: pciAddr (typecheck)

Check failure on line 154 in pkg/host/internal/sriov/sriov.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

undefined: pciAddr) (typecheck)

Check failure on line 154 in pkg/host/internal/sriov/sriov.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

undefined: pciAddr (typecheck)

Check failure on line 154 in pkg/host/internal/sriov/sriov.go

View workflow job for this annotation

GitHub Actions / test

undefined: pciAddr

Check failure on line 154 in pkg/host/internal/sriov/sriov.go

View workflow job for this annotation

GitHub Actions / test-coverage

undefined: pciAddr

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 @@ -205,7 +222,7 @@ func (s *sriov) DiscoverSriovDevices(storeManager store.ManagerInterface) ([]sri
log.Log.V(2).Info("DiscoverSriovDevices")
pfList := []sriovnetworkv1.InterfaceExt{}

pci, err := ghw.PCI()
pci, err := s.ghwLib.PCI()
if err != nil {
return nil, fmt.Errorf("DiscoverSriovDevices(): error getting PCI info: %v", err)
}
Expand Down Expand Up @@ -293,7 +310,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
Loading

0 comments on commit 19b4cb6

Please sign in to comment.