Skip to content

Commit

Permalink
Add tag cli args for pkg repo release (#1664)
Browse files Browse the repository at this point in the history
* Add tag cli args for pkgr release

Signed-off-by: Devanshu <[email protected]>

* Add e2e test case for repo release with tag

Signed-off-by: Devanshu <[email protected]>

---------

Signed-off-by: Devanshu <[email protected]>
  • Loading branch information
devanshuVmware authored Dec 25, 2024
1 parent cfe66c0 commit a1c5d04
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cli/pkg/kctrl/cmd/package/repository/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ReleaseOptions struct {
chdir string
outputLocation string
debug bool
tag string
}

const (
Expand Down Expand Up @@ -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-<TIMESTAMP>)")

return cmd
}
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 34 additions & 1 deletion cli/test/e2e/package_repo_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a1c5d04

Please sign in to comment.