diff --git a/kube-client/src/config/file_loader.rs b/kube-client/src/config/file_loader.rs index a65ea2bbb..5bd02c8af 100644 --- a/kube-client/src/config/file_loader.rs +++ b/kube-client/src/config/file_loader.rs @@ -83,12 +83,21 @@ impl ConfigLoader { .ok_or_else(|| KubeconfigError::LoadClusterOfContext(cluster_name.clone()))?; let user_name = user.unwrap_or(¤t_context.user); + + // 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()) - .ok_or_else(|| KubeconfigError::FindUser(user_name.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 { if exec_config.provide_cluster_info { diff --git a/kube-client/src/config/mod.rs b/kube-client/src/config/mod.rs index a55c3e03f..20f25d21a 100644 --- a/kube-client/src/config/mod.rs +++ b/kube-client/src/config/mod.rs @@ -53,10 +53,6 @@ pub enum KubeconfigError { #[error("failed to load the cluster of context: {0}")] LoadClusterOfContext(String), - /// Failed to find named user - #[error("failed to find named user: {0}")] - FindUser(String), - /// Failed to find the path of kubeconfig #[error("failed to find the path of kubeconfig")] FindPath,