Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tag cli args for pkg repo release #1664

Merged
merged 4 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
praveenrewar marked this conversation as resolved.
Show resolved Hide resolved
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
Loading