Remove need to set Capabilities for cdi driver

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-04-14 10:23:05 +02:00
parent 7ec9561a77
commit dedf5747cc
4 changed files with 15 additions and 9 deletions

View file

@ -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,
}

View file

@ -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})
}

View file

@ -45,7 +45,6 @@ func TestCreateWithCDIDevices(t *testing.T) {
{
Driver: "cdi",
DeviceIDs: []string{"vendor1.com/device=foo"},
Capabilities: [][]string{{"cdi"}},
},
}
assert.Check(t, is.DeepEqual(inspect.HostConfig.DeviceRequests, expectedRequests))

View file

@ -243,7 +243,6 @@ func WithCDIDevices(cdiDeviceNames ...string) func(*TestContainerConfig) {
return func(c *TestContainerConfig) {
request := containertypes.DeviceRequest{
Driver: "cdi",
Capabilities: [][]string{{"cdi"}},
DeviceIDs: cdiDeviceNames,
}
c.HostConfig.DeviceRequests = append(c.HostConfig.DeviceRequests, request)