diff --git a/go.mod b/go.mod index e1d4d4a8e57..3b91b69d2de 100644 --- a/go.mod +++ b/go.mod @@ -57,6 +57,7 @@ require ( google.golang.org/grpc v1.62.0 gopkg.in/yaml.v3 v3.0.1 gotest.tools/v3 v3.5.1 + tags.cncf.io/container-device-interface v0.8.0 ) require ( @@ -190,5 +191,4 @@ require ( sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.3.0 // indirect - tags.cncf.io/container-device-interface v0.8.0 // indirect ) diff --git a/pkg/compose/create.go b/pkg/compose/create.go index 46faa87c817..ab0842e6e4d 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -48,6 +48,7 @@ import ( "github.com/docker/docker/errdefs" "github.com/docker/go-connections/nat" "github.com/sirupsen/logrus" + cdi "tags.cncf.io/container-device-interface/pkg/parser" ) type createOptions struct { @@ -645,7 +646,14 @@ func getDeployResources(s types.ServiceConfig) container.Resources { setReservations(s.Deploy.Resources.Reservations, &resources) } + var cdiDeviceNames []string for _, device := range s.Devices { + + if device.Source == device.Target && cdi.IsQualifiedName(device.Source) { + cdiDeviceNames = append(cdiDeviceNames, device.Source) + continue + } + resources.Devices = append(resources.Devices, container.DeviceMapping{ PathOnHost: device.Source, PathInContainer: device.Target, @@ -653,6 +661,13 @@ func getDeployResources(s types.ServiceConfig) container.Resources { }) } + if len(cdiDeviceNames) > 0 { + resources.DeviceRequests = append(resources.DeviceRequests, container.DeviceRequest{ + Driver: "cdi", + DeviceIDs: cdiDeviceNames, + }) + } + ulimits := toUlimits(s.Ulimits) resources.Ulimits = ulimits return resources