github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/debug/info.go (about) 1 package debug 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/spf13/cobra" 8 9 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" 10 "github.com/kubeshop/testkube/pkg/api/v1/client" 11 "github.com/kubeshop/testkube/pkg/api/v1/testkube" 12 "github.com/kubeshop/testkube/pkg/ui" 13 ) 14 15 // NewShowDebugInfoCmd creates a new cobra command to print the debug info to the CLI 16 func NewShowDebugInfoCmd() *cobra.Command { 17 return &cobra.Command{ 18 Use: "info", 19 Short: "Show debug info", 20 Long: "Get all the necessary information to debug an issue in Testkube", 21 Run: func(cmd *cobra.Command, args []string) { 22 client, _, err := common.GetClient(cmd) 23 ui.ExitOnError("getting client", err) 24 25 debug, err := GetDebugInfo(client) 26 ui.ExitOnError("get debug info", err) 27 28 PrintDebugInfo(debug) 29 }, 30 } 31 } 32 33 // GetDebugInfo returns information on the current Testkube environment 34 func GetDebugInfo(apiClient client.Client) (testkube.DebugInfo, error) { 35 debug, err := apiClient.GetDebugInfo() 36 if err != nil { 37 return testkube.DebugInfo{}, err 38 } 39 40 info, err := apiClient.GetServerInfo() 41 if err != nil { 42 return testkube.DebugInfo{}, err 43 } 44 45 debug.ClientVersion = common.Version 46 debug.ServerVersion = info.Version 47 48 return debug, nil 49 } 50 51 // PrintDebugInfo prints the debugging data to the CLI 52 func PrintDebugInfo(info testkube.DebugInfo) { 53 ui.Table(info, os.Stdout) 54 ui.NL() 55 56 ui.Info("API LOGS") 57 ui.NL() 58 for _, l := range info.ApiLogs { 59 ui.Info(l) 60 } 61 ui.NL() 62 63 ui.Info("OPERATOR LOGS") 64 ui.NL() 65 for _, l := range info.OperatorLogs { 66 ui.Info(l) 67 } 68 ui.NL() 69 70 ui.Info("EXECUTION LOGS") 71 ui.NL() 72 for id, logs := range info.ExecutionLogs { 73 ui.Info(fmt.Sprintf("EXECUTION ID: %s", id)) 74 ui.NL() 75 for _, l := range logs { 76 ui.Info(l) 77 } 78 ui.NL() 79 } 80 ui.NL() 81 }