Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
332 changes: 160 additions & 172 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ clap = { version = "4", default-features = false }
hyper = { version = "1", default-features = false }
hyper-util = { version = "0.1", default-features = false }

k8s-openapi = { version = "0.25", default-features = false }
k8s-openapi = { version = "0.27", default-features = false }

kube-client = { version = ">=1.1.0,<1.2.0", default-features = false }
kube-core = { version = ">=1.1.0,<1.2.0", default-features = false }
kube-runtime = { version = ">=1.1.0,<1.2.0", default-features = false }
kube = { version = ">=1.1.0,<1.2.0", default-features = false }
kube-client = { version = "3.1", default-features = false }
kube-core = { version = "3.1", default-features = false }
kube-runtime = { version = "3.1", default-features = false }
kube = { version = "3.1", default-features = false }

prometheus-client = { version = "0.24.0", default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ features = [

[dev-dependencies]
anyhow = "1"
chrono = { version = "0.4", default-features = false }
futures = { version = "0.3", default-features = false }
jiff = "0.2"
maplit = "1"
prometheus-client = "0.24"
rand = "0.10"
Expand Down
4 changes: 1 addition & 3 deletions examples/lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ where

fn print_claim(claim: &kubert::lease::Claim, identity: &str) {
let holder = &claim.holder;
let expiry = claim
.expiry
.to_rfc3339_opts(chrono::SecondsFormat::Secs, true);
let expiry = claim.expiry.display_with_offset(jiff::tz::Offset::UTC);

if !claim.is_current() {
println!("! Expired for {holder} at {expiry}");
Expand Down
70 changes: 35 additions & 35 deletions examples/tests/lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ use tokio::time;

type Api = kube::Api<coordv1::Lease>;

macro_rules! assert_time_eq {
($a:expr, $b:expr $(,)?) => {
assert_eq!(
$a.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
$b.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
);
};
}

#[tokio::test(flavor = "current_thread")]
async fn exclusive() {
let handle = Handle::setup().await;
Expand All @@ -42,7 +33,7 @@ async fn exclusive() {
let lease1 = handle.init_new().await;
let claim1 = lease1.ensure_claimed("bob", &params).await.expect("claim");
assert_eq!(claim0.holder, claim1.holder);
assert_eq!(claim0.expiry.timestamp(), claim1.expiry.timestamp());
assert_eq!(claim0.expiry, claim1.expiry);
assert!(claim0.is_current_for("alice"));
assert!(claim1.is_current_for("alice"));
assert!(!claim0.is_current_for("bob"));
Expand All @@ -54,16 +45,18 @@ async fn exclusive() {
rsrc.holder_identity.as_deref().expect("holderIdentity"),
"alice"
);
assert_time_eq!(
assert_eq!(
rsrc.renew_time
.as_ref()
.map(|metav1::MicroTime(t)| t)
.expect("renewTime"),
claim0.expiry - chrono::Duration::from_std(params.lease_duration).unwrap()
.expect("renewTime")
.round(jiff::TimestampRound::new().smallest(jiff::Unit::Microsecond))
.unwrap(),
(claim0.expiry - params.lease_duration)
);
// Since we just acquired this, the acquire time and renew time are the
// same.
assert_time_eq!(
assert_eq!(
rsrc.acquire_time.as_ref().unwrap().0,
rsrc.renew_time.as_ref().unwrap().0
);
Expand Down Expand Up @@ -106,12 +99,13 @@ async fn expires() {
rsrc.holder_identity.as_deref().expect("holderIdentity"),
"bob"
);
assert_time_eq!(
rsrc.renew_time
assert_eq!(
*rsrc
.renew_time
.as_ref()
.map(|metav1::MicroTime(t)| t)
.expect("renewTime"),
claim1.expiry - chrono::Duration::from_std(params.lease_duration).unwrap(),
claim1.expiry - params.lease_duration,
);
// Since we just acquired this, the acquire time and renew time are the
// same.
Expand Down Expand Up @@ -162,19 +156,21 @@ async fn renews() {
rsrc.holder_identity.as_deref().expect("holderIdentity"),
"alice"
);
assert_time_eq!(
rsrc.renew_time
assert_eq!(
*rsrc
.renew_time
.as_ref()
.map(|metav1::MicroTime(t)| t)
.expect("renewTime"),
claim2.expiry - chrono::Duration::from_std(params.lease_duration).unwrap(),
claim2.expiry - params.lease_duration,
);
assert_time_eq!(
rsrc.acquire_time
assert_eq!(
*rsrc
.acquire_time
.as_ref()
.map(|metav1::MicroTime(t)| t)
.expect("renewTime"),
claim0.expiry - chrono::Duration::from_std(params.lease_duration).unwrap(),
claim0.expiry - params.lease_duration,
);
assert_eq!(
time::Duration::from_secs(
Expand Down Expand Up @@ -205,19 +201,21 @@ async fn renews() {
rsrc.holder_identity.as_deref().expect("holderIdentity"),
"bob"
);
assert_time_eq!(
rsrc.renew_time
assert_eq!(
*rsrc
.renew_time
.as_ref()
.map(|metav1::MicroTime(t)| t)
.expect("renewTime"),
claim3.expiry - chrono::Duration::from_std(params.lease_duration).unwrap(),
claim3.expiry - params.lease_duration,
);
assert_time_eq!(
rsrc.acquire_time
assert_eq!(
*rsrc
.acquire_time
.as_ref()
.map(|metav1::MicroTime(t)| t)
.expect("renewTime"),
claim3.expiry - chrono::Duration::from_std(params.lease_duration).unwrap(),
claim3.expiry - params.lease_duration,
);
assert_eq!(
time::Duration::from_secs(
Expand Down Expand Up @@ -276,19 +274,21 @@ async fn vacate_expired_noop() {
// Inspect the lease resource to verify that it has all expected fields.
let rsrc = handle.get().await;
assert_eq!(rsrc.holder_identity.as_deref(), Some("id"));
assert_time_eq!(
rsrc.renew_time
assert_eq!(
*rsrc
.renew_time
.as_ref()
.map(|metav1::MicroTime(t)| t)
.expect("renewTime"),
claim.expiry - chrono::Duration::from_std(params.lease_duration).unwrap(),
claim.expiry - params.lease_duration,
);
assert_time_eq!(
rsrc.acquire_time
assert_eq!(
*rsrc
.acquire_time
.as_ref()
.map(|metav1::MicroTime(t)| t)
.expect("renewTime"),
claim.expiry - chrono::Duration::from_std(params.lease_duration).unwrap(),
claim.expiry - params.lease_duration,
);
assert_eq!(rsrc.lease_duration_seconds, Some(3));
assert_eq!(rsrc.lease_transitions, Some(1));
Expand Down
8 changes: 4 additions & 4 deletions kubert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ initialized = [
]
lease = [
"dep:backon",
"dep:chrono",
"dep:futures-util",
"dep:hyper",
"dep:jiff",
"dep:k8s-openapi",
"dep:kube-client",
"dep:kube-core",
Expand Down Expand Up @@ -115,10 +115,10 @@ runtime = [
"shutdown",
]
runtime-diagnostics = [
"dep:chrono",
"dep:serde_json",
"dep:jiff",
"dep:k8s-openapi",
"dep:parking_lot",
"dep:serde_json",
"dep:sha2",
"runtime",
]
Expand Down Expand Up @@ -184,12 +184,12 @@ ahash = { version = "0.8", optional = true }
backon = { version = "1", optional = true, features = ["tokio-sleep"] }
bytes = { version = "1", optional = true }
drain = { version = "0.2.1", optional = true, default-features = false }
chrono = { version = "0.4", optional = true, default-features = false }
futures-core = { version = "0.3", optional = true, default-features = false }
futures-util = { version = "0.3", optional = true, default-features = false }
http-body-util = { version = "0.1", optional = true }
hyper = { workspace = true, optional = true, default-features = false }
hyper-util = { workspace = true, optional = true, default-features = false }
jiff = { version = "0.2", optional = true }
once_cell = { version = "1", optional = true }
parking_lot = { version = "0.12", optional = true }
pin-project-lite = { version = "0.2", optional = true }
Expand Down
7 changes: 4 additions & 3 deletions kubert/src/admin/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use jiff::Timestamp;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Time;
use parking_lot::Mutex;
use std::{net::SocketAddr, sync::Arc};
Expand All @@ -12,7 +13,7 @@ use self::watch::WatchDiagnostics;

#[derive(Clone, Debug)]
pub(crate) struct Diagnostics {
initial_time: chrono::DateTime<chrono::Utc>,
initial_time: Timestamp,
watches: Arc<Mutex<Vec<watch::StateRef>>>,
#[cfg(feature = "lease")]
leases: Arc<Mutex<Vec<lease::StateRef>>>,
Expand All @@ -37,7 +38,7 @@ struct Summary {
impl Diagnostics {
pub(super) fn new() -> Self {
Self {
initial_time: chrono::Utc::now(),
initial_time: Timestamp::now(),
watches: Default::default(),
#[cfg(feature = "lease")]
leases: Default::default(),
Expand Down Expand Up @@ -81,7 +82,7 @@ impl Diagnostics {
let leases = self.summarize_leases();
let summary = Summary {
initial_timestamp: Time(self.initial_time),
current_timestamp: Time(chrono::Utc::now()),
current_timestamp: Time(Timestamp::now()),
watches,
#[cfg(feature = "lease")]
leases,
Expand Down
5 changes: 3 additions & 2 deletions kubert/src/admin/diagnostics/lease.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use jiff::Timestamp;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Time;
use parking_lot::RwLock;
use std::{
Expand Down Expand Up @@ -54,7 +55,7 @@ impl LeaseDiagnostics {
field_manager,
}: &crate::LeaseParams,
) -> Self {
let now = Time(chrono::Utc::now());
let now = Time(Timestamp::now());
Self(Arc::new(RwLock::new(LeaseState {
name: name.clone(),
namespace: namespace.clone(),
Expand Down Expand Up @@ -90,7 +91,7 @@ impl LeaseDiagnostics {
{
return;
}
let now = Time(chrono::Utc::now());
let now = Time(Timestamp::now());
state.current = claim
.as_deref()
.cloned()
Expand Down
5 changes: 3 additions & 2 deletions kubert/src/admin/diagnostics/watch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ahash::AHashMap;
use jiff::Timestamp;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::{ObjectMeta, Time};
use kube_runtime::watcher;
use parking_lot::RwLock;
Expand Down Expand Up @@ -88,7 +89,7 @@ impl WatchDiagnostics {
api_url: api_url.to_string(),
label_selector: label_selector.unwrap_or_default().to_string(),
stats: WatchStats {
creation_timestamp: Time(chrono::Utc::now()),
creation_timestamp: Time(Timestamp::now()),
errors: 0,
last_error: None,
resets: 0,
Expand Down Expand Up @@ -137,7 +138,7 @@ impl WatchDiagnostics {
uid: meta.uid.clone().unwrap_or_default(),
};

let now = Time(chrono::Utc::now());
let now = Time(Timestamp::now());
let WatchState {
ref mut known,
ref mut resetting,
Expand Down
Loading
Loading