@@ -1078,6 +1078,12 @@ fn sandbox_template_to_k8s(
10781078 serde_json:: json!( runtime_class) ,
10791079 ) ;
10801080 }
1081+ if let Some ( node_selector) = platform_config_struct ( template, "node_selector" ) {
1082+ spec. insert ( "nodeSelector" . to_string ( ) , node_selector) ;
1083+ }
1084+ if let Some ( tolerations) = platform_config_struct ( template, "tolerations" ) {
1085+ spec. insert ( "tolerations" . to_string ( ) , tolerations) ;
1086+ }
10811087
10821088 // Per-sandbox platform_config.host_users overrides the cluster-wide default.
10831089 let use_user_namespaces = platform_config_bool ( template, "host_users" )
@@ -2322,4 +2328,111 @@ mod tests {
23222328 ) ;
23232329 assert ! ( cr[ "spec" ] . get( "logLevel" ) . is_none( ) ) ;
23242330 }
2331+
2332+ #[ test]
2333+ fn node_selector_from_platform_config ( ) {
2334+ let template = SandboxTemplate {
2335+ platform_config : Some ( Struct {
2336+ fields : [ (
2337+ "node_selector" . to_string ( ) ,
2338+ Value {
2339+ kind : Some ( Kind :: StructValue ( Struct {
2340+ fields : [ (
2341+ "gpu-pool" . to_string ( ) ,
2342+ Value {
2343+ kind : Some ( Kind :: StringValue ( "true" . to_string ( ) ) ) ,
2344+ } ,
2345+ ) ]
2346+ . into_iter ( )
2347+ . collect ( ) ,
2348+ } ) ) ,
2349+ } ,
2350+ ) ]
2351+ . into_iter ( )
2352+ . collect ( ) ,
2353+ } ) ,
2354+ ..SandboxTemplate :: default ( )
2355+ } ;
2356+
2357+ let pod_template = {
2358+ let params = SandboxPodParams :: default ( ) ;
2359+ sandbox_template_to_k8s (
2360+ & template,
2361+ false ,
2362+ & std:: collections:: HashMap :: new ( ) ,
2363+ false ,
2364+ & params,
2365+ )
2366+ } ;
2367+
2368+ assert_eq ! (
2369+ pod_template[ "spec" ] [ "nodeSelector" ] [ "gpu-pool" ] ,
2370+ serde_json:: json!( "true" )
2371+ ) ;
2372+ }
2373+
2374+ #[ test]
2375+ fn tolerations_from_platform_config ( ) {
2376+ let toleration = Struct {
2377+ fields : [
2378+ (
2379+ "key" . to_string ( ) ,
2380+ Value {
2381+ kind : Some ( Kind :: StringValue ( "nvidia.com/gpu" . to_string ( ) ) ) ,
2382+ } ,
2383+ ) ,
2384+ (
2385+ "operator" . to_string ( ) ,
2386+ Value {
2387+ kind : Some ( Kind :: StringValue ( "Exists" . to_string ( ) ) ) ,
2388+ } ,
2389+ ) ,
2390+ (
2391+ "effect" . to_string ( ) ,
2392+ Value {
2393+ kind : Some ( Kind :: StringValue ( "NoSchedule" . to_string ( ) ) ) ,
2394+ } ,
2395+ ) ,
2396+ ]
2397+ . into_iter ( )
2398+ . collect ( ) ,
2399+ } ;
2400+
2401+ let template = SandboxTemplate {
2402+ platform_config : Some ( Struct {
2403+ fields : [ (
2404+ "tolerations" . to_string ( ) ,
2405+ Value {
2406+ kind : Some ( Kind :: ListValue ( prost_types:: ListValue {
2407+ values : vec ! [ Value {
2408+ kind: Some ( Kind :: StructValue ( toleration) ) ,
2409+ } ] ,
2410+ } ) ) ,
2411+ } ,
2412+ ) ]
2413+ . into_iter ( )
2414+ . collect ( ) ,
2415+ } ) ,
2416+ ..SandboxTemplate :: default ( )
2417+ } ;
2418+
2419+ let pod_template = {
2420+ let params = SandboxPodParams :: default ( ) ;
2421+ sandbox_template_to_k8s (
2422+ & template,
2423+ false ,
2424+ & std:: collections:: HashMap :: new ( ) ,
2425+ false ,
2426+ & params,
2427+ )
2428+ } ;
2429+
2430+ let tolerations = pod_template[ "spec" ] [ "tolerations" ]
2431+ . as_array ( )
2432+ . expect ( "tolerations should be an array" ) ;
2433+ assert_eq ! ( tolerations. len( ) , 1 ) ;
2434+ assert_eq ! ( tolerations[ 0 ] [ "key" ] , "nvidia.com/gpu" ) ;
2435+ assert_eq ! ( tolerations[ 0 ] [ "operator" ] , "Exists" ) ;
2436+ assert_eq ! ( tolerations[ 0 ] [ "effect" ] , "NoSchedule" ) ;
2437+ }
23252438}
0 commit comments