From 60e75a96878730b818f045fa951d30e650bf7c04 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 17 Oct 2024 14:19:47 +0300 Subject: [PATCH 1/3] fix: move docer command Signed-off-by: Vladislav Sukhin --- cmd/kubectl-testkube/commands/docker.go | 21 +++++++++++ .../{pro/docker.go => docker/init.go} | 35 ++++++++++++++++--- cmd/kubectl-testkube/commands/pro.go | 1 - cmd/kubectl-testkube/commands/root.go | 1 + 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 cmd/kubectl-testkube/commands/docker.go rename cmd/kubectl-testkube/commands/{pro/docker.go => docker/init.go} (79%) diff --git a/cmd/kubectl-testkube/commands/docker.go b/cmd/kubectl-testkube/commands/docker.go new file mode 100644 index 00000000000..b424e496b73 --- /dev/null +++ b/cmd/kubectl-testkube/commands/docker.go @@ -0,0 +1,21 @@ +package commands + +import ( + "github.com/spf13/cobra" + + "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/docker" +) + +func NewDockerCmd() *cobra.Command { + + cmd := &cobra.Command{ + Use: "docker", + Short: "Testkube Docker commands", + Run: func(cmd *cobra.Command, args []string) { + }, + } + + cmd.AddCommand(docker.NewInitCmd()) + + return cmd +} diff --git a/cmd/kubectl-testkube/commands/pro/docker.go b/cmd/kubectl-testkube/commands/docker/init.go similarity index 79% rename from cmd/kubectl-testkube/commands/pro/docker.go rename to cmd/kubectl-testkube/commands/docker/init.go index 49f8e1b8b5a..892927f0d5a 100644 --- a/cmd/kubectl-testkube/commands/pro/docker.go +++ b/cmd/kubectl-testkube/commands/docker/init.go @@ -1,7 +1,8 @@ -package pro +package docker import ( "errors" + "fmt" "os" "github.com/pterm/pterm" @@ -9,10 +10,11 @@ import ( "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" "github.com/kubeshop/testkube/cmd/kubectl-testkube/config" + "github.com/kubeshop/testkube/pkg/telemetry" "github.com/kubeshop/testkube/pkg/ui" ) -func NewDockerCmd() *cobra.Command { +func NewInitCmd() *cobra.Command { var noLogin bool // ignore ask for login var dockerContainerName, dockerImage string var options common.HelmOptions @@ -25,9 +27,9 @@ func NewDockerCmd() *cobra.Command { } cmd := &cobra.Command{ - Use: "docker", + Use: "init", Short: "Run Testkube Docker Agent and connect to Testkube Pro environment", - Aliases: []string{"da", "docker-agent"}, + Aliases: []string{"install", "agent"}, Run: func(cmd *cobra.Command, args []string) { ui.Info("WELCOME TO") ui.Logo() @@ -137,3 +139,28 @@ func NewDockerCmd() *cobra.Command { return cmd } + +func sendErrTelemetry(cmd *cobra.Command, clientCfg config.Data, errType string, errorLogs error) { + var errorStackTrace string + errorStackTrace = fmt.Sprintf("%+v", errorLogs) + if clientCfg.TelemetryEnabled { + ui.Debug("collecting anonymous telemetry data, you can disable it by calling `kubectl testkube disable telemetry`") + out, err := telemetry.SendCmdErrorEvent(cmd, common.Version, errType, errorStackTrace) + if ui.Verbose && err != nil { + ui.Err(err) + } + + ui.Debug("telemetry send event response", out) + } +} + +func sendAttemptTelemetry(cmd *cobra.Command, clientCfg config.Data) { + if clientCfg.TelemetryEnabled { + ui.Debug("collecting anonymous telemetry data, you can disable it by calling `kubectl testkube disable telemetry`") + out, err := telemetry.SendCmdAttemptEvent(cmd, common.Version) + if ui.Verbose && err != nil { + ui.Err(err) + } + ui.Debug("telemetry send event response", out) + } +} diff --git a/cmd/kubectl-testkube/commands/pro.go b/cmd/kubectl-testkube/commands/pro.go index 4fae70e3bc4..09986b4c757 100644 --- a/cmd/kubectl-testkube/commands/pro.go +++ b/cmd/kubectl-testkube/commands/pro.go @@ -19,7 +19,6 @@ func NewProCmd() *cobra.Command { cmd.AddCommand(pro.NewDisconnectCmd()) cmd.AddCommand(pro.NewInitCmd()) cmd.AddCommand(pro.NewLoginCmd()) - cmd.AddCommand(pro.NewDockerCmd()) return cmd } diff --git a/cmd/kubectl-testkube/commands/root.go b/cmd/kubectl-testkube/commands/root.go index 464f6657f65..9e3bc877185 100644 --- a/cmd/kubectl-testkube/commands/root.go +++ b/cmd/kubectl-testkube/commands/root.go @@ -62,6 +62,7 @@ func init() { RootCmd.AddCommand(NewAgentCmd()) RootCmd.AddCommand(NewCloudCmd()) RootCmd.AddCommand(NewProCmd()) + RootCmd.AddCommand(NewDockerCmd()) RootCmd.AddCommand(pro.NewLoginCmd()) RootCmd.SetHelpCommand(NewHelpCmd()) From 569a11e5c72074a747e2eebf208cf73c832aa6d9 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 17 Oct 2024 14:50:23 +0300 Subject: [PATCH 2/3] fix: remove unsued settings Signed-off-by: Vladislav Sukhin --- cmd/kubectl-testkube/commands/common/helper.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/kubectl-testkube/commands/common/helper.go b/cmd/kubectl-testkube/commands/common/helper.go index 3ce2daa823d..1b2260322b5 100644 --- a/cmd/kubectl-testkube/commands/common/helper.go +++ b/cmd/kubectl-testkube/commands/common/helper.go @@ -845,8 +845,6 @@ func prepareTestkubeUpgradeDockerArgs(options HelmOptions, dockerContainerName, "--set", "mongodb.enabled=false", "--set", - "testkube-dashboard.enabled=false", - "--set", "testkube-api.cloud.key=" + options.Master.AgentToken, "--set", "testkube-api.cloud.url=" + options.Master.URIs.Agent, From a67c66d5a37af9ef105c4c689be74adf96e0936d Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Thu, 17 Oct 2024 16:01:15 +0300 Subject: [PATCH 3/3] fix: show help Signed-off-by: Vladislav Sukhin --- cmd/kubectl-testkube/commands/docker.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/kubectl-testkube/commands/docker.go b/cmd/kubectl-testkube/commands/docker.go index b424e496b73..fab1d9b8cd2 100644 --- a/cmd/kubectl-testkube/commands/docker.go +++ b/cmd/kubectl-testkube/commands/docker.go @@ -4,6 +4,7 @@ import ( "github.com/spf13/cobra" "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/docker" + "github.com/kubeshop/testkube/pkg/ui" ) func NewDockerCmd() *cobra.Command { @@ -12,6 +13,8 @@ func NewDockerCmd() *cobra.Command { Use: "docker", Short: "Testkube Docker commands", Run: func(cmd *cobra.Command, args []string) { + err := cmd.Help() + ui.PrintOnError("Displaying help", err) }, }