Skip to content

Commit 3c3939f

Browse files
authored
change auth behavior to match upstream on unknown/empty user - use null auth (#1595)
Signed-off-by: Aviram Hassan <aviramyhassan@gmail.com>
1 parent 7920fc3 commit 3c3939f

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

kube-client/src/config/file_loader.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,21 @@ impl ConfigLoader {
8383
.ok_or_else(|| KubeconfigError::LoadClusterOfContext(cluster_name.clone()))?;
8484

8585
let user_name = user.unwrap_or(&current_context.user);
86+
87+
// client-go doesn't fail on empty/missing user, so we don't either
88+
// see https://github.com/kube-rs/kube/issues/1594
8689
let mut user = config
8790
.auth_infos
8891
.iter()
8992
.find(|named_user| &named_user.name == user_name)
9093
.and_then(|named_user| named_user.auth_info.clone())
91-
.ok_or_else(|| KubeconfigError::FindUser(user_name.clone()))?;
94+
.unwrap_or_else(|| {
95+
// assuming that empty user is ok but if it's not empty user we should warn
96+
if !user_name.is_empty() {
97+
tracing::warn!("User {user_name} wasn't found in kubeconfig, using null auth");
98+
}
99+
AuthInfo::default()
100+
});
92101

93102
if let Some(exec_config) = &mut user.exec {
94103
if exec_config.provide_cluster_info {

kube-client/src/config/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ pub enum KubeconfigError {
5353
#[error("failed to load the cluster of context: {0}")]
5454
LoadClusterOfContext(String),
5555

56-
/// Failed to find named user
57-
#[error("failed to find named user: {0}")]
58-
FindUser(String),
59-
6056
/// Failed to find the path of kubeconfig
6157
#[error("failed to find the path of kubeconfig")]
6258
FindPath,

0 commit comments

Comments
 (0)