Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for CDI device request using devices #12184

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add support for CDI device request using devices
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Oct 4, 2024
commit 8c6d94e6d253ed5dd1bef94b34a41ef964572a53
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
Loading