From ac786b3fead83d71f0c8cbebd94a4ee2e8ced459 Mon Sep 17 00:00:00 2001 From: Eliad Peller Date: Wed, 5 Mar 2025 15:18:46 +0200 Subject: [PATCH] kube-runtime: fix exponential backoff ExponentialBuilder::default() uses max_times=Some(3), which means it will give up after 3 times. call without_max_times() in order to avoid it. this matches the previous backoff-based implementation that called .with_max_elapsed_time(None) additionally, save the actual builder which contains all the relevant params, so we could reset it easily (the current implementation didn't use the same params in new() and reset()). Signed-off-by: Eliad Peller --- kube-runtime/src/watcher.rs | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/kube-runtime/src/watcher.rs b/kube-runtime/src/watcher.rs index 755320b38..28b90c0dd 100644 --- a/kube-runtime/src/watcher.rs +++ b/kube-runtime/src/watcher.rs @@ -885,39 +885,31 @@ pub fn watch_object Self { + let builder = backon::ExponentialBuilder::default() + .with_min_delay(min_delay) + .with_max_delay(max_delay) + .with_factor(factor) + .without_max_times(); + + if enable_jitter { + builder.with_jitter(); + } + Self { - inner: backon::ExponentialBuilder::default() - .with_min_delay(min_delay) - .with_max_delay(max_delay) - .with_factor(factor) - .with_jitter() - .build(), - min_delay, - max_delay, - factor, - enable_jitter, + inner: builder.build(), + builder, } } } impl Backoff for ExponentialBackoff { fn reset(&mut self) { - let mut builder = backon::ExponentialBuilder::default() - .with_min_delay(self.min_delay) - .with_max_delay(self.max_delay) - .with_factor(self.factor); - if self.enable_jitter { - builder = builder.with_jitter(); - } - self.inner = builder.build(); + self.inner = self.builder.build(); } }