@@ -3506,9 +3506,14 @@ fn sandbox_template_to_k8s_with_validated_config(
35063506 }
35073507 apply_pod_driver_config ( & mut spec, & driver_config. pod ) ;
35083508
3509- // Per-sandbox platform_config.host_users overrides the cluster-wide default.
3510- let use_user_namespaces = platform_config_bool ( template, "host_users" )
3511- . map_or ( params. enable_user_namespaces , |host_users| !host_users) ;
3509+ // Per-sandbox portable intent overrides the cluster-wide default. This
3510+ // driver owns the Kubernetes-specific `hostUsers` translation. Accept the
3511+ // former platform_config encoding during rolling upgrades from gateways
3512+ // that predate the typed field.
3513+ let use_user_namespaces = template
3514+ . user_namespaces
3515+ . or_else ( || platform_config_bool ( template, "host_users" ) . map ( |host_users| !host_users) )
3516+ . unwrap_or ( params. enable_user_namespaces ) ;
35123517
35133518 if use_user_namespaces {
35143519 spec. insert ( "hostUsers" . to_string ( ) , serde_json:: json!( false ) ) ;
@@ -4124,7 +4129,7 @@ fn platform_config_bool(template: &SandboxTemplate, key: &str) -> Option<bool> {
41244129 let config = template. platform_config . as_ref ( ) ?;
41254130 let value = config. fields . get ( key) ?;
41264131 match value. kind . as_ref ( ) {
4127- Some ( prost_types:: value:: Kind :: BoolValue ( b ) ) => Some ( * b ) ,
4132+ Some ( prost_types:: value:: Kind :: BoolValue ( value ) ) => Some ( * value ) ,
41284133 _ => None ,
41294134 }
41304135}
@@ -6846,15 +6851,7 @@ mod tests {
68466851 #[ test]
68476852 fn user_namespaces_per_sandbox_override_enables ( ) {
68486853 let template = SandboxTemplate {
6849- platform_config : Some ( Struct {
6850- fields : std:: iter:: once ( (
6851- "host_users" . to_string ( ) ,
6852- Value {
6853- kind : Some ( Kind :: BoolValue ( false ) ) ,
6854- } ,
6855- ) )
6856- . collect ( ) ,
6857- } ) ,
6854+ user_namespaces : Some ( true ) ,
68586855 ..SandboxTemplate :: default ( )
68596856 } ;
68606857
@@ -6870,7 +6867,7 @@ mod tests {
68706867 assert_eq ! (
68716868 pod_template[ "spec" ] [ "hostUsers" ] ,
68726869 serde_json:: json!( false ) ,
6873- "per-sandbox host_users: false must enable user namespaces "
6870+ "per-sandbox user namespace intent must set hostUsers: false "
68746871 ) ;
68756872 let caps = pod_template[ "spec" ] [ "containers" ] [ 0 ] [ "securityContext" ] [ "capabilities" ] [ "add" ]
68766873 . as_array ( )
@@ -6881,15 +6878,7 @@ mod tests {
68816878 #[ test]
68826879 fn user_namespaces_per_sandbox_override_disables ( ) {
68836880 let template = SandboxTemplate {
6884- platform_config : Some ( Struct {
6885- fields : std:: iter:: once ( (
6886- "host_users" . to_string ( ) ,
6887- Value {
6888- kind : Some ( Kind :: BoolValue ( true ) ) ,
6889- } ,
6890- ) )
6891- . collect ( ) ,
6892- } ) ,
6881+ user_namespaces : Some ( false ) ,
68936882 ..SandboxTemplate :: default ( )
68946883 } ;
68956884
@@ -6907,7 +6896,7 @@ mod tests {
69076896
69086897 assert ! (
69096898 pod_template[ "spec" ] [ "hostUsers" ] . is_null( ) ,
6910- "per-sandbox host_users: true must disable user namespaces even when cluster default is on "
6899+ "per-sandbox user namespace intent must override the cluster default"
69116900 ) ;
69126901 let caps = pod_template[ "spec" ] [ "containers" ] [ 0 ] [ "securityContext" ] [ "capabilities" ] [ "add" ]
69136902 . as_array ( )
@@ -6919,6 +6908,37 @@ mod tests {
69196908 ) ;
69206909 }
69216910
6911+ #[ test]
6912+ fn user_namespaces_accepts_legacy_host_users_encoding ( ) {
6913+ let template = SandboxTemplate {
6914+ platform_config : Some ( Struct {
6915+ fields : std:: iter:: once ( (
6916+ "host_users" . to_string ( ) ,
6917+ Value {
6918+ kind : Some ( Kind :: BoolValue ( false ) ) ,
6919+ } ,
6920+ ) )
6921+ . collect ( ) ,
6922+ } ) ,
6923+ ..SandboxTemplate :: default ( )
6924+ } ;
6925+
6926+ let params = SandboxPodParams :: default ( ) ;
6927+ let pod_template = sandbox_template_to_k8s (
6928+ & template,
6929+ false ,
6930+ & std:: collections:: HashMap :: new ( ) ,
6931+ true ,
6932+ & params,
6933+ ) ;
6934+
6935+ assert_eq ! (
6936+ pod_template[ "spec" ] [ "hostUsers" ] ,
6937+ serde_json:: json!( false ) ,
6938+ "legacy host_users: false must still enable user namespaces"
6939+ ) ;
6940+ }
6941+
69226942 #[ test]
69236943 fn automount_service_account_token_is_disabled ( ) {
69246944 let pod_template = {
@@ -7084,43 +7104,6 @@ mod tests {
70847104 ) ;
70857105 }
70867106
7087- #[ test]
7088- fn platform_config_bool_extracts_value ( ) {
7089- let template = SandboxTemplate {
7090- platform_config : Some ( Struct {
7091- fields : std:: iter:: once ( (
7092- "my_bool" . to_string ( ) ,
7093- Value {
7094- kind : Some ( Kind :: BoolValue ( true ) ) ,
7095- } ,
7096- ) )
7097- . collect ( ) ,
7098- } ) ,
7099- ..SandboxTemplate :: default ( )
7100- } ;
7101-
7102- assert_eq ! ( platform_config_bool( & template, "my_bool" ) , Some ( true ) ) ;
7103- assert_eq ! ( platform_config_bool( & template, "missing" ) , None ) ;
7104- }
7105-
7106- #[ test]
7107- fn platform_config_bool_returns_none_for_non_bool ( ) {
7108- let template = SandboxTemplate {
7109- platform_config : Some ( Struct {
7110- fields : std:: iter:: once ( (
7111- "a_string" . to_string ( ) ,
7112- Value {
7113- kind : Some ( Kind :: StringValue ( "hello" . to_string ( ) ) ) ,
7114- } ,
7115- ) )
7116- . collect ( ) ,
7117- } ) ,
7118- ..SandboxTemplate :: default ( )
7119- } ;
7120-
7121- assert_eq ! ( platform_config_bool( & template, "a_string" ) , None ) ;
7122- }
7123-
71247107 #[ test]
71257108 fn log_level_propagates_as_env_var_to_sandbox_pod ( ) {
71267109 let spec = SandboxSpec {
0 commit comments