Skip to content

Commit

Permalink
add support for CDI device request using devices
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Oct 8, 2024
1 parent f794c79 commit 3a95a08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
)
15 changes: 15 additions & 0 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -645,14 +646,28 @@ 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,
CgroupPermissions: device.Permissions,
})
}

if len(cdiDeviceNames) > 0 {
resources.DeviceRequests = append(resources.DeviceRequests, container.DeviceRequest{
Driver: "cdi",
DeviceIDs: cdiDeviceNames,
})
}

ulimits := toUlimits(s.Ulimits)
resources.Ulimits = ulimits
return resources
Expand Down

0 comments on commit 3a95a08

Please sign in to comment.