Skip to content

Commit

Permalink
allow null user in kubeconfig's context (#1608)
Browse files Browse the repository at this point in the history
Signed-off-by: Aviram Hassan <[email protected]>
  • Loading branch information
aviramha authored Oct 18, 2024
1 parent 9dd62b9 commit 1addf43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion kube-client/src/config/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// The default namespace to use on unspecified requests
#[serde(skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
Expand Down
30 changes: 14 additions & 16 deletions kube-client/src/config/file_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&current_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()?);
}
Expand All @@ -108,7 +106,7 @@ impl ConfigLoader {
Ok(ConfigLoader {
current_context,
cluster,
user,
user: auth_info,
})
}

Expand Down

0 comments on commit 1addf43

Please sign in to comment.