Skip to content

Commit

Permalink
Merge pull request #701 from joaopapereira/move-tag-mechanism-out-of-…
Browse files Browse the repository at this point in the history
…internal

Move tag mechanism out of internal
  • Loading branch information
joaopapereira authored Sep 23, 2024
2 parents b9cb2a8 + 04dc8e9 commit 484f01f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
7 changes: 4 additions & 3 deletions pkg/imgpkg/cmd/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

"carvel.dev/imgpkg/pkg/imgpkg/bundle"
"carvel.dev/imgpkg/pkg/imgpkg/image"
ctlimgset "carvel.dev/imgpkg/pkg/imgpkg/imageset"
"carvel.dev/imgpkg/pkg/imgpkg/internal/util"
"carvel.dev/imgpkg/pkg/imgpkg/lockconfig"
Expand Down Expand Up @@ -106,10 +107,10 @@ func (c *CopyOptions) Run() error {
levelLogger := util.NewUILevelLogger(util.LogWarn, prefixedLogger)
imagesUploaderLogger := util.NewProgressBar(levelLogger, "done uploading images", "Error uploading images")

var tagGen util.TagGenerator
tagGen = util.DefaultTagGenerator{}
var tagGen ctlimgset.TagGenerator
tagGen = image.DefaultTagGenerator{}
if c.UseRepoBasedTags {
tagGen = util.RepoBasedTagGenerator{}
tagGen = image.RepoBasedTagGenerator{}
}

imageSet := ctlimgset.NewImageSet(c.Concurrency, prefixedLogger, tagGen)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0

package util_test
package image_test

import (
"testing"

"carvel.dev/imgpkg/pkg/imgpkg/image"
"carvel.dev/imgpkg/pkg/imgpkg/imagedigest"
util "carvel.dev/imgpkg/pkg/imgpkg/internal/util"
regname "github.com/google/go-containerregistry/pkg/name"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestGenerateTagRepobasedgenerator(t *testing.T) {
digestWrap.DigestWrap(imgIdxRef, test.origRef)
importRepo, err := regname.NewRepository("import-registry/dst-repo")
require.NoError(t, err)
tagGen := util.RepoBasedTagGenerator{}
tagGen := image.RepoBasedTagGenerator{}
tag, err := tagGen.GenerateTag(digestWrap, importRepo)
require.NoError(t, err)
require.Equal(t, test.expectedTag, tag.TagStr())
Expand Down
7 changes: 1 addition & 6 deletions pkg/imgpkg/internal/util/tag.go → pkg/imgpkg/image/tag.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0

package util
package image

import (
"fmt"
Expand Down Expand Up @@ -32,11 +32,6 @@ func (t TagGenDigest) Digest() (regv1.Hash, error) {
}, nil
}

// TagGenerator interface
type TagGenerator interface {
GenerateTag(item imagedigest.DigestWrap, destinationRepo regname.Repository) (regname.Tag, error)
}

// DefaultTagGenerator implements GenerateTag
// and generates default tag
type DefaultTagGenerator struct{}
Expand Down
9 changes: 7 additions & 2 deletions pkg/imgpkg/imageset/image_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ type Logger interface {
Logf(str string, args ...interface{})
}

// TagGenerator interface
type TagGenerator interface {
GenerateTag(item imagedigest.DigestWrap, destinationRepo regname.Repository) (regname.Tag, error)
}

type ImageSet struct {
concurrency int
logger Logger
tagGen util.TagGenerator
tagGen TagGenerator
}

// NewImageSet constructor for creating an ImageSet
func NewImageSet(concurrency int, logger Logger, tagGen util.TagGenerator) ImageSet {
func NewImageSet(concurrency int, logger Logger, tagGen TagGenerator) ImageSet {
return ImageSet{concurrency, logger, tagGen}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/imgpkg/plainimage/contents.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"

ctlimg "carvel.dev/imgpkg/pkg/imgpkg/image"
"carvel.dev/imgpkg/pkg/imgpkg/internal/util"
regname "github.com/google/go-containerregistry/pkg/name"
regv1 "github.com/google/go-containerregistry/pkg/v1"
regremote "github.com/google/go-containerregistry/pkg/v1/remote"
Expand Down Expand Up @@ -61,7 +60,7 @@ func (i Contents) Push(uploadRef regname.Tag, labels map[string]string, writer I
return "", err
}

uploadTagRef, err := util.BuildDefaultUploadTagRef(img, uploadRef.Repository)
uploadTagRef, err := ctlimg.BuildDefaultUploadTagRef(img, uploadRef.Repository)
if err != nil {
return "", fmt.Errorf("Building default upload tag image ref: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/imgpkg/v1/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var stdOut *bytes.Buffer
func testSetup(registryBuild *helpers.FakeTestRegistryBuilder, imageName string, bundleName string, tarPath string, lockfilePath string) (v1.CopyOrigin, v1.CopyOpts, registry.Registry) {
stdOut = bytes.NewBufferString("")
uiLogger := util.NewUILevelLogger(util.LogWarn, util.NewBufferLogger(stdOut))
tagGen := util.DefaultTagGenerator{}
tagGen := ctlimg.DefaultTagGenerator{}
imageSet := imageset.NewImageSet(1, uiLogger, tagGen)

opts := v1.CopyOpts{
Expand Down

0 comments on commit 484f01f

Please sign in to comment.