Skip to content

Commit

Permalink
olm install - attempt to create resources until context is canceled
Browse files Browse the repository at this point in the history
which will typically occur when the specified timeout has
been reached

Signed-off-by: everettraven <everettraven@gmail.com>
  • Loading branch information
everettraven committed Dec 8, 2023
1 parent 22e3734 commit 2b9af4c
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions internal/olm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,10 @@ func (c Client) DoCreate(ctx context.Context, objs ...client.Object) error {
return nil
}

// try to create 10 times before giving up
// try to create resource until context is cancelled
// or resource is created successfully
func (c Client) safeCreateOneResource(ctx context.Context, obj client.Object, kind string, resourceName string) error {
backoff := wait.Backoff{
// retrying every one seconds. We're relaying on the timeout context, so the number of steps is very large, so
// we could use the timeout flag (or its default value), as it used to create the context.
Duration: time.Second,
Steps: 1000,
Factor: 1,
}

err := wait.ExponentialBackoffWithContext(ctx, backoff, func(ctx context.Context) (bool, error) {
err := wait.PollUntilContextCancel(ctx, time.Second, false, func(ctx context.Context) (bool, error) {
err := c.KubeClient.Create(ctx, obj)
if err == nil || apierrors.IsAlreadyExists(err) {
log.Infof(" %s %q created", kind, resourceName)
Expand Down

0 comments on commit 2b9af4c

Please sign in to comment.