Skip to content

Commit

Permalink
fix: check service name
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
  • Loading branch information
vsukhin committed Nov 27, 2024
1 parent 68fe09f commit c55187f
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ func uiWatch(execution testkube.TestWorkflowExecution, serviceName string, servi
if serviceName == "" {
result, err = watchTestWorkflowLogs(execution.Id, execution.Signature, client)
} else {
found := false
if execution.Workflow != nil && execution.Workflow.Spec != nil {
_, found = execution.Workflow.Spec.Services[serviceName]
}

if !found {
ui.Failf("unknown service '%s' for test workflow execution %s", serviceName, execution.Id)
}

result, err = watchTestWorkflowServiceLogs(execution.Id, serviceName, serviceIndex, execution.Signature, client)
}
ui.ExitOnError("reading test workflow execution logs", err)
Expand Down Expand Up @@ -295,17 +304,10 @@ func getTimestampLength(line string) int {
return 0
}

func watchTestWorkflowLogs(id string, signature []testkube.TestWorkflowSignature, client apiclientv1.Client) (*testkube.TestWorkflowResult, error) {
ui.Info("Getting logs from test workflow job", id)

notifications, err := client.GetTestWorkflowExecutionNotifications(id)
if err != nil {
return nil, err
}

func printTestWorkflowLogs(signature []testkube.TestWorkflowSignature,
notifications chan testkube.TestWorkflowExecutionNotification) (result *testkube.TestWorkflowResult) {
steps := flattenSignatures(signature)

var result *testkube.TestWorkflowResult
var isLineBeginning = true
for l := range notifications {
if l.Output != nil {
Expand All @@ -323,7 +325,18 @@ func watchTestWorkflowLogs(id string, signature []testkube.TestWorkflowSignature
}

ui.NL()
return result
}

func watchTestWorkflowLogs(id string, signature []testkube.TestWorkflowSignature, client apiclientv1.Client) (*testkube.TestWorkflowResult, error) {
ui.Info("Getting logs from test workflow job", id)

notifications, err := client.GetTestWorkflowExecutionNotifications(id)
if err != nil {
return nil, err
}

result := printTestWorkflowLogs(signature, notifications)
return result, nil
}

Expand Down Expand Up @@ -357,27 +370,7 @@ func watchTestWorkflowServiceLogs(id, serviceName string, serviceIndex int,
break
}

steps := flattenSignatures(signature)

var result *testkube.TestWorkflowResult
var isLineBeginning = true
for l := range notifications {
if l.Output != nil {
continue
}
if l.Result != nil {
if printResultDifference(result, l.Result, steps) {
isLineBeginning = true
}
result = l.Result
continue
}

printStructuredLogLines(l.Log, &isLineBeginning)
}

ui.NL()

result := printTestWorkflowLogs(signature, notifications)
return result, nil
}

Expand Down

0 comments on commit c55187f

Please sign in to comment.