Skip to content

Commit f947198

Browse files
authored
Use sync timeout to decide how long to retry waiting for k8s api for prometheus.operator.* components (#4568)
* use sync timeout to decide how long to retry waiting for k8s api
1 parent 08c69ec commit f947198

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Main (unreleased)
5252

5353
- Fix potential deadlock in `loki.source.journal` when stopping or reloading the component. (@thampiotr)
5454

55+
- Honor sync timeout when waiting for network availability for prometheus.operator.* components. (@dehaansa)
56+
5557
v1.11.0
5658
-----------------
5759

internal/component/prometheus/operator/common/crdmanager.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,21 +364,26 @@ func (c *crdManager) configureInformers(ctx context.Context, informers cache.Inf
364364
var informer cache.Informer
365365
var err error
366366

367+
timeoutCtx, cancel := context.WithTimeout(ctx, c.args.InformerSyncTimeout)
368+
deadline, _ := timeoutCtx.Deadline()
369+
defer cancel()
367370
backoff := backoff.New(
368-
ctx,
371+
timeoutCtx,
369372
backoff.Config{
370373
MinBackoff: 1 * time.Second,
371374
MaxBackoff: 10 * time.Second,
372-
MaxRetries: 3, // retry up to 3 times
375+
MaxRetries: 0, // Will retry until InformerSyncTimeout is reached
373376
},
374377
)
375-
for backoff.Ongoing() {
378+
for {
376379
// Retry to get the informer in case of a timeout.
377380
informer, err = getInformer(ctx, informers, prototype, c.args.InformerSyncTimeout)
378-
if err == nil {
381+
nextDelay := backoff.NextDelay()
382+
// exit loop on success, timeout, max retries reached, or if next backoff exceeds timeout
383+
if err == nil || !backoff.Ongoing() || time.Now().Add(nextDelay).After(deadline) {
379384
break
380385
}
381-
level.Warn(c.logger).Log("msg", "failed to get informer, retrying", "next backoff", backoff.NextDelay(), "err", err)
386+
level.Warn(c.logger).Log("msg", "failed to get informer, retrying", "next backoff", nextDelay, "err", err)
382387
backoff.Wait()
383388
}
384389
if err != nil {

0 commit comments

Comments
 (0)