github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/tests/watch.go (about) 1 package tests 2 3 import ( 4 "os" 5 6 "github.com/spf13/cobra" 7 8 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" 9 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/validator" 10 "github.com/kubeshop/testkube/pkg/ui" 11 ) 12 13 func NewWatchExecutionCmd() *cobra.Command { 14 return &cobra.Command{ 15 Use: "execution <executionName>", 16 Aliases: []string{"e", "executions"}, 17 Short: "Watch logs output from executor pod", 18 Long: `Gets test execution details, until it's in success/error state, blocks until gets complete state`, 19 Args: validator.ExecutionName, 20 Run: func(cmd *cobra.Command, args []string) { 21 client, _, err := common.GetClient(cmd) 22 ui.ExitOnError("getting client", err) 23 24 executionID := args[0] 25 execution, err := client.GetExecution(executionID) 26 ui.ExitOnError("get execution failed", err) 27 28 if execution.ExecutionResult.IsCompleted() { 29 ui.Completed("execution is already finished") 30 } else { 31 info, err := client.GetServerInfo() 32 ui.ExitOnError("getting server info", err) 33 34 if info.Features != nil && info.Features.LogsV2 { 35 err = watchLogsV2(execution.Id, false, client) 36 } else { 37 err = watchLogs(execution.Id, false, client) 38 } 39 40 ui.NL() 41 uiShellGetExecution(execution.Id) 42 if err != nil { 43 os.Exit(1) 44 } 45 46 } 47 48 }, 49 } 50 }