From dedf5747cca3b8cc64ee15ee8799c7c429751f01 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 14 Apr 2023 10:23:05 +0200 Subject: [PATCH] Remove need to set Capabilities for cdi driver Signed-off-by: Evan Lezar --- daemon/cdi.go | 3 --- daemon/devices.go | 11 +++++++++++ integration/container/cdi_test.go | 5 ++--- integration/internal/container/ops.go | 5 ++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/daemon/cdi.go b/daemon/cdi.go index 89274e28c3..2b80cfe1e1 100644 --- a/daemon/cdi.go +++ b/daemon/cdi.go @@ -5,7 +5,6 @@ import ( "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/docker/docker/errdefs" - "github.com/docker/docker/pkg/capabilities" "github.com/hashicorp/go-multierror" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" @@ -29,7 +28,6 @@ func RegisterCDIDriver(opts ...cdi.Option) { return fmt.Errorf("CDI device injection failed due to registry initialization failure: %w", err) } driver := &deviceDriver{ - capset: capabilities.Set{"cdi": struct{}{}}, updateSpec: errorOnUpdateSpec, } registerDeviceDriver("cdi", driver) @@ -42,7 +40,6 @@ func RegisterCDIDriver(opts ...cdi.Option) { } driver := &deviceDriver{ - capset: capabilities.Set{"cdi": struct{}{}}, updateSpec: c.injectCDIDevices, } diff --git a/daemon/devices.go b/daemon/devices.go index a7b76eacaf..0053fc1051 100644 --- a/daemon/devices.go +++ b/daemon/devices.go @@ -30,6 +30,17 @@ func (daemon *Daemon) handleDevice(req container.DeviceRequest, spec *specs.Spec } } } else if dd := deviceDrivers[req.Driver]; dd != nil { + // We add a special case for the CDI driver here as the cdi driver does + // not distinguish between capabilities. + // Furthermore, the "OR" and "AND" matching logic for the capability + // sets requires that a dummy capability be specified when constructing a + // DeviceRequest. + // This workaround can be removed once these device driver are + // refactored to be plugins, with each driver implementing its own + // matching logic, for example. + if req.Driver == "cdi" { + return dd.updateSpec(spec, &deviceInstance{req: req}) + } if selected := dd.capset.Match(req.Capabilities); selected != nil { return dd.updateSpec(spec, &deviceInstance{req: req, selectedCaps: selected}) } diff --git a/integration/container/cdi_test.go b/integration/container/cdi_test.go index aefc30fc55..c25d1cf206 100644 --- a/integration/container/cdi_test.go +++ b/integration/container/cdi_test.go @@ -43,9 +43,8 @@ func TestCreateWithCDIDevices(t *testing.T) { expectedRequests := []containertypes.DeviceRequest{ { - Driver: "cdi", - DeviceIDs: []string{"vendor1.com/device=foo"}, - Capabilities: [][]string{{"cdi"}}, + Driver: "cdi", + DeviceIDs: []string{"vendor1.com/device=foo"}, }, } assert.Check(t, is.DeepEqual(inspect.HostConfig.DeviceRequests, expectedRequests)) diff --git a/integration/internal/container/ops.go b/integration/internal/container/ops.go index dd14a2724e..a38bc81198 100644 --- a/integration/internal/container/ops.go +++ b/integration/internal/container/ops.go @@ -242,9 +242,8 @@ func WithRuntime(name string) func(*TestContainerConfig) { func WithCDIDevices(cdiDeviceNames ...string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { request := containertypes.DeviceRequest{ - Driver: "cdi", - Capabilities: [][]string{{"cdi"}}, - DeviceIDs: cdiDeviceNames, + Driver: "cdi", + DeviceIDs: cdiDeviceNames, } c.HostConfig.DeviceRequests = append(c.HostConfig.DeviceRequests, request) }