Skip to content
Merged
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
2 changes: 1 addition & 1 deletion kube-runtime/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ where
},
run_at: reconciler_finished_at
.checked_add(requeue_after)
.unwrap_or_else(crate::scheduler::far_future),
.unwrap_or_else(crate::scheduler::max_schedule_time),
}),
result: Some(result),
}
Expand Down
14 changes: 8 additions & 6 deletions kube-runtime/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
let next_time = request
.run_at
.checked_add(*self.debounce)
.unwrap_or_else(far_future);
.map_or_else(max_schedule_time, |time|
// Clamp `time` to avoid [`DelayQueue`] panic (see <https://github.com/kube-rs/kube/issues/1772>)
time.min(max_schedule_time()));
match self.scheduled.raw_entry_mut().from_key(&request.message) {
// If new request is supposed to be earlier than the current entry's scheduled
// time (for eg: the new request is user triggered and the current entry is the
Expand Down Expand Up @@ -220,7 +222,7 @@
///
/// NOTE: `can_take_message` should be considered to be fairly performance-sensitive, since
/// it will generally be executed for each pending message, for each [`poll_next`](Self::poll_next).
pub fn hold_unless<C: Fn(&T) -> bool>(self: Pin<&mut Self>, can_take_message: C) -> HoldUnless<T, R, C> {

Check warning on line 225 in kube-runtime/src/scheduler.rs

View workflow job for this annotation

GitHub Actions / clippy_nightly

lifetime flowing from input to output with different syntax can be confusing

warning: lifetime flowing from input to output with different syntax can be confusing --> kube-runtime/src/scheduler.rs:225:53 | 225 | pub fn hold_unless<C: Fn(&T) -> bool>(self: Pin<&mut Self>, can_take_message: C) -> HoldUnless<T, R, C> { | ^^^^^^^^^ ------------------- the lifetime gets resolved as `'_` | | | this lifetime flows to the output | = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default help: one option is to remove the lifetime for references and use the anonymous lifetime for paths | 225 | pub fn hold_unless<C: Fn(&T) -> bool>(self: Pin<&mut Self>, can_take_message: C) -> HoldUnless<'_, T, R, C> { | +++
HoldUnless {
scheduler: self,
can_take_message,
Expand All @@ -231,7 +233,7 @@
/// Its equivalent to doing `self.hold_unless(|_| false)` and is useful when the
/// consumer is not ready to consume the expired messages that the [`Scheduler`] emits.
#[must_use]
pub fn hold(self: Pin<&mut Self>) -> Hold<T, R> {

Check warning on line 236 in kube-runtime/src/scheduler.rs

View workflow job for this annotation

GitHub Actions / clippy_nightly

lifetime flowing from input to output with different syntax can be confusing

warning: lifetime flowing from input to output with different syntax can be confusing --> kube-runtime/src/scheduler.rs:236:27 | 236 | pub fn hold(self: Pin<&mut Self>) -> Hold<T, R> { | ^^^^^^^^^ ---------- the lifetime gets resolved as `'_` | | | this lifetime flows to the output | help: one option is to remove the lifetime for references and use the anonymous lifetime for paths | 236 | pub fn hold(self: Pin<&mut Self>) -> Hold<'_, T, R> { | +++
Hold { scheduler: self }
}

Expand Down Expand Up @@ -283,11 +285,11 @@
Scheduler::new(requests, debounce)
}

// internal fallback for overflows in schedule times
pub(crate) fn far_future() -> Instant {
// private method from tokio for convenience - remove if upstream becomes pub
// https://github.com/tokio-rs/tokio/blob/6fcd9c02176bf3cd570bc7de88edaa3b95ea480a/tokio/src/time/instant.rs#L57-L63
Instant::now() + Duration::from_secs(86400 * 365 * 30)
// [`DelayQueue`] panics when trying to schedule an event further than 2 years into the future.
// (See <https://github.com/kube-rs/kube/issues/1772>.)
// We limit all scheduled durations to 6 months to stay well clear of that limit.
pub(crate) fn max_schedule_time() -> Instant {
Instant::now() + Duration::from_secs(86400 * 30 * 6)
}

#[cfg(test)]
Expand Down
Loading