1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-01 08:00:51 +00:00

fix: Add support for multiple Kubeconfig files (#635)

This adds support for having multiple Kubeconfig file set as part of the
`KUBECONFIG` env var.
This commit is contained in:
Thomas O'Donnell 2019-11-12 06:34:01 +01:00 committed by Matan Kushner
parent c7cbaa155e
commit fc2f644237

View File

@ -38,15 +38,23 @@ fn get_kube_context(contents: &str) -> Option<(String, String)> {
Some((current_ctx.to_string(), ns.to_string()))
}
fn parse_kubectl_file(filename: &path::PathBuf) -> Option<(String, String)> {
let contents = utils::read_file(filename).ok()?;
get_kube_context(&contents)
}
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let filename = match env::var("KUBECONFIG") {
Ok(path) => path::PathBuf::from(path),
Err(_) => dirs::home_dir()?.join(".kube").join("config"),
let kube_cfg = match env::var("KUBECONFIG") {
Ok(paths) => env::split_paths(&paths)
.filter_map(|filename| parse_kubectl_file(&filename))
.nth(0),
Err(_) => {
let filename = dirs::home_dir()?.join(".kube").join("config");
parse_kubectl_file(&filename)
}
};
let contents = utils::read_file(filename).ok()?;
match get_kube_context(&contents) {
match kube_cfg {
Some(kube_cfg) => {
let (kube_ctx, kube_ns) = kube_cfg;