From b1b25cc9cc85084e8b40e6fec09ce591063d9163 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Wed, 10 Jul 2024 14:28:42 +0300 Subject: [PATCH] fix: add parent ids for test workflow running context Signed-off-by: Vladislav Sukhin --- api/v1/testkube.yaml | 11 ++++++++--- cmd/tcl/testworkflow-toolkit/commands/execute.go | 11 ++++++----- cmd/tcl/testworkflow-toolkit/spawn/utils.go | 1 + cmd/testworkflow-toolkit/env/config.go | 1 + .../testkube/model_test_workflow_execution_request.go | 2 ++ pkg/testworkflows/testworkflowexecutor/executor.go | 2 ++ pkg/testworkflows/testworkflowprocessor/container.go | 1 + 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/api/v1/testkube.yaml b/api/v1/testkube.yaml index 307e36bc291..d40044ccc93 100644 --- a/api/v1/testkube.yaml +++ b/api/v1/testkube.yaml @@ -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 @@ -8034,7 +8039,7 @@ components: runningContext: type: array description: running context for the test workflow execution - items: + items: $ref: "#/components/schemas/TestWorkflowRunningContext" required: - id @@ -8071,7 +8076,7 @@ components: runningContext: type: array description: running context for the test workflow execution - items: + items: $ref: "#/components/schemas/TestWorkflowRunningContext" required: - id diff --git a/cmd/tcl/testworkflow-toolkit/commands/execute.go b/cmd/tcl/testworkflow-toolkit/commands/execute.go index a599d1ff118..aecd9ff19d3 100644 --- a/cmd/tcl/testworkflow-toolkit/commands/execute.go +++ b/cmd/tcl/testworkflow-toolkit/commands/execute.go @@ -12,6 +12,7 @@ import ( "encoding/json" "fmt" "os" + "strings" "sync" "time" @@ -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), @@ -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 { diff --git a/cmd/tcl/testworkflow-toolkit/spawn/utils.go b/cmd/tcl/testworkflow-toolkit/spawn/utils.go index 75713eb6794..b6ef29ab72c 100644 --- a/cmd/tcl/testworkflow-toolkit/spawn/utils.go +++ b/cmd/tcl/testworkflow-toolkit/spawn/utils.go @@ -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, }) } diff --git a/cmd/testworkflow-toolkit/env/config.go b/cmd/testworkflow-toolkit/env/config.go index c7fd6207610..12074400eb1 100644 --- a/cmd/testworkflow-toolkit/env/config.go +++ b/cmd/testworkflow-toolkit/env/config.go @@ -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 { diff --git a/pkg/api/v1/testkube/model_test_workflow_execution_request.go b/pkg/api/v1/testkube/model_test_workflow_execution_request.go index e47f5f8e101..d5e885af16e 100644 --- a/pkg/api/v1/testkube/model_test_workflow_execution_request.go +++ b/pkg/api/v1/testkube/model_test_workflow_execution_request.go @@ -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"` } diff --git a/pkg/testworkflows/testworkflowexecutor/executor.go b/pkg/testworkflows/testworkflowexecutor/executor.go index b1b358d0042..6278ff2c7e2 100644 --- a/pkg/testworkflows/testworkflowexecutor/executor.go +++ b/pkg/testworkflows/testworkflowexecutor/executor.go @@ -7,6 +7,7 @@ import ( "io" "os" "strconv" + "strings" "sync" "time" @@ -448,6 +449,7 @@ func (e *executor) Execute(ctx context.Context, workflow testworkflowsv1.TestWor "name": "", "number": "1", "scheduledAt": now.UTC().Format(constants.RFC3339Millis), + "parentIds": strings.Join(request.ParentExecutionIds, "/"), }) // Preserve resolved TestWorkflow diff --git a/pkg/testworkflows/testworkflowprocessor/container.go b/pkg/testworkflows/testworkflowprocessor/container.go index 3b2a01de28b..95860748ae2 100644 --- a/pkg/testworkflows/testworkflowprocessor/container.go +++ b/pkg/testworkflows/testworkflowprocessor/container.go @@ -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}}",