diff --git a/src/kubectl.rs b/src/kubectl.rs index d621b16..2533971 100644 --- a/src/kubectl.rs +++ b/src/kubectl.rs @@ -4,6 +4,7 @@ use crate::cli::KubectlPathBuf; use crate::config::{ConfigId, OperationalConfig, PortForwardConfig, RetryDelay}; +use anyhow::anyhow; use serde::Deserialize; use std::env::current_dir; use std::io::{BufRead, Read}; @@ -248,11 +249,23 @@ impl Kubectl { // Wait for the child process to finish let status = child.wait(); let status = match status { - Ok(status) => status, + Ok(status) => { + match status.code().unwrap() { + 1 => { + // Kill the process if the exit code is 1 + out_tx + .send(ChildEvent::Exit(id, status, RestartPolicy::None)) + .ok(); + break 'new_process Err(anyhow!("Command returned status code 1")); + } + _ => {} + }; + status + } Err(e) => { out_tx.send(ChildEvent::Error(id, ChildError::Wait(e))).ok(); - // TODO: Break out of this loop if the error is unfixable? continue 'new_process; + // TODO: Break out of this loop if the error is unfixable? } }; @@ -310,6 +323,7 @@ pub enum ChildEvent { #[derive(Debug)] pub enum RestartPolicy { WillRestartIn(RetryDelay), + None, } #[derive(Debug, thiserror::Error)] diff --git a/src/main.rs b/src/main.rs index 63fb34f..77e9c96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -251,13 +251,19 @@ fn start_output_loop_thread(out_rx: Receiver) -> JoinHandle<()> { "{id}: Process exited with {} - will retry in {}", status, delay ); - } else { + } else if delay == RetryDelay::NONE { eprintln!( "{id}: Process exited with {} - retrying immediately", status ); } } + RestartPolicy::None => { + eprintln!( + "{id}: Process exited with {} - shutting process down", + status + ); + } } } ChildEvent::Error(id, error) => {