Skip to content

Commit

Permalink
fix: add parent ids for test workflow running context
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Jul 10, 2024
1 parent 581d826 commit b1b25cc
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
11 changes: 8 additions & 3 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7939,7 +7939,12 @@ components:
type: array
description: running context for the test workflow execution
items:
$ref: "#/components/schemas/TestWorkflowRunningContext"
$ref: "#/components/schemas/TestWorkflowRunningContext"
parentExecutionIds:
type: array
description: parent execution ids
items:
type: string

TestWorkflowWithExecution:
type: object
Expand Down Expand Up @@ -8034,7 +8039,7 @@ components:
runningContext:
type: array
description: running context for the test workflow execution
items:
items:
$ref: "#/components/schemas/TestWorkflowRunningContext"
required:
- id
Expand Down Expand Up @@ -8071,7 +8076,7 @@ components:
runningContext:
type: array
description: running context for the test workflow execution
items:
items:
$ref: "#/components/schemas/TestWorkflowRunningContext"
required:
- id
Expand Down
11 changes: 6 additions & 5 deletions cmd/tcl/testworkflow-toolkit/commands/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -149,11 +150,10 @@ func buildTestExecution(test testworkflowsv1.StepExecuteTest, async, disableWebh
func buildWorkflowExecution(workflow testworkflowsv1.StepExecuteWorkflow, async bool) (func() error, error) {
return func() (err error) {
c := env.Testkube()
path := env.Config().Execution.ResourceId
if env.Config().Execution.ResourceId != env.Config().Execution.RootResourceId {
path = env.Config().Execution.RootResourceId + "/" + path
parentIds := []string{env.ExecutionId()}
if env.Config().Execution.ParentIds != "" {
parentIds = append(strings.Split(env.Config().Execution.ParentIds, "/"), parentIds...)
}

exec, err := c.ExecuteTestWorkflow(workflow.Name, testkube.TestWorkflowExecutionRequest{
Name: workflow.ExecutionName,
Config: testworkflows.MapConfigValueKubeToAPI(workflow.Config),
Expand All @@ -165,10 +165,11 @@ func buildWorkflowExecution(workflow testworkflowsv1.StepExecuteWorkflow, async
CallerResourceType: common.Ptr(testkube.TESTWORKFLOW_TestWorkflowRunningContextCallerResourceType),
CallerResourceName: env.WorkflowName(),
CallerResourceExecutionID: env.ExecutionId(),
FullExecutionPath: path,
FullExecutionPath: strings.Join(parentIds, "/"),
},
},
},
ParentExecutionIds: parentIds,
})
execName := exec.Name
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/tcl/testworkflow-toolkit/spawn/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func CreateExecutionMachine(prefix string, index int64) (string, expressions.Mac
"name": env.ExecutionName(),
"number": env.ExecutionNumber(),
"scheduledAt": env.ExecutionScheduledAt().UTC().Format(constants.RFC3339Millis),
"parentIds": env.Config().Execution.ParentIds,
})
}

Expand Down
1 change: 1 addition & 0 deletions cmd/testworkflow-toolkit/env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type envExecutionConfig struct {
ResourceId string `envconfig:"TK_EXI"`
RootResourceId string `envconfig:"TK_EXR"`
FSPrefix string `envconfig:"TK_FS"`
ParentIds string `envconfig:"TK_PAR"`
}

type envSystemConfig struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_execution_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ type TestWorkflowExecutionRequest struct {
DisableWebhooks bool `json:"disableWebhooks,omitempty"`
// running context for the test workflow execution
RunningContext []TestWorkflowRunningContext `json:"runningContext,omitempty"`
// parent execution ids
ParentExecutionIds []string `json:"parentExecutionIds,omitempty"`
}
2 changes: 2 additions & 0 deletions pkg/testworkflows/testworkflowexecutor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -448,6 +449,7 @@ func (e *executor) Execute(ctx context.Context, workflow testworkflowsv1.TestWor
"name": "<mock_name>",
"number": "1",
"scheduledAt": now.UTC().Format(constants.RFC3339Millis),
"parentIds": strings.Join(request.ParentExecutionIds, "/"),
})

// Preserve resolved TestWorkflow
Expand Down
1 change: 1 addition & 0 deletions pkg/testworkflows/testworkflowprocessor/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ func (c *container) EnableToolkit(ref string) Container {
"TK_EXN": "{{execution.name}}",
"TK_EXC": "{{execution.number}}",
"TK_EXS": "{{execution.scheduledAt}}",
"TK_PAR": "{{execution.parentIds}}",
"TK_EXI": "{{resource.id}}",
"TK_EXR": "{{resource.root}}",
"TK_FS": "{{resource.fsPrefix}}",
Expand Down

0 comments on commit b1b25cc

Please sign in to comment.