diff --git a/README.md b/README.md index e1053d4..bbc0c29 100644 --- a/README.md +++ b/README.md @@ -156,16 +156,18 @@ sudo apt-get install -y gcc make libssl-dev pkg-config - [x] List - [ ] Store manifest in store so CNI plugin can get access - [x] Fix pod naming to avoid collisions + - [x] Logs - Deployments - [x] Apply - [x] Remove - [x] List - - [ ] Logs + - [x] Logs - [x] Output matches kubectl - Daemonsets - [x] Apply - [x] Remove - [x] List + - [x] Logs - [x] Output matches kubectl - Ingress - [x] Apply @@ -180,6 +182,7 @@ sudo apt-get install -y gcc make libssl-dev pkg-config - [x] Hash checking - [x] List - [x] Output matches kubectl + - [x] Logs - [ ] ForbidConcurrent - [ ] Create the pod when creating the cronjob to check it's legit - Secret diff --git a/src/logs.rs b/src/logs.rs index b3b510e..5b4a86b 100644 --- a/src/logs.rs +++ b/src/logs.rs @@ -78,13 +78,16 @@ pub async fn logs(args: LogArgs) -> Result<(), Box> { log_pod(&conns, name, ns, &args).await } "deployment" => { - log_deployment(&conns, name, ns, &args).await + log_child_pods(&conns, ResourceType::Deployment, name, ns, &args).await } "daemonset" => { - log_daemonset(&conns, name, ns, &args).await + log_child_pods(&conns, ResourceType::DaemonSet, name, ns, &args).await + } + "cronjob" => { + log_child_pods(&conns, ResourceType::CronJob, name, ns, &args).await } _ => { - Err(format!("Unexpected resource type {}", resource_type).into()) + Err(anyhow!("Unexpected resource type {}", resource_type).into()) } } } @@ -114,10 +117,10 @@ pub async fn log_pod(conns: &ssh::SshClients, name: &str, ns: String, args: &Log Ok(()) } -pub async fn log_deployment(conns: &ssh::SshClients, name: &str, ns: String, args: &LogArgs) -> Result<(), Box> { +pub async fn log_child_pods(conns: &ssh::SshClients, resource_type: ResourceType, name: &str, ns: String, args: &LogArgs) -> Result<(), Box> { let mut cmd = args.to_podman_log_args(); - cmd.push(format!("$(sudo podman pod ls --filter label=skate.io/deployment={} --filter label=skate.io/namespace={} -q)", name, ns)); + cmd.push(format!("$(sudo podman pod ls --filter label=skate.io/{}={} --filter label=skate.io/namespace={} -q)", resource_type.to_string().to_lowercase(), name, ns)); let cmd = cmd.join(" "); @@ -139,29 +142,3 @@ pub async fn log_deployment(conns: &ssh::SshClients, name: &str, ns: String, arg Ok(()) } - -pub async fn log_daemonset(conns: &ssh::SshClients, name: &str, ns: String, args: &LogArgs) -> Result<(), Box> { - let mut cmd = args.to_podman_log_args(); - - cmd.push(format!("$(sudo podman pod ls --filter label=skate.io/daemonset={} --filter label=skate.io/namespace={} -q)", name, ns)); - - let cmd = cmd.join(" "); - - let fut: FuturesUnordered<_> = conns.clients.iter().map(|c| c.execute_stdout(&cmd)).collect(); - - - let result: Vec<_> = fut.collect().await; - - if result.iter().all(|r| r.is_err()) { - return Err(format!("{:?}", result.into_iter().map(|r| r.err().unwrap().to_string()).collect::>()).into()) - } - - for res in result { - match res { - Err(e) => eprintln!("{}", e), - _ => {} - } - } - - Ok(()) -} \ No newline at end of file