Skip to content

Commit 23654c6

Browse files
committed
pkg/api: honor cdi devices from the hostconfig
pass down the devices specifies in the resources block so that CDI devices in the compose file are honored. Tested manually with the following compose file: services: testgpupodman_count: image: ubuntu:latest command: ["nvidia-smi"] profiles: [gpu] deploy: resources: reservations: devices: - driver: nvidia count: 1 capabilities: [gpu] testgpupodman_deviceid: image: docker.io/ubuntu:latest command: ["nvidia-smi"] deploy: resources: reservations: devices: - driver: cdi device_ids: ['nvidia.com/gpu=all'] capabilities: [gpu] Closes: containers#19338 Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 48f8742 commit 23654c6

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed

pkg/api/handlers/compat/containers_create.go

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
163163
for _, dev := range cc.HostConfig.Devices {
164164
devices = append(devices, fmt.Sprintf("%s:%s:%s", dev.PathOnHost, dev.PathInContainer, dev.CgroupPermissions))
165165
}
166+
for _, r := range cc.HostConfig.Resources.DeviceRequests {
167+
if r.Driver == "cdi" {
168+
devices = append(devices, r.DeviceIDs...)
169+
}
170+
}
166171

167172
// iterate blkreaddevicebps
168173
readBps := make([]string, 0, len(cc.HostConfig.BlkioDeviceReadBps))

test/compose/cdi_device/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cdi devices
2+
===========
3+
4+
This test copies a CDI device file on a tmpfs mounted on /etc/cdi, then checks that the CDI device in the compose file is present in a container. The test is skipped when running as rootless.
5+
6+
Validation
7+
------------
8+
9+
* The CDI device is present in the container.

test/compose/cdi_device/device.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"cdiVersion": "0.3.0",
3+
"kind": "vendor.com/device",
4+
"devices": [
5+
{
6+
"name": "myKmsg",
7+
"containerEdits": {
8+
"mounts": [
9+
{"hostPath": "/dev/kmsg", "containerPath": "/dev/kmsg1", "options": ["rw", "rprivate", "rbind"]}
10+
]
11+
}
12+
}
13+
]
14+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
test:
3+
image: alpine
4+
command: ["top"]
5+
deploy:
6+
resources:
7+
reservations:
8+
devices:
9+
- driver: cdi
10+
device_ids: ['vendor.com/device=myKmsg']
11+
capabilities: []

test/compose/cdi_device/setup.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if is_rootless; then
2+
reason=" - can't write to /etc/cdi"
3+
_show_ok skip "$testname # skip$reason"
4+
exit 0
5+
fi
6+
7+
mkdir -p /etc/cdi
8+
mount -t tmpfs tmpfs /etc/cdi
9+
cp device.json /etc/cdi

test/compose/cdi_device/teardown.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if ! is_rootless; then
2+
umount /etc/cdi
3+
rmdir /etc/cdi || true # do not return an error if the directory is non-empty
4+
fi

test/compose/cdi_device/tests.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- bash -*-
2+
3+
ctr_name="cdi_device-test-1"
4+
5+
podman exec "$ctr_name" sh -c 'test /dev/ksmg1'

0 commit comments

Comments
 (0)