diff --git a/src/executor.rs b/src/executor.rs index 298d75e..b4223de 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -296,22 +296,7 @@ impl DefaultExecutor { let ids = ids.split("\n").collect::>(); - - let failures: Vec<_> = ids.iter().filter_map(|id|{ - match self.remove_pod(id, grace_period) { - Ok(_) => None, - Err(e) => { - Some(e) - } - } - }).collect(); - - if !failures.is_empty() { - let mut err = anyhow!("failures when removing pods for deployment"); - err = failures.iter().fold(err, |a, b| a.context(b.to_string())); - return Err(err.into()); - } - Ok(()) + self.remove_pods(ids, grace_period) } fn remove_daemonset(&self, daemonset: DaemonSet, grace_period: Option) -> Result<(), Box> { @@ -320,9 +305,11 @@ impl DefaultExecutor { let ids = exec_cmd("podman", &["ps", "--filter", &format!("label=skate.io/namespace={}", ns), "--filter", &format!("label=skate.io/daemonset={}", name), "-q"])?; let ids = ids.split("\n").collect::>(); + self.remove_pods(ids, grace_period) + } - - let failures: Vec<_> = ids.iter().filter_map(|id|{ + fn remove_pods(&self, ids: Vec<&str>, grace_period: Option) -> Result<(), Box> { + let failures: Vec<_> = ids.iter().filter_map(|id| { match self.remove_pod(id, grace_period) { Ok(_) => None, Err(e) => { @@ -332,8 +319,8 @@ impl DefaultExecutor { }).collect(); if !failures.is_empty() { - let mut err = anyhow!("failures when removing pods for daemonset"); - err = failures.iter().fold(err, |a, b| a.context(b.to_string())); + let mut err = anyhow!("failures when removing pods"); + err = failures.iter().fold(err, |a, b| a.context(b.to_string())); return Err(err.into()); } Ok(())