From fac549fb213dce0388f18d1c3c2366dcc33b0a11 Mon Sep 17 00:00:00 2001 From: Casey Davenport Date: Wed, 24 May 2023 16:14:42 -0700 Subject: [PATCH] Add basic retry --- main.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index e5a2dded32..15743aaf2d 100644 --- a/main.go +++ b/main.go @@ -258,10 +258,28 @@ func main() { // Check if we need to do any cleanup. client := mgr.GetClient() instance := &v1.Installation{} - if err := client.Get(ctx, utils.DefaultInstanceKey, instance); err != nil { - log.Errorf("Error querying Installation: %s", err) - return - } else if instance.DeletionTimestamp == nil { + retries := 0 + for { + if err := client.Get(ctx, utils.DefaultInstanceKey, instance); errors.IsNotFound(err) { + // No installation - we can exit immediately. + return + } else if err != nil { + // Error querying - retry after a small sleep. + if retries >= 5 { + log.Errorf("Too many retries, exiting with error: %s", err) + return + } + log.Errorf("Error querying Installation, will retry: %s", err) + retries++ + time.Sleep(1 * time.Second) + continue + } + + // Success + break + } + + if instance.DeletionTimestamp == nil { // Installation isn't terminating, so we can exit immediately. return }