From 0bf551f5afda730e9a3341ab309d948d9f9038e9 Mon Sep 17 00:00:00 2001 From: kazk Date: Fri, 19 Nov 2021 15:10:02 -0800 Subject: [PATCH] Fix empty kubeconfig file not defaulting Signed-off-by: kazk --- kube-client/src/config/file_config.rs | 4 ++-- kube-client/src/config/mod.rs | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/kube-client/src/config/file_config.rs b/kube-client/src/config/file_config.rs index dd394aa35..956221df8 100644 --- a/kube-client/src/config/file_config.rs +++ b/kube-client/src/config/file_config.rs @@ -258,8 +258,8 @@ impl Kubeconfig { merged_docs = Some(config); } } - let config = merged_docs.ok_or_else(|| KubeconfigError::EmptyConfig(path.as_ref().to_path_buf()))?; - Ok(config) + // Empty file defaults to an empty Kubeconfig + Ok(merged_docs.unwrap_or_default()) } /// Read a Config from `KUBECONFIG` or the the default location. diff --git a/kube-client/src/config/mod.rs b/kube-client/src/config/mod.rs index bfe93e41d..7ee9ede40 100644 --- a/kube-client/src/config/mod.rs +++ b/kube-client/src/config/mod.rs @@ -69,10 +69,6 @@ pub enum KubeconfigError { #[error("the structure of the parsed kubeconfig is invalid: {0}")] InvalidStructure(#[source] serde_yaml::Error), - /// Failed to find a single YAML document in kubeconfig - #[error("failed to find a single YAML document in kubeconfig: {0}")] - EmptyConfig(PathBuf), - /// Failed to parse cluster url #[error("failed to parse cluster url: {0}")] ParseClusterUrl(#[source] http::uri::InvalidUri),