Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20260910-115122.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: Check if a matched network interface is RDMA enabled before registering it to kubernetes
time: 2026-09-10T11:51:22.339221+02:00
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,15 @@ Exposes RDMA character devices for a network interface.
networkRdma:
- matcher: '(^ib0$)'
resourceCount: 4
deviceType: vf # optional: vf or pf
```

Only interfaces with an RDMA-device mapping are exposed. `deviceType: vf`
requires the interface's PCI function to have a `physfn` attribute;
`deviceType: pf` requires a positive `sriov_totalvfs` value. Omitting
`deviceType` disables PF/VF filtering. The `pf` and `vf` values are
case-insensitive.

### Numa affinity

Exposes statically-configured resources that exist purely to fake NUMA affinity. Unlike the other types these resources are **not** backed by udev: the devices are created directly from configuration and are always healthy. Each device advertises a NUMA topology hint for the configured node, so the kubelet topology manager co-locates a requesting pod with that node. Allocating one mounts nothing and sets no env vars.
Expand Down
38 changes: 38 additions & 0 deletions cmd/udev-manager/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/ydb-platform/udev-manager/internal/plugin"
)

// parseYAML is a test helper that parses a YAML string into a appConfig.
Expand Down Expand Up @@ -217,6 +219,30 @@ var _ = Describe("netRdmaConfig.validate", func() {
nc := &netRdmaConfig{Matcher: `[`}
Expect(nc.validate()).To(MatchError(ContainSubstring(".matcher")))
})

DescribeTable("accepts supported device types",
func(deviceType, expected plugin.NetRdmaDeviceType) {
nc := &netRdmaConfig{Matcher: `ib.*`, DeviceType: deviceType}
Expect(nc.validate()).NotTo(HaveOccurred())
Expect(nc.DeviceType).To(Equal(expected))
},
Entry("omitted", plugin.NetRdmaDeviceTypeAny, plugin.NetRdmaDeviceTypeAny),
Entry("lowercase PF", plugin.NetRdmaDeviceTypePF, plugin.NetRdmaDeviceTypePF),
Entry("uppercase PF", plugin.NetRdmaDeviceType("PF"), plugin.NetRdmaDeviceTypePF),
Entry("mixed-case PF", plugin.NetRdmaDeviceType("pF"), plugin.NetRdmaDeviceTypePF),
Entry("lowercase VF", plugin.NetRdmaDeviceTypeVF, plugin.NetRdmaDeviceTypeVF),
Entry("uppercase VF", plugin.NetRdmaDeviceType("VF"), plugin.NetRdmaDeviceTypeVF),
Entry("mixed-case VF", plugin.NetRdmaDeviceType("vF"), plugin.NetRdmaDeviceTypeVF),
)

DescribeTable("rejects unsupported device types",
func(deviceType plugin.NetRdmaDeviceType) {
nc := &netRdmaConfig{Matcher: `ib.*`, DeviceType: deviceType}
Expect(nc.validate()).To(MatchError(ContainSubstring(".deviceType")))
},
Entry("explicit any", plugin.NetRdmaDeviceType("any")),
Entry("unknown value", plugin.NetRdmaDeviceType("nic")),
)
})

var _ = Describe("numaAffinityConfig.validate", func() {
Expand Down Expand Up @@ -332,6 +358,18 @@ networkRdma:
Expect(cfg.NetworkRdma[0].matcher).NotTo(BeNil())
})

It("parses networkRdma deviceType", func() {
cfg := mustParseYAML(`
domain: ydb.tech
networkRdma:
- matcher: "eth(.*)"
resourceCount: 2
deviceType: vf
`)
Expect(cfg.NetworkRdma).To(HaveLen(1))
Expect(string(cfg.NetworkRdma[0].DeviceType)).To(Equal("vf"))
})

It("parses numaAffinity section", func() {
cfg := mustParseYAML(`
domain: ydb.tech
Expand Down
24 changes: 21 additions & 3 deletions cmd/udev-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ func startApp(
discovery,
registry,
plugin.NetRdmaMatcherTemplater(domain, netRdmaConfig.matcher),
plugin.NetRdmaMatcherInstances(domain, netRdmaConfig.matcher, int(netRdmaConfig.ResourceCount)),
plugin.NetRdmaMatcherInstances(
domain,
netRdmaConfig.matcher,
int(netRdmaConfig.ResourceCount),
netRdmaConfig.DeviceType,
),
),
cancel,
)
Expand Down Expand Up @@ -380,8 +385,9 @@ func (nbc *netBWConfig) validate() error {
}

type netRdmaConfig struct {
Matcher string `yaml:"matcher"` // matcher should be a valid regular expression
ResourceCount uint `yaml:"resourceCount"`
Matcher string `yaml:"matcher"` // matcher should be a valid regular expression
ResourceCount uint `yaml:"resourceCount"`
DeviceType plugin.NetRdmaDeviceType `yaml:"deviceType,omitempty"`

matcher *regexp.Regexp // compiled matcher if the config is valid
}
Expand All @@ -393,6 +399,18 @@ func (nrc *netRdmaConfig) validate() error {
return fmt.Errorf(".matcher: %q must be a valid regexp: %w", nrc.Matcher, err)
}
nrc.matcher = matcher
nrc.DeviceType = plugin.NetRdmaDeviceType(strings.ToLower(string(nrc.DeviceType)))

switch nrc.DeviceType {
case plugin.NetRdmaDeviceTypeAny, plugin.NetRdmaDeviceTypePF, plugin.NetRdmaDeviceTypeVF:
default:
return fmt.Errorf(
".deviceType: %q must be either %q, %q, or omitted",
nrc.DeviceType,
plugin.NetRdmaDeviceTypePF,
plugin.NetRdmaDeviceTypeVF,
)
}
return nil
}

Expand Down
117 changes: 111 additions & 6 deletions internal/plugin/net_rdma.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"strconv"
"strings"

"github.com/Mellanox/rdmamap"
Expand All @@ -13,6 +14,21 @@ import (
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
)

// NetRdmaDeviceType restricts networkRdma resources to a particular SR-IOV
// function type. The zero value disables function-type filtering.
type NetRdmaDeviceType string

const (
// NetRdmaDeviceTypeAny disables PF/VF filtering.
NetRdmaDeviceTypeAny NetRdmaDeviceType = ""
// NetRdmaDeviceTypePF selects SR-IOV physical functions.
NetRdmaDeviceTypePF NetRdmaDeviceType = "pf"
// NetRdmaDeviceTypeVF selects SR-IOV virtual functions.
NetRdmaDeviceTypeVF NetRdmaDeviceType = "vf"

netRdmaDeviceTypeUnknown NetRdmaDeviceType = "unknown"
)

type netRdma struct {
domain string
ifname string
Expand Down Expand Up @@ -81,8 +97,34 @@ func NetRdmaMatcherTemplater(domain string, matcher *regexp.Regexp) FromDevice[*
}

// NetRdmaMatcherInstances returns a FromDevice function that produces
// resourcesCount netRdma instances for each matching RDMA-capable net device.
func NetRdmaMatcherInstances(domain string, matcher *regexp.Regexp, resourcesCount int) FromDevice[[]*netRdma] {
// resourcesCount netRdma instances for each matching RDMA-capable net device
// of the requested device type.
func NetRdmaMatcherInstances(
domain string,
matcher *regexp.Regexp,
resourcesCount int,
deviceType NetRdmaDeviceType,
) FromDevice[[]*netRdma] {
return netRdmaMatcherInstances(
domain,
matcher,
resourcesCount,
deviceType,
rdmamap.GetRdmaDeviceForNetdevice,
rdmamap.GetRdmaCharDevices,
classifyNetRdmaDevice,
)
}

func netRdmaMatcherInstances(
domain string,
matcher *regexp.Regexp,
resourcesCount int,
deviceType NetRdmaDeviceType,
lookupDevice func(string) (string, error),
lookupCharDevices func(string) []string,
classifyDevice func(udev.Device) (NetRdmaDeviceType, error),
) FromDevice[[]*netRdma] {
return func(dev udev.Device) ([]*netRdma, error) {
if dev.Subsystem() != udev.NetSubsystem {
return nil, nil
Expand All @@ -97,12 +139,24 @@ func NetRdmaMatcherInstances(domain string, matcher *regexp.Regexp, resourcesCou
return nil, nil
}

rdmaDevice, err := rdmamap.GetRdmaDeviceForNetdevice(ifname)
if err != nil {
klog.Errorf("fail to get rdma devices for network device: %s %v", ifname, err)
if deviceType != NetRdmaDeviceTypeAny {
actualDeviceType, err := classifyDevice(dev)
if err != nil {
return nil, fmt.Errorf("classify network interface %q: %w", ifname, err)
}
if actualDeviceType != deviceType {
return nil, nil
}
}

rdmaDevice, err := lookupDevice(ifname)
if isRdmaNonMatch(ifname, rdmaDevice, err) {
return nil, nil
}
rdmaCharDevices := rdmamap.GetRdmaCharDevices(rdmaDevice)
if err != nil {
return nil, fmt.Errorf("get RDMA device for network interface %q: %w", ifname, err)
}
rdmaCharDevices := lookupCharDevices(rdmaDevice)
klog.Infof("found rdma character devices for ifname: %s devices: %v", ifname, rdmaCharDevices)

instances := make([]*netRdma, 0, resourcesCount)
Expand All @@ -119,3 +173,54 @@ func NetRdmaMatcherInstances(domain string, matcher *regexp.Regexp, resourcesCou
return instances, nil
}
}

func classifyNetRdmaDevice(dev udev.Device) (NetRdmaDeviceType, error) {
for parent := dev.Parent(); parent != nil; parent = parent.Parent() {
if parent.Subsystem() != udev.PciSubsystem {
continue
}

attributeKeys := parent.SystemAttributeKeys()
attributes := make(map[string]struct{}, len(attributeKeys))
for _, attribute := range attributeKeys {
attributes[attribute] = struct{}{}
}

if _, ok := attributes[udev.SysAttrPhysfn]; ok {
return NetRdmaDeviceTypeVF, nil
}

if _, ok := attributes[udev.SysAttrTotalVFs]; !ok {
return netRdmaDeviceTypeUnknown, nil
}

totalVFsString := parent.SystemAttribute(udev.SysAttrTotalVFs)
totalVFs, err := strconv.ParseUint(totalVFsString, 10, 32)
if err != nil {
return netRdmaDeviceTypeUnknown, fmt.Errorf(
"parse %s value %q: %w",
udev.SysAttrTotalVFs,
totalVFsString,
err,
)
}
if totalVFs > 0 {
return NetRdmaDeviceTypePF, nil
}
return netRdmaDeviceTypeUnknown, nil
}

return netRdmaDeviceTypeUnknown, nil
}

func isRdmaNonMatch(ifname, rdmaDevice string, err error) bool {
if err == nil {
// rdmamap returns an empty device without an error when an IPoIB
// interface has no matching RDMA device.
return rdmaDevice == ""
}

// rdmamap does not expose sentinel errors for these definitive non-matches.
return err.Error() == fmt.Sprintf("rdma device not found for netdev %s", ifname) ||
err.Error() == "unknown device type"
}
Loading
Loading