@@ -2,6 +2,7 @@ package daemon
22
33import (
44 "context"
5+ "maps"
56 "os"
67 "path/filepath"
78 "slices"
@@ -76,6 +77,45 @@ func (i *fakeImageService) StorageDriver() string {
7677 return "overlay"
7778}
7879
80+ func TestCreateSpecPreservesCDIAdditionalGIDs (t * testing.T ) {
81+ cdiDir := t .TempDir ()
82+ err := os .WriteFile (filepath .Join (cdiDir , "test-device.yaml" ), []byte (`
83+ cdiVersion: "0.7.0"
84+ kind: "example.com/device"
85+ devices:
86+ - name: foo
87+ containerEdits:
88+ additionalGids:
89+ - 1234
90+ ` ), 0o644 )
91+ assert .NilError (t , err )
92+
93+ origDeviceDrivers := maps .Clone (deviceDrivers )
94+ t .Cleanup (func () {
95+ deviceDrivers = origDeviceDrivers
96+ })
97+ RegisterCDIDriver (cdiDir )
98+
99+ c := & container.Container {
100+ Config : & containertypes.Config {},
101+ HostConfig : & containertypes.HostConfig {
102+ Resources : containertypes.Resources {
103+ DeviceRequests : []containertypes.DeviceRequest {
104+ {
105+ Driver : "cdi" ,
106+ DeviceIDs : []string {"example.com/device=foo" },
107+ },
108+ },
109+ },
110+ },
111+ }
112+ d := setupFakeDaemon (t , c )
113+
114+ s , err := d .createSpec (t .Context (), & configStore {}, c , nil )
115+ assert .NilError (t , err )
116+ assert .Assert (t , slices .Contains (s .Process .User .AdditionalGids , uint32 (1234 )), "CDI additional GID not present in OCI spec" )
117+ }
118+
79119// TestTmpfsDevShmNoDupMount checks that a user-specified /dev/shm tmpfs
80120// mount (as in "docker run --tmpfs /dev/shm:rw,size=NNN") does not result
81121// in "Duplicate mount point" error from the engine.
0 commit comments