diff --git a/kube-client/src/config/file_config.rs b/kube-client/src/config/file_config.rs index 6ef99cafc..086f3753e 100644 --- a/kube-client/src/config/file_config.rs +++ b/kube-client/src/config/file_config.rs @@ -328,7 +328,7 @@ pub struct Context { /// Name of the cluster for this context pub cluster: String, /// Name of the `AuthInfo` for this context - pub user: String, + pub user: Option, /// The default namespace to use on unspecified requests #[serde(skip_serializing_if = "Option::is_none")] pub namespace: Option, diff --git a/kube-client/src/config/file_loader.rs b/kube-client/src/config/file_loader.rs index 5bd02c8af..3e18b25d9 100644 --- a/kube-client/src/config/file_loader.rs +++ b/kube-client/src/config/file_loader.rs @@ -82,24 +82,22 @@ impl ConfigLoader { .and_then(|named_cluster| named_cluster.cluster.clone()) .ok_or_else(|| KubeconfigError::LoadClusterOfContext(cluster_name.clone()))?; - let user_name = user.unwrap_or(¤t_context.user); + let user_name = user.or_else(|| current_context.user.as_ref()); // client-go doesn't fail on empty/missing user, so we don't either // see https://github.com/kube-rs/kube/issues/1594 - let mut user = config - .auth_infos - .iter() - .find(|named_user| &named_user.name == user_name) - .and_then(|named_user| named_user.auth_info.clone()) - .unwrap_or_else(|| { - // assuming that empty user is ok but if it's not empty user we should warn - if !user_name.is_empty() { - tracing::warn!("User {user_name} wasn't found in kubeconfig, using null auth"); - } - AuthInfo::default() - }); - - if let Some(exec_config) = &mut user.exec { + let mut auth_info = if let Some(user) = user_name { + config + .auth_infos + .iter() + .find(|named_user| &named_user.name == user) + .and_then(|named_user| named_user.auth_info.clone()) + .unwrap_or_else(AuthInfo::default) + } else { + AuthInfo::default() + }; + + if let Some(exec_config) = &mut auth_info.exec { if exec_config.provide_cluster_info { exec_config.cluster = Some((&cluster).try_into()?); } @@ -108,7 +106,7 @@ impl ConfigLoader { Ok(ConfigLoader { current_context, cluster, - user, + user: auth_info, }) }