Skip to content

Commit

Permalink
fix: better error messages and failed execution info (#877)
Browse files Browse the repository at this point in the history
* fix: better error messages and failed execution info

* fix: consisten case in messages

* fix: better logs

* fix: double import

* fix: renamed import package aliases to make more constistent
  • Loading branch information
exu authored Jan 26, 2022
1 parent fd82824 commit 0fd321a
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 120 deletions.
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/scripts/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func watchLogs(id string, client client.Client) {
if execution.ExecutionResult.IsCompleted() {
fmt.Println()

uiShellCommandBlock(id)
uiShellGetExecution(id)

return
}
}

uiShellCommandBlock(id)
uiShellGetExecution(id)
}
15 changes: 8 additions & 7 deletions cmd/kubectl-testkube/commands/scripts/execution_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"text/template"

"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/ui"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -77,14 +78,14 @@ func (r ExecutionRawRenderer) Watch(execution testkube.Execution, writer io.Writ
return err
}

// TODO fix this - introduce some common data interface for rendering such objects
// renderers need to be simplified and render Execution should be in one place (not many as now)
// - move all logic from execution, start, watch here to show final execution
func (r ExecutionRawRenderer) renderDetails(execution testkube.Execution, writer io.Writer) error {
_, err := fmt.Fprintf(writer, "Name: %s, Status: %s, Duration: %s\n",
execution.Name,
*execution.ExecutionResult.Status,
execution.CalculateDuration(),
)

return err
ui.Writer = writer
uiPrintStatus(execution)
uiShellGetExecution(execution.Id)
return nil
}

func GetExecutionRenderer(cmd *cobra.Command) ExecutionRenderer {
Expand Down
19 changes: 14 additions & 5 deletions cmd/kubectl-testkube/commands/scripts/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func NewStartScriptCmd() *cobra.Command {
DownloadArtifacts(execution.Id, downloadDir, client)
}

uiShellCommandBlock(execution.Id)
uiShellGetExecution(execution.Id)
uiShellWatchExecution(execution.Id)
},
}

Expand All @@ -71,6 +72,8 @@ func NewStartScriptCmd() *cobra.Command {
func uiPrintStatus(execution testkube.Execution) {
result := execution.ExecutionResult

ui.NL()

switch true {
case result.IsQueued():
ui.Warn("Script queued for execution")
Expand All @@ -79,26 +82,32 @@ func uiPrintStatus(execution testkube.Execution) {
ui.Warn("Script execution started")

case result.IsSuccesful():
fmt.Println(result.Output)
ui.Info(result.Output)
duration := execution.EndTime.Sub(execution.StartTime)
ui.Success("Script execution completed with sucess in " + duration.String())

case result.IsFailed():
fmt.Println(result.ErrorMessage)
ui.Warn("Test script execution failed:")
ui.Info(result.ErrorMessage)
ui.Errf("Script execution failed")
os.Exit(1)
}

ui.NL()
}

func uiShellCommandBlock(id string) {
func uiShellGetExecution(id string) {
ui.ShellCommand(
"Use following command to get script execution details",
"kubectl testkube scripts execution "+id,
)

ui.NL()
}

func uiShellWatchExecution(id string) {
ui.ShellCommand(
"or watch script execution until complete",
"Watch script execution until complete",
"kubectl testkube scripts watch "+id,
)

Expand Down
1 change: 0 additions & 1 deletion internal/app/api/v1/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ func (s TestKubeAPI) GetExecutionHandler() fiber.Handler {
}
}

s.Log.Infow("get script execution request", "id", scriptID, "executionID", executionID)
s.Log.Debugw("get script execution request - debug", "execution", execution)

return c.JSON(execution)
Expand Down
Loading

0 comments on commit 0fd321a

Please sign in to comment.