issue8827: Pass logger in call chain (#8875)
* Pass logger in call chain Signed-off-by: hu-keyu <hzldd999@gmail.com>pull/8879/head
parent
c6a420bd3a
commit
e06b62e3a8
|
@ -0,0 +1 @@
|
||||||
|
Pass the logger in kopia related operations.
|
|
@ -19,6 +19,8 @@ package backend
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob"
|
"github.com/kopia/kopia/repo/blob"
|
||||||
|
|
||||||
"github.com/vmware-tanzu/velero/pkg/repository/udmrepo"
|
"github.com/vmware-tanzu/velero/pkg/repository/udmrepo"
|
||||||
|
@ -29,17 +31,19 @@ type AzureBackend struct {
|
||||||
option azure.Option
|
option azure.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AzureBackend) Setup(ctx context.Context, flags map[string]string) error {
|
func (c *AzureBackend) Setup(ctx context.Context, flags map[string]string, logger logrus.FieldLogger) error {
|
||||||
if flags[udmrepo.StoreOptionCACert] != "" {
|
if flags[udmrepo.StoreOptionCACert] != "" {
|
||||||
flags["caCertEncoded"] = "true"
|
flags["caCertEncoded"] = "true"
|
||||||
}
|
}
|
||||||
c.option = azure.Option{
|
c.option = azure.Option{
|
||||||
Config: flags,
|
Config: flags,
|
||||||
Limits: setupLimits(ctx, flags),
|
Limits: setupLimits(ctx, flags),
|
||||||
|
Logger: logger,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AzureBackend) Connect(ctx context.Context, isCreate bool) (blob.Storage, error) {
|
func (c *AzureBackend) Connect(ctx context.Context, isCreate bool, logger logrus.FieldLogger) (blob.Storage, error) {
|
||||||
|
c.option.Logger = logger
|
||||||
return azure.NewStorage(ctx, &c.option, false)
|
return azure.NewStorage(ctx, &c.option, false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,11 @@ package azure
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob"
|
"github.com/kopia/kopia/repo/blob"
|
||||||
"github.com/kopia/kopia/repo/blob/azure"
|
"github.com/kopia/kopia/repo/blob/azure"
|
||||||
"github.com/kopia/kopia/repo/blob/throttling"
|
"github.com/kopia/kopia/repo/blob/throttling"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/vmware-tanzu/velero/pkg/repository/udmrepo"
|
"github.com/vmware-tanzu/velero/pkg/repository/udmrepo"
|
||||||
azureutil "github.com/vmware-tanzu/velero/pkg/util/azure"
|
azureutil "github.com/vmware-tanzu/velero/pkg/util/azure"
|
||||||
|
@ -33,12 +34,13 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
blob.AddSupportedStorage(storageType, Option{}, NewStorage)
|
blob.AddSupportedStorage(storageType, Option{Logger: logrus.New()}, NewStorage)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Option struct {
|
type Option struct {
|
||||||
Config map[string]string `json:"config" kopia:"sensitive"`
|
Config map[string]string `json:"config" kopia:"sensitive"`
|
||||||
Limits throttling.Limits
|
Limits throttling.Limits
|
||||||
|
Logger logrus.FieldLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
|
@ -56,7 +58,7 @@ func (s *Storage) ConnectionInfo() blob.ConnectionInfo {
|
||||||
func NewStorage(ctx context.Context, option *Option, isCreate bool) (blob.Storage, error) {
|
func NewStorage(ctx context.Context, option *Option, isCreate bool) (blob.Storage, error) {
|
||||||
cfg := option.Config
|
cfg := option.Config
|
||||||
|
|
||||||
client, _, err := azureutil.NewStorageClient(logrus.New(), cfg)
|
client, _, err := azureutil.NewStorageClient(option.Logger, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob/throttling"
|
"github.com/kopia/kopia/repo/blob/throttling"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -29,6 +31,7 @@ import (
|
||||||
|
|
||||||
func TestAzureSetup(t *testing.T) {
|
func TestAzureSetup(t *testing.T) {
|
||||||
backend := AzureBackend{}
|
backend := AzureBackend{}
|
||||||
|
logger := velerotest.NewLogger()
|
||||||
|
|
||||||
flags := map[string]string{
|
flags := map[string]string{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
|
@ -40,7 +43,7 @@ func TestAzureSetup(t *testing.T) {
|
||||||
UploadBytesPerSecond: 200,
|
UploadBytesPerSecond: 200,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := backend.Setup(context.Background(), flags)
|
err := backend.Setup(context.Background(), flags, logger)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, flags, backend.option.Config)
|
assert.Equal(t, flags, backend.option.Config)
|
||||||
assert.Equal(t, limits, backend.option.Limits)
|
assert.Equal(t, limits, backend.option.Limits)
|
||||||
|
|
|
@ -19,6 +19,8 @@ package backend
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob"
|
"github.com/kopia/kopia/repo/blob"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,8 +28,8 @@ import (
|
||||||
// the backend storage
|
// the backend storage
|
||||||
type Store interface {
|
type Store interface {
|
||||||
// Setup setups the variables to a specific backend storage
|
// Setup setups the variables to a specific backend storage
|
||||||
Setup(ctx context.Context, flags map[string]string) error
|
Setup(ctx context.Context, flags map[string]string, logger logrus.FieldLogger) error
|
||||||
|
|
||||||
// Connect connects to a specific backend storage with the storage variables
|
// Connect connects to a specific backend storage with the storage variables
|
||||||
Connect(ctx context.Context, isCreate bool) (blob.Storage, error)
|
Connect(ctx context.Context, isCreate bool, logger logrus.FieldLogger) (blob.Storage, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob"
|
"github.com/kopia/kopia/repo/blob"
|
||||||
"github.com/kopia/kopia/repo/blob/filesystem"
|
"github.com/kopia/kopia/repo/blob/filesystem"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -36,7 +38,7 @@ const (
|
||||||
defaultDirMode = 0o700
|
defaultDirMode = 0o700
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *FsBackend) Setup(ctx context.Context, flags map[string]string) error {
|
func (c *FsBackend) Setup(ctx context.Context, flags map[string]string, logger logrus.FieldLogger) error {
|
||||||
path, err := mustHaveString(udmrepo.StoreOptionFsPath, flags)
|
path, err := mustHaveString(udmrepo.StoreOptionFsPath, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -53,7 +55,7 @@ func (c *FsBackend) Setup(ctx context.Context, flags map[string]string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FsBackend) Connect(ctx context.Context, isCreate bool) (blob.Storage, error) {
|
func (c *FsBackend) Connect(ctx context.Context, isCreate bool, logger logrus.FieldLogger) (blob.Storage, error) {
|
||||||
if !filepath.IsAbs(c.options.Path) {
|
if !filepath.IsAbs(c.options.Path) {
|
||||||
return nil, errors.Errorf("filesystem repository path is not absolute, path: %s", c.options.Path)
|
return nil, errors.Errorf("filesystem repository path is not absolute, path: %s", c.options.Path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob/filesystem"
|
"github.com/kopia/kopia/repo/blob/filesystem"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
@ -63,11 +65,12 @@ func TestFSSetup(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger := velerotest.NewLogger()
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
fsFlags := FsBackend{}
|
fsFlags := FsBackend{}
|
||||||
|
|
||||||
err := fsFlags.Setup(context.Background(), tc.flags)
|
err := fsFlags.Setup(context.Background(), tc.flags, logger)
|
||||||
|
|
||||||
if tc.expectedErr == "" {
|
if tc.expectedErr == "" {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -19,6 +19,8 @@ package backend
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob"
|
"github.com/kopia/kopia/repo/blob"
|
||||||
"github.com/kopia/kopia/repo/blob/gcs"
|
"github.com/kopia/kopia/repo/blob/gcs"
|
||||||
|
|
||||||
|
@ -29,7 +31,7 @@ type GCSBackend struct {
|
||||||
options gcs.Options
|
options gcs.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GCSBackend) Setup(ctx context.Context, flags map[string]string) error {
|
func (c *GCSBackend) Setup(ctx context.Context, flags map[string]string, logger logrus.FieldLogger) error {
|
||||||
var err error
|
var err error
|
||||||
c.options.BucketName, err = mustHaveString(udmrepo.StoreOptionOssBucket, flags)
|
c.options.BucketName, err = mustHaveString(udmrepo.StoreOptionOssBucket, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -49,6 +51,6 @@ func (c *GCSBackend) Setup(ctx context.Context, flags map[string]string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GCSBackend) Connect(ctx context.Context, isCreate bool) (blob.Storage, error) {
|
func (c *GCSBackend) Connect(ctx context.Context, isCreate bool, logger logrus.FieldLogger) (blob.Storage, error) {
|
||||||
return gcs.New(ctx, &c.options, false)
|
return gcs.New(ctx, &c.options, false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob/gcs"
|
"github.com/kopia/kopia/repo/blob/gcs"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
@ -85,11 +87,12 @@ func TestGcsSetup(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger := velerotest.NewLogger()
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
gcsFlags := GCSBackend{}
|
gcsFlags := GCSBackend{}
|
||||||
|
|
||||||
err := gcsFlags.Setup(context.Background(), tc.flags)
|
err := gcsFlags.Setup(context.Background(), tc.flags, logger)
|
||||||
|
|
||||||
if tc.expectedErr == "" {
|
if tc.expectedErr == "" {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -4,6 +4,7 @@ package mocks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
context "context"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
blob "github.com/kopia/kopia/repo/blob"
|
blob "github.com/kopia/kopia/repo/blob"
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ type Store struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect provides a mock function with given fields: ctx, isCreate
|
// Connect provides a mock function with given fields: ctx, isCreate
|
||||||
func (_m *Store) Connect(ctx context.Context, isCreate bool) (blob.Storage, error) {
|
func (_m *Store) Connect(ctx context.Context, isCreate bool, logger logrus.FieldLogger) (blob.Storage, error) {
|
||||||
ret := _m.Called(ctx, isCreate)
|
ret := _m.Called(ctx, isCreate)
|
||||||
|
|
||||||
var r0 blob.Storage
|
var r0 blob.Storage
|
||||||
|
@ -39,7 +40,7 @@ func (_m *Store) Connect(ctx context.Context, isCreate bool) (blob.Storage, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup provides a mock function with given fields: ctx, flags
|
// Setup provides a mock function with given fields: ctx, flags
|
||||||
func (_m *Store) Setup(ctx context.Context, flags map[string]string) error {
|
func (_m *Store) Setup(ctx context.Context, flags map[string]string, logger logrus.FieldLogger) error {
|
||||||
ret := _m.Called(ctx, flags)
|
ret := _m.Called(ctx, flags)
|
||||||
|
|
||||||
var r0 error
|
var r0 error
|
||||||
|
|
|
@ -19,6 +19,8 @@ package backend
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob"
|
"github.com/kopia/kopia/repo/blob"
|
||||||
"github.com/kopia/kopia/repo/blob/s3"
|
"github.com/kopia/kopia/repo/blob/s3"
|
||||||
|
|
||||||
|
@ -29,7 +31,7 @@ type S3Backend struct {
|
||||||
options s3.Options
|
options s3.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *S3Backend) Setup(ctx context.Context, flags map[string]string) error {
|
func (c *S3Backend) Setup(ctx context.Context, flags map[string]string, logger logrus.FieldLogger) error {
|
||||||
var err error
|
var err error
|
||||||
c.options.BucketName, err = mustHaveString(udmrepo.StoreOptionOssBucket, flags)
|
c.options.BucketName, err = mustHaveString(udmrepo.StoreOptionOssBucket, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,6 +53,6 @@ func (c *S3Backend) Setup(ctx context.Context, flags map[string]string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *S3Backend) Connect(ctx context.Context, isCreate bool) (blob.Storage, error) {
|
func (c *S3Backend) Connect(ctx context.Context, isCreate bool, logger logrus.FieldLogger) (blob.Storage, error) {
|
||||||
return s3.New(ctx, &c.options, false)
|
return s3.New(ctx, &c.options, false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo/blob/s3"
|
"github.com/kopia/kopia/repo/blob/s3"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
@ -115,11 +117,12 @@ func TestS3Setup(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger := velerotest.NewLogger()
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
s3Flags := S3Backend{}
|
s3Flags := S3Backend{}
|
||||||
|
|
||||||
err := s3Flags.Setup(context.Background(), tc.flags)
|
err := s3Flags.Setup(context.Background(), tc.flags, logger)
|
||||||
|
|
||||||
if tc.expectedErr == "" {
|
if tc.expectedErr == "" {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -96,13 +96,13 @@ func (ks *kopiaRepoService) Init(ctx context.Context, repoOption udmrepo.RepoOpt
|
||||||
repoCtx := kopia.SetupKopiaLog(ctx, ks.logger)
|
repoCtx := kopia.SetupKopiaLog(ctx, ks.logger)
|
||||||
|
|
||||||
if createNew {
|
if createNew {
|
||||||
if err := CreateBackupRepo(repoCtx, repoOption); err != nil {
|
if err := CreateBackupRepo(repoCtx, repoOption, ks.logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeInitParameters(repoCtx, repoOption, ks.logger)
|
return writeInitParameters(repoCtx, repoOption, ks.logger)
|
||||||
}
|
}
|
||||||
return ConnectBackupRepo(repoCtx, repoOption)
|
return ConnectBackupRepo(repoCtx, repoOption, ks.logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ks *kopiaRepoService) Open(ctx context.Context, repoOption udmrepo.RepoOptions) (udmrepo.BackupRepo, error) {
|
func (ks *kopiaRepoService) Open(ctx context.Context, repoOption udmrepo.RepoOptions) (udmrepo.BackupRepo, error) {
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/kopia/kopia/repo"
|
"github.com/kopia/kopia/repo"
|
||||||
"github.com/kopia/kopia/repo/blob"
|
"github.com/kopia/kopia/repo/blob"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -44,17 +46,17 @@ var backendStores = []kopiaBackendStore{
|
||||||
|
|
||||||
// CreateBackupRepo creates a Kopia repository and then connect to it.
|
// CreateBackupRepo creates a Kopia repository and then connect to it.
|
||||||
// The storage must be empty, otherwise, it will fail
|
// The storage must be empty, otherwise, it will fail
|
||||||
func CreateBackupRepo(ctx context.Context, repoOption udmrepo.RepoOptions) error {
|
func CreateBackupRepo(ctx context.Context, repoOption udmrepo.RepoOptions, logger logrus.FieldLogger) error {
|
||||||
if repoOption.ConfigFilePath == "" {
|
if repoOption.ConfigFilePath == "" {
|
||||||
return errors.New("invalid config file path")
|
return errors.New("invalid config file path")
|
||||||
}
|
}
|
||||||
|
|
||||||
backendStore, err := setupBackendStore(ctx, repoOption.StorageType, repoOption.StorageOptions)
|
backendStore, err := setupBackendStore(ctx, repoOption.StorageType, repoOption.StorageOptions, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error to setup backend storage")
|
return errors.Wrap(err, "error to setup backend storage")
|
||||||
}
|
}
|
||||||
|
|
||||||
st, err := backendStore.store.Connect(ctx, true)
|
st, err := backendStore.store.Connect(ctx, true, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error to connect to storage")
|
return errors.Wrap(err, "error to connect to storage")
|
||||||
}
|
}
|
||||||
|
@ -74,17 +76,17 @@ func CreateBackupRepo(ctx context.Context, repoOption udmrepo.RepoOptions) error
|
||||||
|
|
||||||
// ConnectBackupRepo connects to an existing Kopia repository.
|
// ConnectBackupRepo connects to an existing Kopia repository.
|
||||||
// If the repository doesn't exist, it will fail
|
// If the repository doesn't exist, it will fail
|
||||||
func ConnectBackupRepo(ctx context.Context, repoOption udmrepo.RepoOptions) error {
|
func ConnectBackupRepo(ctx context.Context, repoOption udmrepo.RepoOptions, logger logrus.FieldLogger) error {
|
||||||
if repoOption.ConfigFilePath == "" {
|
if repoOption.ConfigFilePath == "" {
|
||||||
return errors.New("invalid config file path")
|
return errors.New("invalid config file path")
|
||||||
}
|
}
|
||||||
|
|
||||||
backendStore, err := setupBackendStore(ctx, repoOption.StorageType, repoOption.StorageOptions)
|
backendStore, err := setupBackendStore(ctx, repoOption.StorageType, repoOption.StorageOptions, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error to setup backend storage")
|
return errors.Wrap(err, "error to setup backend storage")
|
||||||
}
|
}
|
||||||
|
|
||||||
st, err := backendStore.store.Connect(ctx, false)
|
st, err := backendStore.store.Connect(ctx, false, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error to connect to storage")
|
return errors.Wrap(err, "error to connect to storage")
|
||||||
}
|
}
|
||||||
|
@ -107,13 +109,13 @@ func findBackendStore(storage string) *kopiaBackendStore {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupBackendStore(ctx context.Context, storageType string, storageOptions map[string]string) (*kopiaBackendStore, error) {
|
func setupBackendStore(ctx context.Context, storageType string, storageOptions map[string]string, logger logrus.FieldLogger) (*kopiaBackendStore, error) {
|
||||||
backendStore := findBackendStore(storageType)
|
backendStore := findBackendStore(storageType)
|
||||||
if backendStore == nil {
|
if backendStore == nil {
|
||||||
return nil, errors.New("error to find storage type")
|
return nil, errors.New("error to find storage type")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := backendStore.store.Setup(ctx, storageOptions)
|
err := backendStore.store.Setup(ctx, storageOptions, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error to setup storage")
|
return nil, errors.Wrap(err, "error to setup storage")
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
|
@ -124,6 +126,7 @@ func TestCreateBackupRepo(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
logger := velerotest.NewLogger()
|
||||||
backendStores = []kopiaBackendStore{
|
backendStores = []kopiaBackendStore{
|
||||||
{udmrepo.StorageTypeAzure, "fake store", tc.backendStore},
|
{udmrepo.StorageTypeAzure, "fake store", tc.backendStore},
|
||||||
{udmrepo.StorageTypeFs, "fake store", tc.backendStore},
|
{udmrepo.StorageTypeFs, "fake store", tc.backendStore},
|
||||||
|
@ -141,7 +144,7 @@ func TestCreateBackupRepo(t *testing.T) {
|
||||||
tc.returnStore.On("GetBlob", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.getBlobErr)
|
tc.returnStore.On("GetBlob", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.getBlobErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := CreateBackupRepo(context.Background(), tc.repoOptions)
|
err := CreateBackupRepo(context.Background(), tc.repoOptions, logger)
|
||||||
|
|
||||||
if tc.expectedErr == "" {
|
if tc.expectedErr == "" {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -207,6 +210,7 @@ func TestConnectBackupRepo(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger := velerotest.NewLogger()
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
backendStores = []kopiaBackendStore{
|
backendStores = []kopiaBackendStore{
|
||||||
|
@ -225,7 +229,7 @@ func TestConnectBackupRepo(t *testing.T) {
|
||||||
tc.returnStore.On("GetBlob", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.getBlobErr)
|
tc.returnStore.On("GetBlob", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.getBlobErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := ConnectBackupRepo(context.Background(), tc.repoOptions)
|
err := ConnectBackupRepo(context.Background(), tc.repoOptions, logger)
|
||||||
|
|
||||||
if tc.expectedErr == "" {
|
if tc.expectedErr == "" {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in New Issue