github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/debug.go (about) 1 package commands 2 3 import ( 4 "github.com/spf13/cobra" 5 6 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" 7 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/validator" 8 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/debug" 9 "github.com/kubeshop/testkube/cmd/kubectl-testkube/config" 10 "github.com/kubeshop/testkube/pkg/ui" 11 ) 12 13 // NewDebugCmd creates the 'testkube debug' command 14 func NewDebugCmd() *cobra.Command { 15 cmd := &cobra.Command{ 16 Use: "debug", 17 Short: "Print environment information for debugging", 18 Run: func(cmd *cobra.Command, args []string) { 19 20 cfg, err := config.Load() 21 ui.ExitOnError("loading config file", err) 22 23 if cfg.ContextType == config.ContextTypeCloud { 24 cfg, err := config.Load() 25 ui.ExitOnError("loading config file", err) 26 ui.NL() 27 28 if cfg.ContextType != config.ContextTypeCloud { 29 ui.Errf("Agent debug is only available for cloud context") 30 ui.NL() 31 ui.ShellCommand("Please try command below to set your context into Cloud mode", `testkube set context -o <org> -e <env> -k <api-key> `) 32 ui.NL() 33 return 34 } 35 36 common.UiPrintContext(cfg) 37 38 client, _, err := common.GetClient(cmd) 39 ui.ExitOnError("getting client", err) 40 41 i, err := client.GetServerInfo() 42 if err != nil { 43 ui.Errf("Error %v", err) 44 ui.NL() 45 ui.Info("Possible reasons:") 46 ui.Warn("- Please check if your agent organization and environment are set correctly") 47 ui.Warn("- Please check if your API token is set correctly") 48 ui.NL() 49 } else { 50 ui.Warn("Agent correctly connected to cloud:\n") 51 ui.InfoGrid(map[string]string{ 52 "Agent version ": i.Version, 53 "Agent namespace": i.Namespace, 54 }) 55 } 56 ui.NL() 57 } else { 58 client, _, err := common.GetClient(cmd) 59 ui.ExitOnError("getting client", err) 60 61 d, err := debug.GetDebugInfo(client) 62 ui.ExitOnError("get debug info", err) 63 64 debug.PrintDebugInfo(d) 65 66 } 67 }, 68 PersistentPreRun: func(cmd *cobra.Command, args []string) { 69 cfg, err := config.Load() 70 ui.ExitOnError("loading config", err) 71 common.UiContextHeader(cmd, cfg) 72 73 validator.PersistentPreRunVersionCheck(cmd, common.Version) 74 }} 75 76 cmd.AddCommand(debug.NewShowDebugInfoCmd()) 77 78 return cmd 79 }