diff --git a/examples/log_stream.rs b/examples/log_stream.rs index 601ab03ba..2953d8093 100644 --- a/examples/log_stream.rs +++ b/examples/log_stream.rs @@ -1,5 +1,9 @@ use futures::{AsyncBufReadExt, TryStreamExt}; -use k8s_openapi::api::core::v1::Pod; +use k8s_openapi::{ + api::core::v1::Pod, + apimachinery::pkg::apis::meta::v1::Time, + chrono::{DateTime, Utc}, +}; use kube::{ api::{Api, LogParams}, Client, @@ -19,8 +23,11 @@ struct App { follow: bool, /// Since seconds - #[arg(long, short = 's')] + #[arg(long, conflicts_with = "since_time")] since: Option<i64>, + /// Since time + #[arg(long, conflicts_with = "since")] + since_time: Option<DateTime<Utc>>, /// Include timestamps in the log output #[arg(long, default_value = "false")] @@ -43,6 +50,7 @@ async fn main() -> anyhow::Result<()> { container: app.container, tail_lines: app.tail, since_seconds: app.since, + since_time: app.since_time.map(|st| Time(st)), timestamps: app.timestamps, ..LogParams::default() }) diff --git a/kube-core/src/subresource.rs b/kube-core/src/subresource.rs index ebf560ddb..1c2ce7343 100644 --- a/kube-core/src/subresource.rs +++ b/kube-core/src/subresource.rs @@ -7,6 +7,7 @@ use crate::{ }; pub use k8s_openapi::api::autoscaling::v1::{Scale, ScaleSpec, ScaleStatus}; +use k8s_openapi::apimachinery::pkg::apis::meta::v1::Time; // ---------------------------------------------------------------------------- // Log subresource @@ -30,6 +31,11 @@ pub struct LogParams { /// If this value precedes the time a pod was started, only logs since the pod start will be returned. /// If this value is in the future, no logs will be returned. Only one of sinceSeconds or sinceTime may be specified. pub since_seconds: Option<i64>, + /// An RFC3339 timestamp from which to show logs. If this value + /// precedes the time a pod was started, only logs since the pod start will be returned. + /// If this value is in the future, no logs will be returned. + /// Only one of sinceSeconds or sinceTime may be specified. + pub since_time: Option<Time>, /// If set, the number of lines from the end of the logs to show. /// If not specified, logs are shown from the creation of the container or sinceSeconds or sinceTime pub tail_lines: Option<i64>, @@ -65,6 +71,9 @@ impl Request { if let Some(ss) = &lp.since_seconds { qp.append_pair("sinceSeconds", &ss.to_string()); + } else if let Some(st) = &lp.since_time { + let ser_since = st.0.to_rfc3339_opts(chrono::SecondsFormat::Secs, true); + qp.append_pair("sinceTime", &ser_since); } if let Some(tl) = &lp.tail_lines {