Browse Source

Remove need to set Capabilities for cdi driver

Signed-off-by: Evan Lezar <elezar@nvidia.com>
Evan Lezar 2 years ago
parent
commit
dedf5747cc
4 changed files with 15 additions and 9 deletions
  1. 0 3
      daemon/cdi.go
  2. 11 0
      daemon/devices.go
  3. 2 3
      integration/container/cdi_test.go
  4. 2 3
      integration/internal/container/ops.go

+ 0 - 3
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,
 	}
 

+ 11 - 0
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})
 		}

+ 2 - 3
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))

+ 2 - 3
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)
 	}