From 3c3939f3988f8b8be7d1dbb9326565f3fd1d31eb Mon Sep 17 00:00:00 2001 From: Aviram Hassan Date: Tue, 8 Oct 2024 10:56:44 +0300 Subject: [PATCH] change auth behavior to match upstream on unknown/empty user - use null auth (#1595) Signed-off-by: Aviram Hassan --- kube-client/src/config/file_loader.rs | 11 ++++++++++- kube-client/src/config/mod.rs | 4 ---- 2 files changed, 10 insertions(+), 5 deletions(-) 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,