Skip to content

Commit

Permalink
Merge pull request #7762 from kaovilai/waitBackupRepoErrsVerbose
Browse files Browse the repository at this point in the history
Surface errors when waiting for backupRepository
  • Loading branch information
Lyndon-Li authored May 17, 2024
2 parents a0b7382 + 2c6853b commit 65a831e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/7762-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Surface errors when waiting for backupRepository and timeout occurs
9 changes: 8 additions & 1 deletion pkg/repository/ensurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ func (r *Ensurer) createBackupRepositoryAndWait(ctx context.Context, namespace s

func (r *Ensurer) waitBackupRepository(ctx context.Context, namespace string, backupRepoKey BackupRepositoryKey) (*velerov1api.BackupRepository, error) {
var repo *velerov1api.BackupRepository
var checkErr error
checkFunc := func(ctx context.Context) (bool, error) {
found, err := GetBackupRepository(ctx, r.repoClient, namespace, backupRepoKey, true)
if err == nil {
repo = found
return true, nil
} else if isBackupRepositoryNotFoundError(err) || isBackupRepositoryNotProvisionedError(err) {
checkErr = err
return false, nil
} else {
return false, err
Expand All @@ -131,7 +133,12 @@ func (r *Ensurer) waitBackupRepository(ctx context.Context, namespace string, ba

err := wait.PollUntilContextTimeout(ctx, time.Millisecond*500, r.resourceTimeout, true, checkFunc)
if err != nil {
return nil, errors.Wrap(err, "failed to wait BackupRepository")
if err == context.DeadlineExceeded {
// if deadline is exceeded, return the error from the last check instead of the wait error
return nil, errors.Wrap(checkErr, "failed to wait BackupRepository, timeout exceeded")
}
// if the error is not deadline exceeded, return the error from the wait
return nil, errors.Wrap(err, "failed to wait BackupRepository, errored early")
}

return repo, nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/repository/ensurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ func TestEnsureRepo(t *testing.T) {
bkRepoObjNotReady,
},
runtimeScheme: scheme,
err: "failed to wait BackupRepository: context deadline exceeded",
err: "failed to wait BackupRepository, timeout exceeded: backup repository not provisioned",
},
{
name: "create fail",
namespace: "fake-ns",
bsl: "fake-bsl",
repositoryType: "fake-repo-type",
runtimeScheme: scheme,
err: "failed to wait BackupRepository: context deadline exceeded",
err: "failed to wait BackupRepository, timeout exceeded: backup repository not provisioned",
},
}

Expand Down Expand Up @@ -175,15 +175,15 @@ func TestCreateBackupRepositoryAndWait(t *testing.T) {
bkRepoObj,
},
runtimeScheme: scheme,
err: "failed to wait BackupRepository: more than one BackupRepository found for workload namespace \"fake-ns\", backup storage location \"fake-bsl\", repository type \"fake-repo-type\"",
err: "failed to wait BackupRepository, errored early: more than one BackupRepository found for workload namespace \"fake-ns\", backup storage location \"fake-bsl\", repository type \"fake-repo-type\"",
},
{
name: "wait repo fail",
namespace: "fake-ns",
bsl: "fake-bsl",
repositoryType: "fake-repo-type",
runtimeScheme: scheme,
err: "failed to wait BackupRepository: context deadline exceeded",
err: "failed to wait BackupRepository, timeout exceeded: backup repository not provisioned",
},
}

Expand Down

0 comments on commit 65a831e

Please sign in to comment.