Skip to content

Commit

Permalink
fix: save container name (#5931)
Browse files Browse the repository at this point in the history
* fix: save container nname

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: optional id message

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: save config

Signed-off-by: Vladislav Sukhin <[email protected]>

---------

Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin authored Oct 14, 2024
1 parent 5d3302f commit e5e3df8
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 19 deletions.
11 changes: 8 additions & 3 deletions cmd/kubectl-testkube/commands/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func CreateVariables(cmd *cobra.Command, ignoreSecretVariable bool) (vars map[st
return
}

func PopulateMasterFlags(cmd *cobra.Command, opts *HelmOptions) {
func PopulateMasterFlags(cmd *cobra.Command, opts *HelmOptions, optionalIds bool) {
var (
apiURIPrefix, uiURIPrefix, agentURIPrefix, cloudRootDomain, proRootDomain string
insecure bool
Expand Down Expand Up @@ -88,8 +88,13 @@ func PopulateMasterFlags(cmd *cobra.Command, opts *HelmOptions) {
cmd.Flags().StringVar(&opts.Master.URIs.Agent, "agent-uri", "", "Testkube Pro agent URI [required for centralized mode]")
cmd.Flags().StringVar(&opts.Master.URIs.Logs, "logs-uri", "", "Testkube Pro logs URI [required for centralized mode]")
cmd.Flags().StringVar(&opts.Master.AgentToken, "agent-token", "", "Testkube Pro agent key [required for centralized mode]")
cmd.Flags().StringVar(&opts.Master.OrgId, "org-id", "", "Testkube Pro organization id [required for centralized mode]")
cmd.Flags().StringVar(&opts.Master.EnvId, "env-id", "", "Testkube Pro environment id [required for centralized mode]")
neededForLogin := ""
if optionalIds {
neededForLogin = ". It can be skipped for no login mode"
}

cmd.Flags().StringVar(&opts.Master.OrgId, "org-id", "", "Testkube Pro organization id [required for centralized mode]"+neededForLogin)
cmd.Flags().StringVar(&opts.Master.EnvId, "env-id", "", "Testkube Pro environment id [required for centralized mode]"+neededForLogin)

cmd.Flags().BoolVar(&opts.Master.Features.LogsV2, "feature-logs-v2", false, "Logs v2 feature flag")
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/kubectl-testkube/commands/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,17 @@ func PopulateOrgAndEnvNames(cfg config.Data, orgId, envId, apiUrl string) (confi
return cfg, nil
}

func PopulateCloudConfig(cfg config.Data, apiKey string, opts *HelmOptions) config.Data {
func PopulateCloudConfig(cfg config.Data, apiKey string, dockerContainerName *string, opts *HelmOptions) config.Data {
if apiKey != "" {
cfg.CloudContext.ApiKey = apiKey
}

cfg.CloudContext.ApiUri = opts.Master.URIs.Api
cfg.CloudContext.UiUri = opts.Master.URIs.Ui
cfg.CloudContext.AgentUri = opts.Master.URIs.Agent
if dockerContainerName != nil {
cfg.CloudContext.DockerContainerName = *dockerContainerName
}

return cfg
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/common/masterFlags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewTestCmd() *cobra.Command {
},
}

PopulateMasterFlags(cmd, &opts)
PopulateMasterFlags(cmd, &opts, false)
PopulateHelmFlags(cmd, &opts)
return cmd
}
Expand Down
19 changes: 13 additions & 6 deletions cmd/kubectl-testkube/commands/context/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (

func NewSetContextCmd() *cobra.Command {
var (
org, env, apiKey string
kubeconfig bool
namespace string
opts common.HelmOptions
org, env, apiKey string
kubeconfig bool
namespace string
opts common.HelmOptions
dockerContainerName string
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -46,7 +47,12 @@ func NewSetContextCmd() *cobra.Command {
ui.Errf("Please provide at least one of the following flags: --org-id, --env-id, --api-key, --root-domain")
}

cfg = common.PopulateCloudConfig(cfg, apiKey, &opts)
var dcName *string
if cmd.Flags().Changed("docker-container") {
dcName = &dockerContainerName
}

cfg = common.PopulateCloudConfig(cfg, apiKey, dcName, &opts)

if cfg.CloudContext.ApiKey != "" {
var err error
Expand Down Expand Up @@ -96,7 +102,8 @@ func NewSetContextCmd() *cobra.Command {
cmd.Flags().String("ui-uri-override", "", "ui uri override")
cmd.Flags().String("agent-uri-override", "", "agnet uri override")
cmd.Flags().String("logs-uri-override", "", "logs service uri override")
cmd.Flags().StringVar(&dockerContainerName, "docker-container", "testkube-agent", "Docker container name for Testkube Docker Agent")

common.PopulateMasterFlags(cmd, &opts)
common.PopulateMasterFlags(cmd, &opts, false)
return cmd
}
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func NewInitCmdStandalone() *cobra.Command {

cmd.Flags().BoolVarP(&export, "export", "", false, "Export the values.yaml")
common.PopulateHelmFlags(cmd, &options)
common.PopulateMasterFlags(cmd, &options)
common.PopulateMasterFlags(cmd, &options, false)

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/pro/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func NewConnectCmd() *cobra.Command {
}

common.PopulateHelmFlags(cmd, &opts)
common.PopulateMasterFlags(cmd, &opts)
common.PopulateMasterFlags(cmd, &opts, false)

cmd.Flags().IntVar(&opts.MinioReplicas, "minio-replicas", 0, "MinIO replicas")
cmd.Flags().IntVar(&opts.MongoReplicas, "mongo-replicas", 0, "MongoDB replicas")
Expand Down
8 changes: 6 additions & 2 deletions cmd/kubectl-testkube/commands/pro/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ func NewDockerCmd() *cobra.Command {

if noLogin {
ui.Alert("Saving Testkube CLI Pro context, you need to authorize CLI through `testkube set context` later")
common.PopulateCloudConfig(cfg, "", &options)
cfg = common.PopulateCloudConfig(cfg, "", &dockerContainerName, &options)

err = config.Save(cfg)
ui.ExitOnError("saving config file", err)

ui.Info(" Happy Testing! 🚀")
ui.NL()
return
Expand All @@ -125,7 +129,7 @@ func NewDockerCmd() *cobra.Command {
},
}

common.PopulateMasterFlags(cmd, &options)
common.PopulateMasterFlags(cmd, &options, true)

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")
Expand Down
9 changes: 7 additions & 2 deletions cmd/kubectl-testkube/commands/pro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
commonint "github.com/kubeshop/testkube/internal/common"
"github.com/kubeshop/testkube/pkg/telemetry"
"github.com/kubeshop/testkube/pkg/ui"
)
Expand Down Expand Up @@ -84,7 +85,11 @@ func NewInitCmd() *cobra.Command {

if noLogin {
ui.Alert("Saving Testkube CLI Pro context, you need to authorize CLI through `testkube set context` later")
common.PopulateCloudConfig(cfg, "", &options)
cfg = common.PopulateCloudConfig(cfg, "", commonint.Ptr(""), &options)

err = config.Save(cfg)
ui.ExitOnError("saving config file", err)

ui.Info(" Happy Testing! 🚀")
ui.NL()
return
Expand All @@ -108,7 +113,7 @@ func NewInitCmd() *cobra.Command {
}

common.PopulateHelmFlags(cmd, &options)
common.PopulateMasterFlags(cmd, &options)
common.PopulateMasterFlags(cmd, &options, false)

cmd.Flags().BoolVarP(&noLogin, "no-login", "", false, "Ignore login prompt, set existing token later by `testkube set context`")
cmd.Flags().BoolVarP(&export, "export", "", false, "Export the values.yaml")
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/pro/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewLoginCmd() *cobra.Command {
},
}

common.PopulateMasterFlags(cmd, &opts)
common.PopulateMasterFlags(cmd, &opts, false)

return cmd
}
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewUpgradeCmd() *cobra.Command {
}

common.PopulateHelmFlags(cmd, &options)
common.PopulateMasterFlags(cmd, &options)
common.PopulateMasterFlags(cmd, &options, false)

cmd.Flags().StringVar(&dockerContainerName, "docker-container", "testkube-agent", "Docker container name for Testkube Docker Agent")

Expand Down

0 comments on commit e5e3df8

Please sign in to comment.