Skip to content

Commit bc8124f

Browse files
giuseppemheon
authored andcommitted
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 57b9709 commit bc8124f

File tree

7 files changed

+66
-0
lines changed

7 files changed

+66
-0
lines changed

Diff for: 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))

Diff for: 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.

Diff for: 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+
}

Diff for: test/compose/cdi_device/docker-compose.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
test:
3+
image: alpine
4+
command: ["top"]
5+
volumes:
6+
- /dev:/dev-host
7+
security_opt:
8+
- label=disable
9+
deploy:
10+
resources:
11+
reservations:
12+
devices:
13+
- driver: cdi
14+
device_ids: ['vendor.com/device=myKmsg']
15+
capabilities: []

Diff for: 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

Diff for: test/compose/cdi_device/teardown.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if ! is_rootless; then
2+
umount -l /etc/cdi
3+
fi

Diff for: test/compose/cdi_device/tests.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- bash -*-
2+
3+
ctr_name="cdi_device-test-1"
4+
5+
podman exec "$ctr_name" sh -c 'stat -c "%t:%T" /dev-host/kmsg'
6+
7+
expected=$output
8+
9+
podman exec "$ctr_name" sh -c 'stat -c "%t:%T" /dev/kmsg1'
10+
11+
is "$output" "$expected" "$testname : device /dev/kmsg1 has the same rdev as /dev/kmsg on the host"

0 commit comments

Comments
 (0)