Skip to content

Commit

Permalink
Make advertising of NUMA node optional
Browse files Browse the repository at this point in the history
This change adds support for making advertising of NUMA node optional.
This can be done per resource pool by setting the config
"exclude_topology" to true. Default behavior is to advertise NUMA node
information.

Signed-off-by: Ravindra Thakur <[email protected]>
  • Loading branch information
rthakur-est committed Mar 22, 2022
1 parent 4433b72 commit ab5f250
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 16 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
github.com/vishvananda/netlink v1.1.1-0.20211101163509-b10eb8fe5cf6
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
google.golang.org/grpc v1.28.1
k8s.io/kubelet v0.18.1
)
Expand Down
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae h1:4hwBBUfQCFe3C
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -190,13 +191,19 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -211,6 +218,7 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -224,6 +232,7 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -239,8 +248,10 @@ golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -264,8 +275,11 @@ golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
5 changes: 3 additions & 2 deletions pkg/accelerator/accelDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ type accelDevice struct {
}

// NewAccelDevice returns an instance of AccelDevice interface
func NewAccelDevice(dev *ghw.PCIDevice, rFactory types.ResourceFactory) (types.AccelDevice, error) {
pciDev, err := resources.NewPciDevice(dev, rFactory, nil)
func NewAccelDevice(dev *ghw.PCIDevice, rFactory types.ResourceFactory,
rc *types.ResourceConfig) (types.AccelDevice, error) {
pciDev, err := resources.NewPciDevice(dev, rFactory, rc, nil)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/accelerator/accelDeviceProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (ap *accelDeviceProvider) GetDiscoveredDevices() []*ghw.PCIDevice {
func (ap *accelDeviceProvider) GetDevices(rc *types.ResourceConfig) []types.PciDevice {
newPciDevices := make([]types.PciDevice, 0)
for _, device := range ap.deviceList {
if newDevice, err := NewAccelDevice(device, ap.rFactory); err == nil {
if newDevice, err := NewAccelDevice(device, ap.rFactory, rc); err == nil {
newPciDevices = append(newPciDevices, newDevice)
} else {
glog.Errorf("accelerator GetDevices() error creating new device: %q", err)
Expand Down
42 changes: 37 additions & 5 deletions pkg/accelerator/accelDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/accelerator"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/factory"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -46,8 +47,9 @@ var _ = Describe("Accelerator", func() {

f := factory.NewResourceFactory("fake", "fake", true)
in := &ghw.PCIDevice{Address: "0000:00:00.1"}
config := &types.ResourceConfig{}

out, err := accelerator.NewAccelDevice(in, f)
out, err := accelerator.NewAccelDevice(in, f, config)

// TODO: assert other fields once implemented
Expect(out.GetDriver()).To(Equal("vfio-pci"))
Expand Down Expand Up @@ -75,8 +77,9 @@ var _ = Describe("Accelerator", func() {

f := factory.NewResourceFactory("fake", "fake", true)
in := &ghw.PCIDevice{Address: "0000:00:00.1"}
config := &types.ResourceConfig{}

out, err := accelerator.NewAccelDevice(in, f)
out, err := accelerator.NewAccelDevice(in, f, config)

Expect(out.GetAPIDevice().Topology).To(BeNil())
Expect(out.GetNumaInfo()).To(Equal(""))
Expand All @@ -99,8 +102,35 @@ var _ = Describe("Accelerator", func() {

f := factory.NewResourceFactory("fake", "fake", true)
in := &ghw.PCIDevice{Address: "0000:00:00.1"}
config := &types.ResourceConfig{}

out, err := accelerator.NewAccelDevice(in, f)
out, err := accelerator.NewAccelDevice(in, f, config)

Expect(out.GetAPIDevice().Topology).To(BeNil())
Expect(out.GetNumaInfo()).To(Equal(""))
Expect(err).NotTo(HaveOccurred())
})
It("should not populate topology due to config excluding topology being set", func() {
fs := &utils.FakeFilesystem{
Dirs: []string{
"sys/bus/pci/devices/0000:00:00.1/net/eth0",
"sys/kernel/iommu_groups/0",
"sys/bus/pci/drivers/vfio-pci",
},
Symlinks: map[string]string{
"sys/bus/pci/devices/0000:00:00.1/iommu_group": "../../../../kernel/iommu_groups/0",
"sys/bus/pci/devices/0000:00:00.1/driver": "../../../../bus/pci/drivers/vfio-pci",
},
Files: map[string][]byte{"sys/bus/pci/devices/0000:00:00.1/numa_node": []byte("1")},
}
defer fs.Use()()
utils.SetDefaultMockNetlinkProvider()

f := factory.NewResourceFactory("fake", "fake", true)
in := &ghw.PCIDevice{Address: "0000:00:00.1"}
config := &types.ResourceConfig{ExcludeTopology: true}

out, err := accelerator.NewAccelDevice(in, f, config)

Expect(out.GetAPIDevice().Topology).To(BeNil())
Expect(out.GetNumaInfo()).To(Equal(""))
Expand All @@ -120,8 +150,9 @@ var _ = Describe("Accelerator", func() {
in := &ghw.PCIDevice{
Address: "0000:00:00.1",
}
config := &types.ResourceConfig{}

dev, err := accelerator.NewAccelDevice(in, f)
dev, err := accelerator.NewAccelDevice(in, f, config)

Expect(dev).To(BeNil())
Expect(err).To(HaveOccurred())
Expand All @@ -143,8 +174,9 @@ var _ = Describe("Accelerator", func() {
in := &ghw.PCIDevice{
Address: "0000:00:00.1",
}
config := &types.ResourceConfig{}

dev, err := accelerator.NewAccelDevice(in, f)
dev, err := accelerator.NewAccelDevice(in, f, config)
Expect(err).NotTo(HaveOccurred())
Expect(dev).NotTo(BeNil())
Expect(dev.GetEnvVal()).To(Equal("0000:00:00.1"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/netdevice/pciNetDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewPciNetDevice(dev *ghw.PCIDevice, rFactory types.ResourceFactory, rc *typ
}
}

pciDev, err := resources.NewPciDevice(dev, rFactory, infoProviders)
pciDev, err := resources.NewPciDevice(dev, rFactory, rc, infoProviders)
if err != nil {
return nil, err
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/netdevice/pciNetDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,32 @@ var _ = Describe("PciNetDevice", func() {

dev, err := netdevice.NewPciNetDevice(in, f, rc)

Expect(dev.GetAPIDevice().Topology).To(BeNil())
Expect(dev.GetNumaInfo()).To(Equal(""))
Expect(err).NotTo(HaveOccurred())
})
It("should not populate topology due to config option being set", func() {
fs := &utils.FakeFilesystem{
Dirs: []string{
"sys/bus/pci/devices/0000:00:00.1/net/eth0",
"sys/kernel/iommu_groups/0",
"sys/bus/pci/drivers/vfio-pci",
},
Symlinks: map[string]string{
"sys/bus/pci/devices/0000:00:00.1/iommu_group": "../../../../kernel/iommu_groups/0",
"sys/bus/pci/devices/0000:00:00.1/driver": "../../../../bus/pci/drivers/vfio-pci",
},
Files: map[string][]byte{"sys/bus/pci/devices/0000:00:00.1/numa_node": []byte("0")},
}
defer fs.Use()()
utils.SetDefaultMockNetlinkProvider()

f := factory.NewResourceFactory("fake", "fake", true)
in := &ghw.PCIDevice{Address: "0000:00:00.1"}
rc := &types.ResourceConfig{ExcludeTopology: true}

dev, err := netdevice.NewPciNetDevice(in, f, rc)

Expect(dev.GetAPIDevice().Topology).To(BeNil())
Expect(dev.GetNumaInfo()).To(Equal(""))
Expect(err).NotTo(HaveOccurred())
Expand Down
8 changes: 6 additions & 2 deletions pkg/resources/pciDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func nodeToStr(nodeNum int) string {
// NewPciDevice returns an instance of PciDevice interface
// A list of DeviceInfoProviders can be set externally.
// If empty, the default driver-based selection provided by ResourceFactory will be used
func NewPciDevice(dev *ghw.PCIDevice, rFactory types.ResourceFactory, infoProviders []types.DeviceInfoProvider) (types.PciDevice, error) {
func NewPciDevice(dev *ghw.PCIDevice, rFactory types.ResourceFactory, rc *types.ResourceConfig,
infoProviders []types.DeviceInfoProvider) (types.PciDevice, error) {
pciAddr := dev.Address

// Get PF PCI address
Expand All @@ -70,8 +71,11 @@ func NewPciDevice(dev *ghw.PCIDevice, rFactory types.ResourceFactory, infoProvid
if len(infoProviders) == 0 {
infoProviders = append(infoProviders, rFactory.GetDefaultInfoProvider(pciAddr, driverName))
}
nodeNum := -1
if !rc.ExcludeTopology {
nodeNum = utils.GetDevNode(pciAddr)
}

nodeNum := utils.GetDevNode(pciAddr)
apiDevice := &pluginapi.Device{
ID: pciAddr,
Health: pluginapi.Healthy,
Expand Down
11 changes: 6 additions & 5 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ var SupportedDevices = map[DeviceType]int{
// ResourceConfig contains configuration parameters for a resource pool
type ResourceConfig struct {
// optional resource prefix that will overwrite global prefix specified in cli params
ResourcePrefix string `json:"resourcePrefix,omitempty"`
ResourceName string `json:"resourceName"` // the resource name will be added with resource prefix in K8s api
DeviceType DeviceType `json:"deviceType,omitempty"`
Selectors *json.RawMessage `json:"selectors,omitempty"`
SelectorObj interface{}
ResourcePrefix string `json:"resourcePrefix,omitempty"`
ResourceName string `json:"resourceName"` // the resource name will be added with resource prefix in K8s api
DeviceType DeviceType `json:"deviceType,omitempty"`
ExcludeTopology bool `json:"exclude_topology,omitempty"`
Selectors *json.RawMessage `json:"selectors,omitempty"`
SelectorObj interface{}
}

// DeviceSelectors contains common device selectors fields
Expand Down

0 comments on commit ab5f250

Please sign in to comment.