Remove need to set Capabilities for cdi driver
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
7ec9561a77
commit
dedf5747cc
4 changed files with 15 additions and 9 deletions
|
@ -5,7 +5,6 @@ import (
|
||||||
|
|
||||||
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||||
"github.com/docker/docker/errdefs"
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/docker/docker/pkg/capabilities"
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"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)
|
return fmt.Errorf("CDI device injection failed due to registry initialization failure: %w", err)
|
||||||
}
|
}
|
||||||
driver := &deviceDriver{
|
driver := &deviceDriver{
|
||||||
capset: capabilities.Set{"cdi": struct{}{}},
|
|
||||||
updateSpec: errorOnUpdateSpec,
|
updateSpec: errorOnUpdateSpec,
|
||||||
}
|
}
|
||||||
registerDeviceDriver("cdi", driver)
|
registerDeviceDriver("cdi", driver)
|
||||||
|
@ -42,7 +40,6 @@ func RegisterCDIDriver(opts ...cdi.Option) {
|
||||||
}
|
}
|
||||||
|
|
||||||
driver := &deviceDriver{
|
driver := &deviceDriver{
|
||||||
capset: capabilities.Set{"cdi": struct{}{}},
|
|
||||||
updateSpec: c.injectCDIDevices,
|
updateSpec: c.injectCDIDevices,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,17 @@ func (daemon *Daemon) handleDevice(req container.DeviceRequest, spec *specs.Spec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if dd := deviceDrivers[req.Driver]; dd != nil {
|
} 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 {
|
if selected := dd.capset.Match(req.Capabilities); selected != nil {
|
||||||
return dd.updateSpec(spec, &deviceInstance{req: req, selectedCaps: selected})
|
return dd.updateSpec(spec, &deviceInstance{req: req, selectedCaps: selected})
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,8 @@ func TestCreateWithCDIDevices(t *testing.T) {
|
||||||
|
|
||||||
expectedRequests := []containertypes.DeviceRequest{
|
expectedRequests := []containertypes.DeviceRequest{
|
||||||
{
|
{
|
||||||
Driver: "cdi",
|
Driver: "cdi",
|
||||||
DeviceIDs: []string{"vendor1.com/device=foo"},
|
DeviceIDs: []string{"vendor1.com/device=foo"},
|
||||||
Capabilities: [][]string{{"cdi"}},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.Check(t, is.DeepEqual(inspect.HostConfig.DeviceRequests, expectedRequests))
|
assert.Check(t, is.DeepEqual(inspect.HostConfig.DeviceRequests, expectedRequests))
|
||||||
|
|
|
@ -242,9 +242,8 @@ func WithRuntime(name string) func(*TestContainerConfig) {
|
||||||
func WithCDIDevices(cdiDeviceNames ...string) func(*TestContainerConfig) {
|
func WithCDIDevices(cdiDeviceNames ...string) func(*TestContainerConfig) {
|
||||||
return func(c *TestContainerConfig) {
|
return func(c *TestContainerConfig) {
|
||||||
request := containertypes.DeviceRequest{
|
request := containertypes.DeviceRequest{
|
||||||
Driver: "cdi",
|
Driver: "cdi",
|
||||||
Capabilities: [][]string{{"cdi"}},
|
DeviceIDs: cdiDeviceNames,
|
||||||
DeviceIDs: cdiDeviceNames,
|
|
||||||
}
|
}
|
||||||
c.HostConfig.DeviceRequests = append(c.HostConfig.DeviceRequests, request)
|
c.HostConfig.DeviceRequests = append(c.HostConfig.DeviceRequests, request)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue