From 6a0ee68c8878dcee0c5f56305f43a7ed73ef250a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natalie=20Klestrup=20R=C3=B6ijezon?= Date: Thu, 28 Nov 2024 16:20:13 +0100 Subject: [PATCH] Remove data from DefaultBackoffBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Natalie Klestrup Röijezon --- kube-runtime/src/utils/watch_ext.rs | 2 +- kube-runtime/src/watcher.rs | 42 +++++++++++++---------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/kube-runtime/src/utils/watch_ext.rs b/kube-runtime/src/utils/watch_ext.rs index a4560de1d..c6700ebf7 100644 --- a/kube-runtime/src/utils/watch_ext.rs +++ b/kube-runtime/src/utils/watch_ext.rs @@ -25,7 +25,7 @@ pub trait WatchStreamExt: Stream { where Self: TryStream + Sized, { - self.backoff(DefaultBackoffBuilder::default()) + self.backoff(DefaultBackoffBuilder) } /// Apply a specific [`BackoffBuilder`] policy to a [`Stream`] using [`StreamBackoff`] diff --git a/kube-runtime/src/watcher.rs b/kube-runtime/src/watcher.rs index aa4072067..0163af73d 100644 --- a/kube-runtime/src/watcher.rs +++ b/kube-runtime/src/watcher.rs @@ -890,38 +890,34 @@ pub fn watch_object; +/// when calling `WatchStreamExt::default_backoff`. +#[derive(Debug, Clone, Default)] +pub struct DefaultBackoffBuilder; /// See [`DefaultBackoffBuilder`]. #[derive(Debug)] pub struct DefaultBackoff(::Backoff); - -impl Default for DefaultBackoffBuilder { - fn default() -> Self { - Self(ResetTimerBackoffBuilder::new( - backon::ExponentialBuilder::default() - .with_min_delay(Duration::from_millis(800)) - .with_max_delay(Duration::from_secs(30)) - // .with_jitter() isn't quite a 1:1 match to randomization factor, it always *adds* 0..min_delay, vs multiplying - // the final delay by +-factor - .with_jitter() - // .with_randomization_factor(1.0) - .with_factor(2.0) - .without_max_times(), - Duration::from_secs(120), - )) - } -} +type Strategy = ResetTimerBackoffBuilder; impl BackoffBuilder for DefaultBackoffBuilder { type Backoff = DefaultBackoff; fn build(self) -> Self::Backoff { - DefaultBackoff(self.0.build()) + DefaultBackoff( + ResetTimerBackoffBuilder::new( + backon::ExponentialBuilder::default() + .with_min_delay(Duration::from_millis(800)) + .with_max_delay(Duration::from_secs(30)) + // .with_jitter() isn't quite a 1:1 match to randomization factor, it always *adds* 0..min_delay, vs multiplying + // the final delay by +-factor + .with_jitter() + // .with_randomization_factor(1.0) + .with_factor(2.0) + .without_max_times(), + Duration::from_secs(120), + ) + .build(), + ) } }