diff --git a/changelogs/unreleased/7762-kaovilai b/changelogs/unreleased/7762-kaovilai new file mode 100644 index 0000000000..6c515123dc --- /dev/null +++ b/changelogs/unreleased/7762-kaovilai @@ -0,0 +1 @@ +Surface errors when waiting for backupRepository and timeout occurs diff --git a/pkg/repository/ensurer.go b/pkg/repository/ensurer.go index 96feeb8fa4..db1e596479 100644 --- a/pkg/repository/ensurer.go +++ b/pkg/repository/ensurer.go @@ -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 @@ -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 diff --git a/pkg/repository/ensurer_test.go b/pkg/repository/ensurer_test.go index a5128c9b44..d480ba1a47 100644 --- a/pkg/repository/ensurer_test.go +++ b/pkg/repository/ensurer_test.go @@ -102,7 +102,7 @@ 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", @@ -110,7 +110,7 @@ func TestEnsureRepo(t *testing.T) { 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", }, } @@ -175,7 +175,7 @@ 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", @@ -183,7 +183,7 @@ func TestCreateBackupRepositoryAndWait(t *testing.T) { 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", }, }