Skip to content

Commit

Permalink
fix: avoid checking for latest release on GitHub with every CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 committed Nov 12, 2024
1 parent 8b26e37 commit a5d9f58
Showing 1 changed file with 12 additions and 8 deletions.
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

0 comments on commit a5d9f58

Please sign in to comment.