Skip to content

Commit

Permalink
fix: [TKC-2343] workflow execution url (#5716)
Browse files Browse the repository at this point in the history
* fix: show test workflow execution uri

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: add uris to test workflow executions

Signed-off-by: Vladislav Sukhin <[email protected]>

---------

Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin authored Aug 2, 2024
1 parent 373079c commit 5775761
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
26 changes: 26 additions & 0 deletions cmd/kubectl-testkube/commands/common/render/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"gopkg.in/yaml.v2"

"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
"github.com/kubeshop/testkube/pkg/api/v1/client"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/ui"
Expand Down Expand Up @@ -182,3 +183,28 @@ func PrintTestSuiteExecutionURIs(execution *testkube.TestSuiteExecution, dashboa
testSuiteName, execution.Id))
ui.NL()
}

func PrintTestWorkflowExecutionURIs(execution *testkube.TestWorkflowExecution) {
cfg, err := config.Load()
ui.ExitOnError("loading config file", err)

if cfg.ContextType != config.ContextTypeCloud {
return
}

if execution.Result == nil || !execution.Result.IsFinished() {
return
}

ui.NL()
workflowName := ""
if execution.Workflow != nil {
workflowName = execution.Workflow.Name
}

ui.ExecutionLink("Test Workflow URI:", fmt.Sprintf("%s/organization/%s/environment/%s/dashboard/test-workflows/%s",
cfg.CloudContext.UiUri, cfg.CloudContext.OrganizationId, cfg.CloudContext.EnvironmentId, workflowName))
ui.ExecutionLink("Test Workflow Execution URI:", fmt.Sprintf("%s/organization/%s/environment/%s/dashboard/test-workflows/%s/execution/%s",
cfg.CloudContext.UiUri, cfg.CloudContext.OrganizationId, cfg.CloudContext.EnvironmentId, workflowName, execution.Id))
ui.NL()
}
31 changes: 22 additions & 9 deletions cmd/kubectl-testkube/commands/testworkflows/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func NewGetTestWorkflowExecutionsCmd() *cobra.Command {
Long: `Gets TestWorkflow execution details by ID, or list if id is not passed`,

Run: func(cmd *cobra.Command, args []string) {
outputFlag := cmd.Flag("output")
outputType := render.OutputPretty
if outputFlag != nil {
outputType = render.OutputType(outputFlag.Value.String())
}

outputPretty := outputType == render.OutputPretty

client, _, err := common.GetClient(cmd)
ui.ExitOnError("getting client", err)

Expand All @@ -51,19 +59,24 @@ func NewGetTestWorkflowExecutionsCmd() *cobra.Command {
ui.ExitOnError("rendering obj", err)
}

ui.Info("Getting logs for test workflow execution", executionID)
if outputPretty {
ui.Info("Getting logs for test workflow execution", executionID)

logs, err := client.GetTestWorkflowExecutionLogs(executionID)
ui.ExitOnError("getting logs from executor", err)
logs, err := client.GetTestWorkflowExecutionLogs(executionID)
ui.ExitOnError("getting logs from executor", err)

sigs := flattenSignatures(execution.Signature)
sigs := flattenSignatures(execution.Signature)

var results map[string]testkube.TestWorkflowStepResult
if execution.Result != nil {
results = execution.Result.Steps
}
var results map[string]testkube.TestWorkflowStepResult
if execution.Result != nil {
results = execution.Result.Steps
}

printRawLogLines(logs, sigs, results)
printRawLogLines(logs, sigs, results)
if !logsOnly {
render.PrintTestWorkflowExecutionURIs(&execution)
}
}
},
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func NewRunTestWorkflowCmd() *cobra.Command {
uiShellWatchExecution(execution.Id)
}

execution, err = client.GetTestWorkflowExecution(execution.Id)
ui.ExitOnError("get execution failed", err)

render.PrintTestWorkflowExecutionURIs(&execution)
uiShellGetExecution(execution.Id)
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/kubectl-testkube/commands/testworkflows/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func NewWatchTestWorkflowExecutionCmd() *cobra.Command {
exitCode := uiWatch(execution, client)
ui.NL()

execution, err = client.GetTestWorkflowExecution(execution.Id)
ui.ExitOnError("get execution failed", err)

render.PrintTestWorkflowExecutionURIs(&execution)
uiShellGetExecution(execution.Id)
os.Exit(exitCode)
},
Expand Down

0 comments on commit 5775761

Please sign in to comment.