Skip to content

Commit

Permalink
Cronjob logs
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnedo committed Aug 12, 2024
1 parent 1951cf2 commit a9be658
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 8 additions & 31 deletions src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ pub async fn logs(args: LogArgs) -> Result<(), Box<dyn Error>> {
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())
}
}
}
Expand Down Expand Up @@ -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<dyn Error>> {
pub async fn log_child_pods(conns: &ssh::SshClients, resource_type: ResourceType, name: &str, ns: String, args: &LogArgs) -> Result<(), Box<dyn Error>> {
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(" ");
Expand All @@ -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<dyn Error>> {
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::<Vec<String>>()).into())
}

for res in result {
match res {
Err(e) => eprintln!("{}", e),
_ => {}
}
}

Ok(())
}

0 comments on commit a9be658

Please sign in to comment.