diff --git a/pkg/repository/provider/unified_repo.go b/pkg/repository/provider/unified_repo.go index 51b9ef2873..988174fa90 100644 --- a/pkg/repository/provider/unified_repo.go +++ b/pkg/repository/provider/unified_repo.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "github.com/kopia/kopia/repo" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -188,11 +189,13 @@ func (urp *unifiedRepoProvider) PrepareRepo(ctx context.Context, param RepoParam log.Debug("Repo has already been initialized remotely") return nil } - log.Infof("failed to connect to the repo: %v, will try to create it", err) + if !errors.Is(err, repo.ErrRepositoryNotInitialized) { + return errors.Wrap(err, "error to connect to backup repo") + } err = urp.repoService.Init(ctx, *repoOption, true) if err != nil { - return errors.Wrap(err, "error to init backup repo") + return errors.Wrap(err, "error to create backup repo") } log.Debug("Prepare repo complete") diff --git a/pkg/repository/provider/unified_repo_test.go b/pkg/repository/provider/unified_repo_test.go index ff6c31b4a7..74cdc74b22 100644 --- a/pkg/repository/provider/unified_repo_test.go +++ b/pkg/repository/provider/unified_repo_test.go @@ -23,6 +23,7 @@ import ( "testing" awscredentials "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/kopia/kopia/repo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -648,7 +649,28 @@ func TestPrepareRepo(t *testing.T) { } return errors.New("fake-error-2") }, - expectedErr: "error to init backup repo: fake-error-2", + expectedErr: "error to connect to backup repo: fake-error-1", + }, + { + name: "not initialize", + getter: new(credmock.SecretStore), + credStoreReturn: "fake-password", + funcTable: localFuncTable{ + getStorageVariables: func(*velerov1api.BackupStorageLocation, string, string) (map[string]string, error) { + return map[string]string{}, nil + }, + getStorageCredentials: func(*velerov1api.BackupStorageLocation, velerocredentials.FileStore) (map[string]string, error) { + return map[string]string{}, nil + }, + }, + repoService: new(reposervicenmocks.BackupRepoService), + retFuncInit: func(ctx context.Context, repoOption udmrepo.RepoOptions, createNew bool) error { + if !createNew { + return repo.ErrRepositoryNotInitialized + } + return errors.New("fake-error-2") + }, + expectedErr: "error to create backup repo: fake-error-2", }, }