Skip to content

Commit

Permalink
fix: add service name check
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 28, 2024
1 parent c4658c5 commit 3768550
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions internal/app/api/v1/testworkflowexecutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
21 changes: 21 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_step_extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3768550

Please sign in to comment.