diff --git a/cli/pkg/kctrl/cmd/package/repository/release/release.go b/cli/pkg/kctrl/cmd/package/repository/release/release.go index 646e9b16e..ff74460d3 100644 --- a/cli/pkg/kctrl/cmd/package/repository/release/release.go +++ b/cli/pkg/kctrl/cmd/package/repository/release/release.go @@ -27,6 +27,7 @@ type ReleaseOptions struct { chdir string outputLocation string debug bool + tag string } const ( @@ -58,6 +59,7 @@ func NewReleaseCmd(o *ReleaseOptions) *cobra.Command { cmd.Flags().StringVar(&o.chdir, "chdir", "", "Location of the working directory") cmd.Flags().StringVar(&o.outputLocation, "copy-to", "", "Output location for pkgrepo-build.yml") cmd.Flags().BoolVar(&o.debug, "debug", false, "Include debug output") + cmd.Flags().StringVarP(&o.tag, "tag", "t", "", "Tag pushed with imgpkg bundle (default build-)") return cmd } @@ -157,10 +159,15 @@ func (o *ReleaseOptions) Run() error { var bundleURL string + tag := o.pkgRepoVersion + if o.tag != "" { + tag = o.tag + } + switch { case pkgRepoBuild.Spec.Export.ImgpkgBundle != nil: imgpkgRunner := ImgpkgRunner{ - BundlePath: fmt.Sprintf("%s:%s", pkgRepoBuild.Spec.Export.ImgpkgBundle.Image, o.pkgRepoVersion), + BundlePath: fmt.Sprintf("%s:%s", pkgRepoBuild.Spec.Export.ImgpkgBundle.Image, tag), Paths: []string{"packages"}, UseKbldImagesLock: true, ImgLockFilepath: tempImgpkgLockPath, diff --git a/cli/test/e2e/package_repo_release_test.go b/cli/test/e2e/package_repo_release_test.go index 22efae972..bb0fdfc65 100644 --- a/cli/test/e2e/package_repo_release_test.go +++ b/cli/test/e2e/package_repo_release_test.go @@ -4,6 +4,7 @@ import ( "fmt" "io/fs" "os" + "os/exec" "path/filepath" "strings" "testing" @@ -49,13 +50,45 @@ func TestPackageRepositoryReleaseInteractively(t *testing.T) { promptOutput.Write(env.Image) }() - kctrl.RunWithOpts([]string{"pkg", "repo", "release", "--tty=true", "--chdir", workingDir, "--version", "1.0.0"}, + version := "1.0.0" + kctrl.RunWithOpts([]string{"pkg", "repo", "release", "--tty=true", "--chdir", workingDir, "--version", version}, RunOpts{NoNamespace: true, StdinReader: promptOutput.StringReader(), StdoutWriter: promptOutput.BufferedOutputWriter(), Interactive: true}) keysToBeIgnored := []string{"creationTimestamp:", "image"} verifyPackageRepoBuild(t, keysToBeIgnored) verifyPackageRepository(t, keysToBeIgnored) + + args := []string{"tag", "list", "-i", os.Getenv("KCTRL_E2E_IMAGE")} + cmd := exec.Command("imgpkg", args...) + output, err := cmd.Output() + require.Contains(t, string(output), version) + require.NoError(t, err, "There was an error in listing the tags") + }) + + logger.Section("Creating a package repository interactively with tags using pkg repo release", func() { + go func() { + promptOutput.WaitFor("Enter the package repository name") + promptOutput.Write(pkgrName) + promptOutput.WaitFor("Enter the registry url") + promptOutput.Write(env.Image) + }() + + version := "1.0.0" + tag := "build-tag-0001" + kctrl.RunWithOpts([]string{"pkg", "repo", "release", "--tty=true", "--chdir", workingDir, "--version", version, "--tag", tag}, + RunOpts{NoNamespace: true, StdinReader: promptOutput.StringReader(), + StdoutWriter: promptOutput.BufferedOutputWriter(), Interactive: true}) + + keysToBeIgnored := []string{"creationTimestamp:", "image"} + verifyPackageRepoBuild(t, keysToBeIgnored) + verifyPackageRepository(t, keysToBeIgnored) + + args := []string{"tag", "list", "-i", os.Getenv("KCTRL_E2E_IMAGE")} + cmd := exec.Command("imgpkg", args...) + output, err := cmd.Output() + require.Contains(t, string(output), tag) + require.NoError(t, err, "There was an error in listing the tags") }) logger.Section(fmt.Sprintf("Installing package repository"), func() {