k8s_test_framework/
exec_tail.rs

1//! Perform a log lookup.
2
3use std::process::Stdio;
4
5use tokio::process::Command;
6
7use super::{Reader, Result};
8
9/// Exec a `tail` command reading the specified `file` within a `Container`
10/// in a `Pod` of a specified `resource` at the specified `namespace` via the
11/// specified `kubectl_command`.
12/// Returns a [`Reader`] that manages the reading process.
13pub fn exec_tail(
14    kubectl_command: &str,
15    namespace: &str,
16    resource: &str,
17    file: &str,
18) -> Result<Reader> {
19    let mut command = Command::new(kubectl_command);
20
21    command.stdin(Stdio::null()).stderr(Stdio::inherit());
22
23    command.arg("exec");
24    command.arg("-n").arg(namespace);
25    command.arg(resource);
26    command.arg("--");
27    command.arg("tail");
28    command.arg("--follow=name");
29    command.arg("--retry");
30    command.arg(file);
31
32    let reader = Reader::spawn(command)?;
33    Ok(reader)
34}