use tokio::process::{Child, Command};
pub async fn port_forward(
kubectl: &str,
ns: &str,
target: &str,
remote_port: u16,
local_port: u16,
) -> anyhow::Result<Child> {
let mut command = Command::new(kubectl);
let child = command
.kill_on_drop(true)
.args([
"port-forward",
"-n",
ns,
target,
&format!("{}:{}", local_port, remote_port),
])
.spawn()?;
Ok(child)
}
#[cfg(test)]
mod test {
use super::*;
#[tokio::test]
async fn test_not_work() {
let result = port_forward("not_found", "gateway", "gateway-istio", 8080, 8080).await;
assert!(result.is_err());
}
}