diff --git a/cmd/kubectl-testkube/commands/testworkflows/run.go b/cmd/kubectl-testkube/commands/testworkflows/run.go index cbe7061a6b..c4deb975c5 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/run.go +++ b/cmd/kubectl-testkube/commands/testworkflows/run.go @@ -198,8 +198,8 @@ func uiWatch(execution testkube.TestWorkflowExecution, serviceName string, servi 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 execution.Workflow != nil { + found = execution.Workflow.HasService(serviceName) } if !found { diff --git a/internal/app/api/v1/testworkflowexecutions.go b/internal/app/api/v1/testworkflowexecutions.go index a806588161..3670613fb7 100644 --- a/internal/app/api/v1/testworkflowexecutions.go +++ b/internal/app/api/v1/testworkflowexecutions.go @@ -104,8 +104,8 @@ func (s *TestkubeAPI) StreamTestWorkflowExecutionServiceNotificationsHandler() f } found := false - if execution.Workflow != nil && execution.Workflow.Spec != nil { - _, found = execution.Workflow.Spec.Services[serviceName] + if execution.Workflow != nil { + found = execution.Workflow.HasService(serviceName) } if !found { @@ -189,7 +189,7 @@ func (s *TestkubeAPI) StreamTestWorkflowExecutionServiceNotificationsWebSocketHa found := false if execution.Workflow != nil && execution.Workflow.Spec != nil { - _, found = execution.Workflow.Spec.Services[serviceName] + found = execution.Workflow.HasService(serviceName) } if !found { diff --git a/pkg/api/v1/testkube/model_test_workflow_extended.go b/pkg/api/v1/testkube/model_test_workflow_extended.go index 2150f76030..846218c83e 100644 --- a/pkg/api/v1/testkube/model_test_workflow_extended.go +++ b/pkg/api/v1/testkube/model_test_workflow_extended.go @@ -96,3 +96,22 @@ func (w TestWorkflow) GetLabels() map[string]string { func (w TestWorkflow) GetAnnotations() map[string]string { return w.Annotations } + +func (w TestWorkflow) HasService(name string) bool { + if w.Spec == nil { + return false + } + + steps := append(w.Spec.Setup, append(w.Spec.Steps, w.Spec.After...)...) + for _, step := range steps { + if step.HasService(name) { + return true + } + } + + if _, ok := w.Spec.Services[name]; ok { + return true + } + + return false +} diff --git a/pkg/api/v1/testkube/model_test_workflow_step_extended.go b/pkg/api/v1/testkube/model_test_workflow_step_extended.go index b8ddb9db83..b4e87b99f1 100644 --- a/pkg/api/v1/testkube/model_test_workflow_step_extended.go +++ b/pkg/api/v1/testkube/model_test_workflow_step_extended.go @@ -65,3 +65,24 @@ func (w *TestWorkflowStep) GetTemplateRefs() []TestWorkflowTemplateRef { return templateRefs } + +func (w *TestWorkflowStep) HasService(name string) bool { + steps := append(w.Setup, w.Steps...) + if w.Parallel != nil { + steps = append(steps, w.Parallel.Setup...) + steps = append(steps, w.Parallel.Steps...) + steps = append(steps, w.Parallel.After...) + } + + for _, step := range steps { + if step.HasService(name) { + return true + } + } + + if _, ok := w.Services[name]; ok { + return true + } + + return false +}