Skip to content

Commit

Permalink
fix: use master config in the env
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramilito committed Nov 17, 2024
1 parent c894030 commit aaf90df
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::config;
use crate::error::SetContextError;
use crate::KUBECONFIG;

use std::{
io::Cursor,
Expand All @@ -25,16 +26,25 @@ pub fn set_default_namespace(ns: &str, ctx: &str, target: &Path) {
}

pub fn set_default_context(ctx: &str, target: &Path) {
Command::new("kubectl")
let kubeconfig = format!(
"{}/.kube/config:{}",
dirs::home_dir().unwrap().display(),
target.to_string_lossy(),
);

let output = Command::new("kubectl")
.arg("config")
.arg(format!("--kubeconfig={}", target.to_string_lossy()))
.arg("use-context")
.arg(ctx)
.env("KUBECONFIG", KUBECONFIG.as_str())
.stdout(Stdio::null())
.spawn()
.unwrap()
.wait()
.unwrap();
.stderr(Stdio::piped())
.output()
.expect("Failed to execute command");

if !output.status.success() {
eprintln!("Error: {}", String::from_utf8_lossy(&output.stderr));
}
}

pub fn get_namespaces() -> Vec<String> {
Expand Down

0 comments on commit aaf90df

Please sign in to comment.