Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow null user in kubeconfig's context #1608

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
.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()

Check warning on line 97 in kube-client/src/config/file_loader.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/config/file_loader.rs#L97

Added line #L97 was not covered by tests
};

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 @@
Ok(ConfigLoader {
current_context,
cluster,
user,
user: auth_info,
})
}

Expand Down
Loading