Skip to content

Commit

Permalink
Add basic retry
Browse files Browse the repository at this point in the history
  • Loading branch information
caseydavenport committed May 24, 2023
1 parent fe99bec commit fac549f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fac549f

Please sign in to comment.