@@ -111,7 +111,6 @@ fn runtime_config() -> DockerDriverRuntimeConfig {
111111 } ) ,
112112 daemon_version : "28.0.0" . to_string ( ) ,
113113 supports_gpu : false ,
114- cdi_gpu_inventory : CdiGpuInventory :: default ( ) ,
115114 allow_all_default_gpu : false ,
116115 sandbox_pids_limit : DEFAULT_SANDBOX_PIDS_LIMIT ,
117116 enable_bind_mounts : false ,
@@ -179,6 +178,7 @@ impl SupervisorReadiness for DisconnectedSupervisorReadiness {
179178}
180179
181180fn test_driver_with_config ( config : DockerDriverRuntimeConfig ) -> DockerComputeDriver {
181+ let allow_all_default_gpu = config. allow_all_default_gpu ;
182182 DockerComputeDriver {
183183 docker : Arc :: new (
184184 Docker :: connect_with_http ( "http://127.0.0.1:2375" , 1 , bollard:: API_DEFAULT_VERSION )
@@ -188,7 +188,10 @@ fn test_driver_with_config(config: DockerDriverRuntimeConfig) -> DockerComputeDr
188188 events : broadcast:: channel ( WATCH_BUFFER ) . 0 ,
189189 pending : Arc :: new ( tokio:: sync:: Mutex :: new ( HashMap :: new ( ) ) ) ,
190190 supervisor_readiness : Arc :: new ( DisconnectedSupervisorReadiness ) ,
191- gpu_selector : Arc :: new ( CdiGpuRoundRobin :: new ( ) ) ,
191+ gpu_selector : Arc :: new ( CdiGpuDefaultSelector :: new (
192+ CdiGpuInventory :: default ( ) ,
193+ allow_all_default_gpu,
194+ ) ) ,
192195 }
193196}
194197
@@ -1105,19 +1108,14 @@ fn validate_sandbox_rejects_unknown_driver_config_fields() {
11051108}
11061109
11071110#[ test]
1108- fn validate_sandbox_rejects_gpu_count_request ( ) {
1111+ fn validate_sandbox_accepts_gpu_count_request_shape ( ) {
11091112 let mut config = runtime_config ( ) ;
11101113 config. supports_gpu = true ;
11111114 let mut sandbox = test_sandbox ( ) ;
11121115 sandbox. spec . as_mut ( ) . unwrap ( ) . resource_requirements = Some ( gpu_resources ( Some ( 2 ) ) ) ;
11131116
1114- let err = DockerComputeDriver :: validate_sandbox ( & sandbox, & config) . unwrap_err ( ) ;
1115-
1116- assert_eq ! ( err. code( ) , tonic:: Code :: InvalidArgument ) ;
1117- assert ! (
1118- err. message( )
1119- . contains( "GPU count requests are not supported" )
1120- ) ;
1117+ DockerComputeDriver :: validate_sandbox ( & sandbox, & config)
1118+ . expect ( "default GPU count shape should be accepted before inventory selection" ) ;
11211119}
11221120
11231121#[ test]
@@ -1166,7 +1164,7 @@ fn validate_sandbox_rejects_multiple_cdi_devices_without_gpu_count() {
11661164 assert_eq ! ( err. code( ) , tonic:: Code :: InvalidArgument ) ;
11671165 assert ! (
11681166 err. message( )
1169- . contains( "requires an explicit gpu count matching its length (2)" )
1167+ . contains( "gpu count (1) must match driver_config.cdi_devices length (2)" )
11701168 ) ;
11711169}
11721170
@@ -1253,9 +1251,15 @@ fn build_container_create_body_maps_default_gpu_to_selected_cdi_device() {
12531251 let mut sandbox = test_sandbox ( ) ;
12541252 sandbox. spec . as_mut ( ) . unwrap ( ) . resource_requirements = Some ( gpu_resources ( None ) ) ;
12551253
1256- let create_body =
1257- build_container_create_body_with_default ( & sandbox, & config, Some ( "nvidia.com/gpu=1" ) )
1258- . unwrap ( ) ;
1254+ let driver_config = DockerSandboxDriverConfig :: default ( ) ;
1255+ let gpu_devices = vec ! [ "nvidia.com/gpu=1" . to_string( ) ] ;
1256+ let create_body = build_container_create_body_with_gpu_devices (
1257+ & sandbox,
1258+ & config,
1259+ & driver_config,
1260+ Some ( & gpu_devices) ,
1261+ )
1262+ . unwrap ( ) ;
12591263 let request = create_body
12601264 . host_config
12611265 . as_ref ( )
@@ -1271,19 +1275,20 @@ fn build_container_create_body_maps_default_gpu_to_selected_cdi_device() {
12711275}
12721276
12731277#[ test]
1274- fn build_container_create_body_rejects_missing_default_cdi_device ( ) {
1278+ fn build_container_create_body_omits_devices_without_resolved_default_cdi_devices ( ) {
12751279 let mut config = runtime_config ( ) ;
12761280 config. supports_gpu = true ;
12771281 let mut sandbox = test_sandbox ( ) ;
12781282 sandbox. spec . as_mut ( ) . unwrap ( ) . resource_requirements = Some ( gpu_resources ( None ) ) ;
12791283
1280- let err = build_container_create_body ( & sandbox, & config) . unwrap_err ( ) ;
1284+ let create_body = build_container_create_body ( & sandbox, & config) . unwrap ( ) ;
12811285
1282- assert_eq ! ( err. code( ) , tonic:: Code :: FailedPrecondition ) ;
12831286 assert ! (
1284- err. message( ) . contains( "selected default CDI GPU device" ) ,
1285- "unexpected error: {}" ,
1286- err. message( )
1287+ create_body
1288+ . host_config
1289+ . as_ref( )
1290+ . and_then( |host_config| host_config. device_requests. as_ref( ) )
1291+ . is_none( )
12871292 ) ;
12881293}
12891294
@@ -1362,8 +1367,11 @@ fn build_container_create_body_rejects_empty_cdi_devices() {
13621367fn driver_default_gpu_selection_consumes_distinct_devices_for_creates ( ) {
13631368 let mut config = runtime_config ( ) ;
13641369 config. supports_gpu = true ;
1365- config. cdi_gpu_inventory = CdiGpuInventory :: new ( [ "nvidia.com/gpu=0" , "nvidia.com/gpu=1" ] ) ;
13661370 let driver = test_driver_with_config ( config) ;
1371+ driver. gpu_selector . refresh (
1372+ CdiGpuInventory :: new ( [ "nvidia.com/gpu=0" , "nvidia.com/gpu=1" ] ) ,
1373+ false ,
1374+ ) ;
13671375 let mut first_sandbox = test_sandbox ( ) ;
13681376 first_sandbox. id = "sbx-first" . to_string ( ) ;
13691377 first_sandbox. name = "first" . to_string ( ) ;
@@ -1375,27 +1383,30 @@ fn driver_default_gpu_selection_consumes_distinct_devices_for_creates() {
13751383
13761384 DockerComputeDriver :: validate_sandbox ( & first_sandbox, & driver. config ) . unwrap ( ) ;
13771385 assert_eq ! (
1378- driver. peek_default_gpu_device ( & first_sandbox ) . unwrap( ) ,
1379- Some ( "nvidia.com/gpu=0" . to_string( ) )
1386+ driver. gpu_selector . peek_device_ids ( 1 ) . unwrap( ) ,
1387+ vec! [ "nvidia.com/gpu=0" . to_string( ) ]
13801388 ) ;
1381- let first_device = driver. next_default_gpu_device ( & first_sandbox) . unwrap ( ) ;
1382- let first_create_body = build_container_create_body_with_default (
1389+ let first_devices = driver. gpu_selector . next_device_ids ( 1 ) . unwrap ( ) ;
1390+ let driver_config = DockerSandboxDriverConfig :: default ( ) ;
1391+ let first_create_body = build_container_create_body_with_gpu_devices (
13831392 & first_sandbox,
13841393 & driver. config ,
1385- first_device. as_deref ( ) ,
1394+ & driver_config,
1395+ Some ( & first_devices) ,
13861396 )
13871397 . unwrap ( ) ;
13881398
13891399 DockerComputeDriver :: validate_sandbox ( & second_sandbox, & driver. config ) . unwrap ( ) ;
13901400 assert_eq ! (
1391- driver. peek_default_gpu_device ( & second_sandbox ) . unwrap( ) ,
1392- Some ( "nvidia.com/gpu=1" . to_string( ) )
1401+ driver. gpu_selector . peek_device_ids ( 1 ) . unwrap( ) ,
1402+ vec! [ "nvidia.com/gpu=1" . to_string( ) ]
13931403 ) ;
1394- let second_device = driver. next_default_gpu_device ( & second_sandbox ) . unwrap ( ) ;
1395- let second_create_body = build_container_create_body_with_default (
1404+ let second_devices = driver. gpu_selector . next_device_ids ( 1 ) . unwrap ( ) ;
1405+ let second_create_body = build_container_create_body_with_gpu_devices (
13961406 & second_sandbox,
13971407 & driver. config ,
1398- second_device. as_deref ( ) ,
1408+ & driver_config,
1409+ Some ( & second_devices) ,
13991410 )
14001411 . unwrap ( ) ;
14011412
0 commit comments