Skip to content

Commit

Permalink
Moving kopia logging to remove kopia from indirect dependency in vele…
Browse files Browse the repository at this point in the history
…ro plugins

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 <[email protected]>
  • Loading branch information
kaovilai committed Jul 12, 2023
1 parent 49e8058 commit 0572287
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/6484-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Velero Plugins no longer need kopia indirect dependency in their go.mod
4 changes: 2 additions & 2 deletions pkg/util/logging/kopia_log.go → pkg/kopia/kopia_log.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package kopia

/*
Copyright the Velero contributors.
Expand All @@ -14,8 +16,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package logging

import (
"context"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package logging
package kopia

import (
"testing"
Expand Down
28 changes: 14 additions & 14 deletions pkg/repository/udmrepo/kopialib/lib_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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,
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/uploader/kopia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0572287

Please sign in to comment.