Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surface errors when waiting for backupRepository #7762

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
kaovilai marked this conversation as resolved.
Show resolved Hide resolved
checkErr = err
return false, nil
kaovilai marked this conversation as resolved.
Show resolved Hide resolved
} 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
Loading