Compare commits
4 Commits
fix/nats_n
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a1aad62c9 | |||
| 0f9a53c8f6 | |||
| b21829470d | |||
| 4dcaf55dc5 |
@@ -1006,8 +1006,28 @@ impl K8sAnywhereConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_env() -> Self {
|
fn from_env() -> Self {
|
||||||
|
fn get_kube_config_path() -> Option<std::path::PathBuf> {
|
||||||
|
// 1. Check for the KUBECONFIG environment variable first (standard practice)
|
||||||
|
if let Ok(val) = std::env::var("KUBECONFIG") {
|
||||||
|
if !val.is_empty() {
|
||||||
|
return Some(std::path::PathBuf::from(val));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Use the standard library to find the home directory
|
||||||
|
// As of recent Rust versions, this is the preferred cross-platform method.
|
||||||
|
let mut path = std::env::home_dir()?;
|
||||||
|
|
||||||
|
// 3. Construct the path to .kube/config
|
||||||
|
// .push() handles OS-specific separators (\ for Windows, / for Unix)
|
||||||
|
path.push(".kube");
|
||||||
|
path.push("config");
|
||||||
|
|
||||||
|
Some(path)
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
kubeconfig: std::env::var("KUBECONFIG").ok().map(|v| v.to_string()),
|
kubeconfig: get_kube_config_path().map(|s| s.to_string_lossy().into_owned()),
|
||||||
use_system_kubeconfig: std::env::var("HARMONY_USE_SYSTEM_KUBECONFIG")
|
use_system_kubeconfig: std::env::var("HARMONY_USE_SYSTEM_KUBECONFIG")
|
||||||
.map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
|
.map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
|
||||||
autoinstall: std::env::var("HARMONY_AUTOINSTALL")
|
autoinstall: std::env::var("HARMONY_AUTOINSTALL")
|
||||||
|
|||||||
Reference in New Issue
Block a user