Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.
Closed
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
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/google/cel-go v0.26.0
github.com/google/go-cmp v0.7.0
github.com/insomniacslk/dhcp v0.0.0-20250417080101-5f8cf70e8c5f
github.com/jaypipes/ghw v0.17.0
github.com/mdlayher/genetlink v1.3.2
github.com/mdlayher/netlink v1.7.2
github.com/prometheus/client_golang v1.23.0
Expand All @@ -47,6 +48,7 @@ require (
cel.dev/expr v0.24.0 // indirect
cloud.google.com/go/auth v0.16.3 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand All @@ -58,6 +60,7 @@ require (
github.com/fxamacker/cbor/v2 v2.8.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.21.1 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
Expand All @@ -68,13 +71,15 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jaypipes/pcidb v1.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/josharian/native v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knqyf263/go-plugin v0.9.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mdlayher/packet v1.1.2 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down Expand Up @@ -116,6 +121,7 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v1.0.0 // indirect
k8s.io/cri-api v0.34.0-beta.0 // indirect
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
k8s.io/kubelet v0.33.3 // indirect
Expand Down
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ cloud.google.com/go/container v1.44.0 h1:JEHeW535svvNwJrjrlQ/cdjd15LCWrPKnHsulru
cloud.google.com/go/container v1.44.0/go.mod h1:tVK2o4UZUTkg9WpBcgj4qRzwGA1dSFdWA3mil3YkLIQ=
github.com/Mellanox/rdmamap v1.1.0 h1:A/W1wAXw+6vm58f3VklrIylgV+eDJlPVIMaIKuxgUT4=
github.com/Mellanox/rdmamap v1.1.0/go.mod h1:fN+/V9lf10ABnDCwTaXRjeeWijLt2iVLETnK+sx/LY8=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -44,6 +46,9 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-openapi/jsonpointer v0.21.1 h1:whnzv/pNXtK2FbX/W9yJfRmE2gsmkfahjMKB0fZvcic=
github.com/go-openapi/jsonpointer v0.21.1/go.mod h1:50I1STOfbY1ycR8jGz8DaMeLCdXiI6aDteEdRNNzpdk=
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
Expand Down Expand Up @@ -81,6 +86,11 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/insomniacslk/dhcp v0.0.0-20250417080101-5f8cf70e8c5f h1:dd33oobuIv9PcBVqvbEiCXEbNTomOHyj3WFuC5YiPRU=
github.com/insomniacslk/dhcp v0.0.0-20250417080101-5f8cf70e8c5f/go.mod h1:zhFlBeJssZ1YBCMZ5Lzu1pX4vhftDvU10WUVb1uXKtM=
github.com/jaypipes/ghw v0.17.0 h1:EVLJeNcy5z6GK/Lqby0EhBpynZo+ayl8iJWY0kbEUJA=
github.com/jaypipes/ghw v0.17.0/go.mod h1:In8SsaDqlb1oTyrbmTC14uy+fbBMvp+xdqX51MidlD8=
github.com/jaypipes/pcidb v1.0.1 h1:WB2zh27T3nwg8AE8ei81sNRb9yWBii3JGNJtT7K9Oic=
github.com/jaypipes/pcidb v1.0.1/go.mod h1:6xYUz/yYEyOkIkUt2t2J2folIuZ4Yg6uByCGFXMCeE4=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
Expand Down Expand Up @@ -122,6 +132,8 @@ github.com/mdlayher/packet v1.1.2 h1:3Up1NG6LZrsgDVn6X4L9Ge/iyRyxFEFD9o6Pr3Q1nQY
github.com/mdlayher/packet v1.1.2/go.mod h1:GEu1+n9sG5VtiRE4SydOmX5GTwyyYlteZiFU+x0kew4=
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -242,6 +254,7 @@ golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -285,9 +298,12 @@ gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSP
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
k8s.io/cloud-provider-gcp v0.0.0-20250326051131-7056e3facd39 h1:2m5DoDX46TPMmpcLRzrOWdBqouWChgbp4F/qlf/lIGc=
k8s.io/cloud-provider-gcp v0.0.0-20250326051131-7056e3facd39/go.mod h1:NZrMafedcWXEFDubORCpHuWMp8cUS1TItObinH7vpwg=
k8s.io/component-helpers v0.34.0-beta.0 h1:VtrSd4nRzYbHSr6hryNvIojiDOjf5MbjAWjyjGBjFjY=
Expand Down
10 changes: 10 additions & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ spec:
- name: bpf-programs
mountPath: /sys/fs/bpf
mountPropagation: HostToContainer
- name: pci-ids-hwdata
mountPath: /usr/share/hwdata/
- name: pci-ids-misc
mountPath: /usr/share/misc/
volumes:
- name: device-plugin
hostPath:
Expand All @@ -172,4 +176,10 @@ spec:
- name: bpf-programs
hostPath:
path: /sys/fs/bpf
- name: pci-ids-hwdata
hostPath:
path: /usr/share/hwdata/
- name: pci-ids-misc
hostPath:
path: /usr/share/misc/
---
42 changes: 42 additions & 0 deletions pkg/apis/attributes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2025 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package apis

const (
AttrPrefix = "dra.net"

AttrInterfaceName = AttrPrefix + "/" + "ifName"
AttrMac = AttrPrefix + "/" + "mac"
AttrPCIVendor = AttrPrefix + "/" + "pciVendor"
AttrPCIDevice = AttrPrefix + "/" + "pciDevice"
AttrPCISubsystem = AttrPrefix + "/" + "pciSubsystem"
AttrNUMANode = AttrPrefix + "/" + "numaNode"
AttrMTU = AttrPrefix + "/" + "mtu"
AttrEncapsulation = AttrPrefix + "/" + "encapsulation"
AttrAlias = AttrPrefix + "/" + "alias"
AttrState = AttrPrefix + "/" + "state"
AttrType = AttrPrefix + "/" + "type"
AttrIPv4 = AttrPrefix + "/" + "ipv4"
AttrIPv6 = AttrPrefix + "/" + "ipv6"
AttrTCFilterNames = AttrPrefix + "/" + "tcFilterNames"
AttrTCXProgramNames = AttrPrefix + "/" + "tcxProgramNames"
AttrEBPF = AttrPrefix + "/" + "ebpf"
AttrSRIOV = AttrPrefix + "/" + "sriov"
AttrSRIOVVfs = AttrPrefix + "/" + "sriovVfs"
AttrVirtual = AttrPrefix + "/" + "virtual"
AttrRDMA = AttrPrefix + "/" + "rdma"
)
10 changes: 10 additions & 0 deletions pkg/cloudprovider/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ const (
GPUDirectRDMA GPUDirectSupport = "GPUDirect-RDMA"
)

const (
GCEAttrPrefix = "gce.dra.net"

AttrGCEBlock = GCEAttrPrefix + "/" + "block"
AttrGCESubblock = GCEAttrPrefix + "/" + "subblock"
AttrGCEHost = GCEAttrPrefix + "/" + "host"
AttrGCENetworkName = GCEAttrPrefix + "/" + "networkName"
AttrGCENetworkProjectNumber = GCEAttrPrefix + "/" + "networkProjectNumber"
)

var (
// https://cloud.google.com/compute/docs/accelerator-optimized-machines#network-protocol
// machine types have a one to one mapping to a network protocol in google cloud
Expand Down
15 changes: 6 additions & 9 deletions pkg/driver/dra_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/google/dranet/pkg/apis"
"github.com/google/dranet/pkg/filter"
"github.com/google/dranet/pkg/names"

"github.com/Mellanox/rdmamap"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -165,11 +164,14 @@ func (np *NetworkDriver) prepareResourceClaim(ctx context.Context, claim *resour
},
Network: netconf,
}
ifName := names.GetOriginalName(result.Device)
ifName, err := np.netdb.GetNetInterfaceName(result.Device)
if err != nil {
errorList = append(errorList, fmt.Errorf("failed to get network interface %s", ifName))
}
// Get Network configuration and merge it
link, err := nlHandle.LinkByName(ifName)
if err != nil {
errorList = append(errorList, fmt.Errorf("fail to get network interface %s", ifName))
errorList = append(errorList, fmt.Errorf("failed to get netlink to interface %s", ifName))
continue
}

Expand Down Expand Up @@ -298,15 +300,10 @@ func (np *NetworkDriver) prepareResourceClaim(ctx context.Context, claim *resour
}
}

device := kubeletplugin.Device{
Requests: []string{result.Request},
PoolName: result.Pool,
DeviceName: result.Device,
}
// TODO: support for multiple pods sharing the same device
// we'll create the subinterface here
for _, uid := range podUIDs {
np.podConfigStore.Set(uid, device.DeviceName, podCfg)
np.podConfigStore.Set(uid, result.Device, podCfg)
}
klog.V(4).Infof("Claim Resources for pods %v : %#v", podUIDs, podCfg)
}
Expand Down
32 changes: 20 additions & 12 deletions pkg/driver/nri_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"fmt"
"time"

"github.com/google/dranet/pkg/names"

"github.com/containerd/nri/pkg/api"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -52,7 +50,7 @@ func (np *NetworkDriver) Synchronize(_ context.Context, pods []*api.PodSandbox,
// host network pods are skipped
if ns != "" {
// store the Pod metadata in the db
np.netdb.AddPodNetns(podKey(pod), ns)
np.netdb.AddPodNetNs(podKey(pod), ns)
}
}

Expand Down Expand Up @@ -106,7 +104,7 @@ func (np *NetworkDriver) RunPodSandbox(ctx context.Context, pod *api.PodSandbox)
return fmt.Errorf("RunPodSandbox pod %s/%s using host network can not claim host devices", pod.Namespace, pod.Name)
}
// store the Pod metadata in the db
np.netdb.AddPodNetns(podKey(pod), ns)
np.netdb.AddPodNetNs(podKey(pod), ns)

// Track all the status updates needed for the resource claims of the pod.
statusUpdates := map[types.NamespacedName]*resourceapply.ResourceClaimStatusApplyConfiguration{}
Expand All @@ -126,7 +124,13 @@ func (np *NetworkDriver) RunPodSandbox(ctx context.Context, pod *api.PodSandbox)
WithDriver(np.driverName).
WithPool(np.nodeName)

ifName := names.GetOriginalName(deviceName)
ifName, err := np.netdb.GetNetInterfaceName(deviceName)
if err != nil {
// Tip: We can tweak the code here to simply log
// this without returning and continue exeuction for cases where the
// device has no associated network interface.
return fmt.Errorf("failed to get network interface %s", ifName)
}

klog.V(2).Infof("RunPodSandbox processing Network device: %s", ifName)
// TODO config options to rename the device and pass parameters
Expand Down Expand Up @@ -229,10 +233,11 @@ func (np *NetworkDriver) RunPodSandbox(ctx context.Context, pod *api.PodSandbox)
// to avoid disrupting the pod shutdown. The kernel will do the cleanup once the namespace
// is deleted.
func (np *NetworkDriver) StopPodSandbox(ctx context.Context, pod *api.PodSandbox) error {
defer np.netdb.Sync() // Sync is expected to return immediately.
klog.V(2).Infof("StopPodSandbox Pod %s/%s UID %s", pod.Namespace, pod.Name, pod.Uid)
start := time.Now()
defer func() {
np.netdb.RemovePodNetns(podKey(pod))
np.netdb.RemovePodNetNs(podKey(pod))
klog.V(2).Infof("StopPodSandbox Pod %s/%s UID %s took %v", pod.Namespace, pod.Name, pod.Uid, time.Since(start))
}()

Expand All @@ -247,18 +252,21 @@ func (np *NetworkDriver) StopPodSandbox(ctx context.Context, pod *api.PodSandbox
// some version of containerd does not send the network namespace information on this hook so
// we workaround it using the local copy we have in the db to associate interfaces with Pods via
// the network namespace id.
ns = np.netdb.GetPodNamespace(podKey(pod))
ns = np.netdb.GetPodNetNs(podKey(pod))
if ns == "" {
klog.Infof("StopPodSandbox pod %s/%s using host network ... skipping", pod.Namespace, pod.Name)
return nil
}
}

for deviceName, config := range podConfig {
ifName := names.GetOriginalName(deviceName)

if err := nsDetachNetdev(ns, config.Network.Interface.Name, ifName); err != nil {
klog.Infof("fail to return network device %s : %v", deviceName, err)
ifName, err := np.netdb.GetNetInterfaceName(deviceName)
if err == nil {
if err := nsDetachNetdev(ns, config.Network.Interface.Name, ifName); err != nil {
klog.Infof("fail to return network device %s : %v", deviceName, err)
}
} else {
klog.V(2).Infof("Failed to identify network interface for device %s: %v; expect kernel to do the cleanup", deviceName, err)
}

if !np.rdmaSharedMode && config.RDMADevice.LinkDev != "" {
Expand All @@ -272,7 +280,7 @@ func (np *NetworkDriver) StopPodSandbox(ctx context.Context, pod *api.PodSandbox

func (np *NetworkDriver) RemovePodSandbox(_ context.Context, pod *api.PodSandbox) error {
klog.V(2).Infof("RemovePodSandbox Pod %s/%s UID %s", pod.Namespace, pod.Name, pod.Uid)
np.netdb.RemovePodNetns(podKey(pod))
np.netdb.RemovePodNetNs(podKey(pod))
return nil
}

Expand Down
Loading
Loading