Merge pull request #5359 from Lyndon-Li/issue-fix-5358

Issue fix 5358
pull/5362/head
Xun Jiang/Bruce Jiang 2022-09-19 17:10:28 +08:00 committed by GitHub
commit ac2bb3ea2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -0,0 +1 @@
Fix a repoEnsurer problem introduced by the refactor - The repoEnsurer didn't check "" state of BackupRepository, as a result, the function GetBackupRepository always returns without an error even though the ensreReady is specified.

View File

@ -83,7 +83,7 @@ func GetBackupRepository(ctx context.Context, cli client.Client, namespace strin
return nil, errors.Errorf("backup repository is not ready: %s", repo.Status.Message)
}
if repo.Status.Phase == velerov1api.BackupRepositoryPhaseNew {
if repo.Status.Phase == "" || repo.Status.Phase == velerov1api.BackupRepositoryPhaseNew {
return nil, backupRepoNotProvisionedError
}
}

View File

@ -96,6 +96,14 @@ func TestGetBackupRepository(t *testing.T) {
backupRepositoryKey: BackupRepositoryKey{"fake-volume-ns-02", "fake-bsl-02", "fake-repository-type-02"},
expected: buildBackupRepoPointer(BackupRepositoryKey{"fake-volume-ns-02", "fake-bsl-02", "fake-repository-type-02"}, velerov1api.BackupRepositoryPhaseNew, "02"),
},
{
name: "repository state is empty, not expect ready",
backupRepositories: []velerov1api.BackupRepository{
buildBackupRepo(BackupRepositoryKey{"fake-volume-ns-01", "fake-bsl-01", "fake-repository-type-01"}, velerov1api.BackupRepositoryPhaseReady, "01"),
buildBackupRepo(BackupRepositoryKey{"fake-volume-ns-02", "fake-bsl-02", "fake-repository-type-02"}, "", "02")},
backupRepositoryKey: BackupRepositoryKey{"fake-volume-ns-02", "fake-bsl-02", "fake-repository-type-02"},
expected: buildBackupRepoPointer(BackupRepositoryKey{"fake-volume-ns-02", "fake-bsl-02", "fake-repository-type-02"}, "", "02"),
},
{
name: "repository not ready, expect ready",
backupRepositories: []velerov1api.BackupRepository{
@ -114,6 +122,15 @@ func TestGetBackupRepository(t *testing.T) {
ensureReady: true,
expectedErr: "backup repository not provisioned",
},
{
name: "repository state is empty, expect ready",
backupRepositories: []velerov1api.BackupRepository{
buildBackupRepo(BackupRepositoryKey{"fake-volume-ns-01", "fake-bsl-01", "fake-repository-type-01"}, velerov1api.BackupRepositoryPhaseReady, "01"),
buildBackupRepo(BackupRepositoryKey{"fake-volume-ns-02", "fake-bsl-02", "fake-repository-type-02"}, "", "02")},
backupRepositoryKey: BackupRepositoryKey{"fake-volume-ns-02", "fake-bsl-02", "fake-repository-type-02"},
ensureReady: true,
expectedErr: "backup repository not provisioned",
},
{
name: "repository ready, expect ready",
backupRepositories: []velerov1api.BackupRepository{
@ -135,7 +152,7 @@ func TestGetBackupRepository(t *testing.T) {
backupRepo, err := GetBackupRepository(context.Background(), fakeClient, velerov1api.DefaultNamespace, tc.backupRepositoryKey, tc.ensureReady)
if backupRepo != nil {
if backupRepo != nil && tc.expected != nil {
backupRepo.ResourceVersion = tc.expected.ResourceVersion
require.Equal(t, *tc.expected, *backupRepo)
} else {