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

fix: avoid checking for latest release on GitHub with every CLI command #6019

Merged
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
20 changes: 12 additions & 8 deletions cmd/kubectl-testkube/commands/docker/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"strings"

"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand All @@ -14,18 +15,15 @@ import (
"github.com/kubeshop/testkube/pkg/ui"
)

const (
StableReleasePlaceholder = "<latest-stable-release>"
)

func NewInitCmd() *cobra.Command {
var noLogin bool // ignore ask for login
var dockerContainerName, dockerImage string
var options common.HelmOptions

latestVersion, err := common.GetLatestVersion()
ui.ExitOnError("Gettong latest version", err)

if latestVersion != "" {
latestVersion = ":" + latestVersion
}

cmd := &cobra.Command{
Use: "init",
Short: "Run Testkube Docker Agent and connect to Testkube Pro environment",
Expand All @@ -34,6 +32,12 @@ func NewInitCmd() *cobra.Command {
ui.Info("WELCOME TO")
ui.Logo()

if strings.Contains(dockerImage, StableReleasePlaceholder) {
latestVersion, err := common.GetLatestVersion()
ui.ExitOnError("Getting latest version", err)
dockerImage = strings.ReplaceAll(dockerImage, StableReleasePlaceholder, latestVersion)
}

cfg, err := config.Load()
if err != nil {
cliErr := common.NewCLIError(
Expand Down Expand Up @@ -135,7 +139,7 @@ func NewInitCmd() *cobra.Command {

cmd.Flags().BoolVarP(&noLogin, "no-login", "", false, "Ignore login prompt, set existing token later by `testkube set context`")
cmd.Flags().StringVar(&dockerContainerName, "docker-container", "testkube-agent", "Docker container name for Testkube Docker Agent")
cmd.Flags().StringVar(&dockerImage, "docker-image", "kubeshop/testkube-agent"+latestVersion, "Docker image for Testkube Docker Agent")
cmd.Flags().StringVar(&dockerImage, "docker-image", "kubeshop/testkube-agent:"+StableReleasePlaceholder, "Docker image for Testkube Docker Agent")

return cmd
}
Expand Down
Loading