From 05722876b90c8a49a9e264aaa6d2f956188cab9a Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Tue, 11 Jul 2023 17:45:39 -0400 Subject: [PATCH] Moving kopia logging to remove kopia from indirect dependency in velero plugins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when running `go mod why -m github.com/kopia/kopia` in velero-plugins prior to this change you will see following ``` ❯ go mod why -m github.com/kopia/kopia github.com/konveyor/openshift-velero-plugin/velero-plugins github.com/vmware-tanzu/velero/pkg/plugin/framework github.com/vmware-tanzu/velero/pkg/util/logging github.com/kopia/kopia/repo/logging ``` after ``` ❯ go mod why -m github.com/kopia/kopia (main module does not need module github.com/kopia/kopia) ``` Signed-off-by: Tiger Kaovilai --- changelogs/unreleased/6484-kaovilai | 1 + pkg/{util/logging => kopia}/kopia_log.go | 4 +-- pkg/{util/logging => kopia}/kopia_log_test.go | 2 +- pkg/repository/udmrepo/kopialib/lib_repo.go | 28 +++++++++---------- pkg/uploader/kopia/snapshot.go | 6 ++-- 5 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 changelogs/unreleased/6484-kaovilai rename pkg/{util/logging => kopia}/kopia_log.go (99%) rename pkg/{util/logging => kopia}/kopia_log_test.go (99%) diff --git a/changelogs/unreleased/6484-kaovilai b/changelogs/unreleased/6484-kaovilai new file mode 100644 index 0000000000..764f43c6f4 --- /dev/null +++ b/changelogs/unreleased/6484-kaovilai @@ -0,0 +1 @@ +Velero Plugins no longer need kopia indirect dependency in their go.mod \ No newline at end of file diff --git a/pkg/util/logging/kopia_log.go b/pkg/kopia/kopia_log.go similarity index 99% rename from pkg/util/logging/kopia_log.go rename to pkg/kopia/kopia_log.go index 82dffc056d..ec08c81c0a 100644 --- a/pkg/util/logging/kopia_log.go +++ b/pkg/kopia/kopia_log.go @@ -1,3 +1,5 @@ +package kopia + /* Copyright the Velero contributors. @@ -14,8 +16,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -package logging - import ( "context" diff --git a/pkg/util/logging/kopia_log_test.go b/pkg/kopia/kopia_log_test.go similarity index 99% rename from pkg/util/logging/kopia_log_test.go rename to pkg/kopia/kopia_log_test.go index 848638c6d0..d50a4bba36 100644 --- a/pkg/util/logging/kopia_log_test.go +++ b/pkg/kopia/kopia_log_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package logging +package kopia import ( "testing" diff --git a/pkg/repository/udmrepo/kopialib/lib_repo.go b/pkg/repository/udmrepo/kopialib/lib_repo.go index 7802555fc7..a0a99d2b45 100644 --- a/pkg/repository/udmrepo/kopialib/lib_repo.go +++ b/pkg/repository/udmrepo/kopialib/lib_repo.go @@ -33,8 +33,8 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" + "github.com/vmware-tanzu/velero/pkg/kopia" "github.com/vmware-tanzu/velero/pkg/repository/udmrepo" - "github.com/vmware-tanzu/velero/pkg/util/logging" ) type kopiaRepoService struct { @@ -91,7 +91,7 @@ func NewKopiaRepoService(logger logrus.FieldLogger) udmrepo.BackupRepoService { } func (ks *kopiaRepoService) Init(ctx context.Context, repoOption udmrepo.RepoOptions, createNew bool) error { - repoCtx := logging.SetupKopiaLog(ctx, ks.logger) + repoCtx := kopia.SetupKopiaLog(ctx, ks.logger) if createNew { if err := CreateBackupRepo(repoCtx, repoOption); err != nil { @@ -113,7 +113,7 @@ func (ks *kopiaRepoService) Open(ctx context.Context, repoOption udmrepo.RepoOpt return nil, errors.Wrapf(err, "repo config %s doesn't exist", repoConfig) } - repoCtx := logging.SetupKopiaLog(ctx, ks.logger) + repoCtx := kopia.SetupKopiaLog(ctx, ks.logger) r, err := openKopiaRepo(repoCtx, repoConfig, repoOption.RepoPassword) if err != nil { @@ -156,7 +156,7 @@ func (ks *kopiaRepoService) Maintain(ctx context.Context, repoOption udmrepo.Rep return errors.Wrapf(err, "repo config %s doesn't exist", repoConfig) } - repoCtx := logging.SetupKopiaLog(ctx, ks.logger) + repoCtx := kopia.SetupKopiaLog(ctx, ks.logger) r, err := openKopiaRepo(repoCtx, repoConfig, repoOption.RepoPassword) if err != nil { @@ -206,7 +206,7 @@ func (ks *kopiaRepoService) DefaultMaintenanceFrequency() time.Duration { } func (km *kopiaMaintenance) runMaintenance(ctx context.Context, rep repo.DirectRepositoryWriter) error { - err := snapshotmaintenance.Run(logging.SetupKopiaLog(ctx, km.logger), rep, km.mode, false, maintenance.SafetyFull) + err := snapshotmaintenance.Run(kopia.SetupKopiaLog(ctx, km.logger), rep, km.mode, false, maintenance.SafetyFull) if err != nil { return errors.Wrapf(err, "error to run maintenance under mode %s", km.mode) } @@ -238,7 +238,7 @@ func (kr *kopiaRepository) OpenObject(ctx context.Context, id udmrepo.ID) (udmre return nil, errors.Wrapf(err, "error to parse object ID from %v", id) } - reader, err := kr.rawRepo.OpenObject(logging.SetupKopiaLog(ctx, kr.logger), objID) + reader, err := kr.rawRepo.OpenObject(kopia.SetupKopiaLog(ctx, kr.logger), objID) if err != nil { return nil, errors.Wrap(err, "error to open object") } @@ -253,7 +253,7 @@ func (kr *kopiaRepository) GetManifest(ctx context.Context, id udmrepo.ID, mani return errors.New("repo is closed or not open") } - metadata, err := kr.rawRepo.GetManifest(logging.SetupKopiaLog(ctx, kr.logger), manifest.ID(id), mani.Payload) + metadata, err := kr.rawRepo.GetManifest(kopia.SetupKopiaLog(ctx, kr.logger), manifest.ID(id), mani.Payload) if err != nil { return errors.Wrap(err, "error to get manifest") } @@ -268,7 +268,7 @@ func (kr *kopiaRepository) FindManifests(ctx context.Context, filter udmrepo.Man return nil, errors.New("repo is closed or not open") } - metadata, err := kr.rawRepo.FindManifests(logging.SetupKopiaLog(ctx, kr.logger), filter.Labels) + metadata, err := kr.rawRepo.FindManifests(kopia.SetupKopiaLog(ctx, kr.logger), filter.Labels) if err != nil { return nil, errors.Wrap(err, "error to find manifests") } @@ -286,7 +286,7 @@ func (kr *kopiaRepository) Time() time.Time { func (kr *kopiaRepository) Close(ctx context.Context) error { if kr.rawWriter != nil { - err := kr.rawWriter.Close(logging.SetupKopiaLog(ctx, kr.logger)) + err := kr.rawWriter.Close(kopia.SetupKopiaLog(ctx, kr.logger)) if err != nil { return errors.Wrap(err, "error to close repo writer") } @@ -295,7 +295,7 @@ func (kr *kopiaRepository) Close(ctx context.Context) error { } if kr.rawRepo != nil { - err := kr.rawRepo.Close(logging.SetupKopiaLog(ctx, kr.logger)) + err := kr.rawRepo.Close(kopia.SetupKopiaLog(ctx, kr.logger)) if err != nil { return errors.Wrap(err, "error to close repo") } @@ -311,7 +311,7 @@ func (kr *kopiaRepository) NewObjectWriter(ctx context.Context, opt udmrepo.Obje return nil } - writer := kr.rawWriter.NewObjectWriter(logging.SetupKopiaLog(ctx, kr.logger), object.WriterOptions{ + writer := kr.rawWriter.NewObjectWriter(kopia.SetupKopiaLog(ctx, kr.logger), object.WriterOptions{ Description: opt.Description, Prefix: index.IDPrefix(opt.Prefix), AsyncWrites: opt.AsyncWrites, @@ -332,7 +332,7 @@ func (kr *kopiaRepository) PutManifest(ctx context.Context, manifest udmrepo.Rep return "", errors.New("repo writer is closed or not open") } - id, err := kr.rawWriter.PutManifest(logging.SetupKopiaLog(ctx, kr.logger), manifest.Metadata.Labels, manifest.Payload) + id, err := kr.rawWriter.PutManifest(kopia.SetupKopiaLog(ctx, kr.logger), manifest.Metadata.Labels, manifest.Payload) if err != nil { return "", errors.Wrap(err, "error to put manifest") } @@ -345,7 +345,7 @@ func (kr *kopiaRepository) DeleteManifest(ctx context.Context, id udmrepo.ID) er return errors.New("repo writer is closed or not open") } - err := kr.rawWriter.DeleteManifest(logging.SetupKopiaLog(ctx, kr.logger), manifest.ID(id)) + err := kr.rawWriter.DeleteManifest(kopia.SetupKopiaLog(ctx, kr.logger), manifest.ID(id)) if err != nil { return errors.Wrap(err, "error to delete manifest") } @@ -358,7 +358,7 @@ func (kr *kopiaRepository) Flush(ctx context.Context) error { return errors.New("repo writer is closed or not open") } - err := kr.rawWriter.Flush(logging.SetupKopiaLog(ctx, kr.logger)) + err := kr.rawWriter.Flush(kopia.SetupKopiaLog(ctx, kr.logger)) if err != nil { return errors.Wrap(err, "error to flush repo") } diff --git a/pkg/uploader/kopia/snapshot.go b/pkg/uploader/kopia/snapshot.go index 033f304210..85000ad00b 100644 --- a/pkg/uploader/kopia/snapshot.go +++ b/pkg/uploader/kopia/snapshot.go @@ -28,9 +28,9 @@ import ( "github.com/sirupsen/logrus" + "github.com/vmware-tanzu/velero/pkg/kopia" "github.com/vmware-tanzu/velero/pkg/repository/udmrepo" "github.com/vmware-tanzu/velero/pkg/uploader" - "github.com/vmware-tanzu/velero/pkg/util/logging" "github.com/kopia/kopia/fs" "github.com/kopia/kopia/fs/localfs" @@ -121,7 +121,7 @@ func Backup(ctx context.Context, fsUploader SnapshotUploader, repoWriter repo.Re return nil, false, errors.Wrap(err, "Unable to get local filesystem entry") } - kopiaCtx := logging.SetupKopiaLog(ctx, log) + kopiaCtx := kopia.SetupKopiaLog(ctx, log) snapID, snapshotSize, err := SnapshotSource(kopiaCtx, repoWriter, fsUploader, sourceInfo, rootDir, forceFull, parentSnapshot, tags, log, "Kopia Uploader") if err != nil { return nil, false, err @@ -306,7 +306,7 @@ func findPreviousSnapshotManifest(ctx context.Context, rep repo.Repository, sour func Restore(ctx context.Context, rep repo.RepositoryWriter, progress *Progress, snapshotID, dest string, log logrus.FieldLogger, cancleCh chan struct{}) (int64, int32, error) { log.Info("Start to restore...") - kopiaCtx := logging.SetupKopiaLog(ctx, log) + kopiaCtx := kopia.SetupKopiaLog(ctx, log) snapshot, err := snapshot.LoadSnapshot(kopiaCtx, rep, manifest.ID(snapshotID)) if err != nil {