daemon/devices: Turn RegisterGPUDeviceDrivers into func

Change GPU device driver registration from init-time function assignment
to direct function exports.

This removes the init() function and global function variable pattern in
favor of a more explicit approach.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2026-03-04 18:22:18 +01:00
parent 561a5a9b36
commit 13a8626eeb
3 changed files with 10 additions and 9 deletions

View File

@@ -10,13 +10,10 @@ import (
"github.com/moby/moby/v2/daemon/config"
"github.com/moby/moby/v2/daemon/internal/capabilities"
"github.com/opencontainers/runtime-spec/specs-go"
"tags.cncf.io/container-device-interface/pkg/cdi"
)
var deviceDrivers = map[string]*deviceDriver{}
var RegisterGPUDeviceDrivers = func(_ *cdi.Cache) {}
type deviceListing struct {
Devices []system.DeviceInfo
Warnings []string

View File

@@ -2,14 +2,10 @@ package daemon
import "tags.cncf.io/container-device-interface/pkg/cdi"
func init() {
RegisterGPUDeviceDrivers = registerGPUDeviceDrivers
}
// registerGPUDeviceDrivers registers GPU device drivers.
// RegisterGPUDeviceDrivers registers GPU device drivers.
// If the cdiCache is provided, it is used to detect presence of CDI specs for AMD GPUs.
// For NVIDIA GPUs, presence of CDI specs is detected by checking for the nvidia-cdi-hook binary.
func registerGPUDeviceDrivers(cdiCache *cdi.Cache) {
func RegisterGPUDeviceDrivers(cdiCache *cdi.Cache) {
// Register NVIDIA device drivers.
if nvidiaDrivers := getNVIDIADeviceDrivers(); len(nvidiaDrivers) > 0 {
for name, driver := range nvidiaDrivers {

View File

@@ -0,0 +1,8 @@
//go:build !linux
package daemon
import "tags.cncf.io/container-device-interface/pkg/cdi"
// RegisterGPUDeviceDrivers is a no-op on non-Linux platforms.
func RegisterGPUDeviceDrivers(_ *cdi.Cache) {}