From 614fbd35d2c12428255d70a80718bf82611237c4 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Mon, 15 Jul 2024 15:34:46 +0300 Subject: [PATCH] fix: pass disable webhooks flag to execute operation Signed-off-by: Vladislav Sukhin --- .../testworkflow-toolkit/commands/execute.go | 22 +++++++++---------- cmd/tcl/testworkflow-toolkit/spawn/utils.go | 9 ++++---- cmd/testworkflow-toolkit/env/config.go | 21 +++++++++++------- .../testworkflowexecutor/executor.go | 18 ++++++++------- .../testworkflowprocessor/container.go | 1 + 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/cmd/tcl/testworkflow-toolkit/commands/execute.go b/cmd/tcl/testworkflow-toolkit/commands/execute.go index 9f655249991..b146ae54621 100644 --- a/cmd/tcl/testworkflow-toolkit/commands/execute.go +++ b/cmd/tcl/testworkflow-toolkit/commands/execute.go @@ -52,7 +52,7 @@ type executionResult struct { Status string `json:"status"` } -func buildTestExecution(test testworkflowsv1.StepExecuteTest, async, disableWebhooks bool) (func() error, error) { +func buildTestExecution(test testworkflowsv1.StepExecuteTest, async bool) (func() error, error) { return func() (err error) { c := env.Testkube() @@ -84,7 +84,7 @@ func buildTestExecution(test testworkflowsv1.StepExecuteTest, async, disableWebh EnvConfigMaps: common.MapSlice(test.ExecutionRequest.EnvConfigMaps, testworkflows.MapTestEnvReferenceKubeToAPI), EnvSecrets: common.MapSlice(test.ExecutionRequest.EnvSecrets, testworkflows.MapTestEnvReferenceKubeToAPI), ExecutionNamespace: test.ExecutionRequest.ExecutionNamespace, - DisableWebhooks: disableWebhooks, + DisableWebhooks: env.ExecutionDisableWebhooks(), }) execName := exec.Name if err != nil { @@ -146,14 +146,14 @@ func buildTestExecution(test testworkflowsv1.StepExecuteTest, async, disableWebh }, nil } -func buildWorkflowExecution(workflow testworkflowsv1.StepExecuteWorkflow, async, disableWebhooks bool) (func() error, error) { +func buildWorkflowExecution(workflow testworkflowsv1.StepExecuteWorkflow, async bool) (func() error, error) { return func() (err error) { c := env.Testkube() exec, err := c.ExecuteTestWorkflow(workflow.Name, testkube.TestWorkflowExecutionRequest{ Name: workflow.ExecutionName, Config: testworkflows.MapConfigValueKubeToAPI(workflow.Config), - DisableWebhooks: disableWebhooks, + DisableWebhooks: env.ExecutionDisableWebhooks(), }) execName := exec.Name if err != nil { @@ -257,11 +257,10 @@ func registerTransfer(transferSrv transfer.Server, request map[string]testworkfl func NewExecuteCmd() *cobra.Command { var ( - tests []string - workflows []string - parallelism int - async bool - disableWebhooks bool + tests []string + workflows []string + parallelism int + async bool ) cmd := &cobra.Command{ @@ -309,7 +308,7 @@ func NewExecuteCmd() *cobra.Command { if err != nil { ui.Fail(errors.Wrapf(err, "'%s' test: computing execution", spec.Name)) } - fn, err := buildTestExecution(*spec, async, disableWebhooks) + fn, err := buildTestExecution(*spec, async) if err != nil { ui.Fail(err) } @@ -347,7 +346,7 @@ func NewExecuteCmd() *cobra.Command { if err != nil { ui.Fail(errors.Wrapf(err, "'%s' workflow: computing execution", spec.Name)) } - fn, err := buildWorkflowExecution(*spec, async, disableWebhooks) + fn, err := buildWorkflowExecution(*spec, async) if err != nil { ui.Fail(err) } @@ -410,7 +409,6 @@ func NewExecuteCmd() *cobra.Command { cmd.Flags().StringArrayVarP(&workflows, "workflow", "w", nil, "workflows to run") cmd.Flags().IntVarP(¶llelism, "parallelism", "p", 0, "how many items could be executed at once") cmd.Flags().BoolVar(&async, "async", false, "should it wait for results") - cmd.Flags().BoolVar(&disableWebhooks, "disableWebhooks", false, "should it disable webhooks") return cmd } diff --git a/cmd/tcl/testworkflow-toolkit/spawn/utils.go b/cmd/tcl/testworkflow-toolkit/spawn/utils.go index 5f50fbfe107..acfe2b137eb 100644 --- a/cmd/tcl/testworkflow-toolkit/spawn/utils.go +++ b/cmd/tcl/testworkflow-toolkit/spawn/utils.go @@ -199,10 +199,11 @@ func CreateExecutionMachine(prefix string, index int64) (string, expressions.Mac "fsPrefix": fsPrefix, }). Register("execution", map[string]interface{}{ - "id": env.ExecutionId(), - "name": env.ExecutionName(), - "number": env.ExecutionNumber(), - "scheduledAt": env.ExecutionScheduledAt().UTC().Format(constants.RFC3339Millis), + "id": env.ExecutionId(), + "name": env.ExecutionName(), + "number": env.ExecutionNumber(), + "scheduledAt": env.ExecutionScheduledAt().UTC().Format(constants.RFC3339Millis), + "disableWebhooks": env.ExecutionDisableWebhooks(), }) } diff --git a/cmd/testworkflow-toolkit/env/config.go b/cmd/testworkflow-toolkit/env/config.go index c7fd6207610..bdfa8f612a7 100644 --- a/cmd/testworkflow-toolkit/env/config.go +++ b/cmd/testworkflow-toolkit/env/config.go @@ -35,14 +35,15 @@ type envCloudConfig struct { } type envExecutionConfig struct { - WorkflowName string `envconfig:"TK_WF"` - Id string `envconfig:"TK_EX"` - Name string `envconfig:"TK_EXN"` - Number int64 `envconfig:"TK_EXC"` - ScheduledAt string `envconfig:"TK_EXS"` - ResourceId string `envconfig:"TK_EXI"` - RootResourceId string `envconfig:"TK_EXR"` - FSPrefix string `envconfig:"TK_FS"` + WorkflowName string `envconfig:"TK_WF"` + Id string `envconfig:"TK_EX"` + Name string `envconfig:"TK_EXN"` + Number int64 `envconfig:"TK_EXC"` + ScheduledAt string `envconfig:"TK_EXS"` + ResourceId string `envconfig:"TK_EXI"` + RootResourceId string `envconfig:"TK_EXR"` + FSPrefix string `envconfig:"TK_FS"` + disableWebhooks bool `envconfig:"TK_DWH"` } type envSystemConfig struct { @@ -145,6 +146,10 @@ func ExecutionScheduledAt() time.Time { return t } +func ExecutionDisableWebhooks() bool { + return Config().Execution.disableWebhooks +} + func JUnitParserEnabled() bool { return Config().Features.EnableJUnitParser } diff --git a/pkg/testworkflows/testworkflowexecutor/executor.go b/pkg/testworkflows/testworkflowexecutor/executor.go index 0a7fef4cb1e..46e89e5e536 100644 --- a/pkg/testworkflows/testworkflowexecutor/executor.go +++ b/pkg/testworkflows/testworkflowexecutor/executor.go @@ -439,10 +439,11 @@ func (e *executor) Execute(ctx context.Context, workflow testworkflowsv1.TestWor "fsPrefix": "", }) mockExecutionMachine := expressions.NewMachine().Register("execution", map[string]interface{}{ - "id": id, - "name": "", - "number": "1", - "scheduledAt": now.UTC().Format(constants.RFC3339Millis), + "id": id, + "name": "", + "number": "1", + "scheduledAt": now.UTC().Format(constants.RFC3339Millis), + "disableWebhooks": request.DisableWebhooks, }) // Preserve resolved TestWorkflow @@ -480,10 +481,11 @@ func (e *executor) Execute(ctx context.Context, workflow testworkflowsv1.TestWor // Build machine with actual execution data executionMachine := expressions.NewMachine().Register("execution", map[string]interface{}{ - "id": id, - "name": executionName, - "number": number, - "scheduledAt": now.UTC().Format(constants.RFC3339Millis), + "id": id, + "name": executionName, + "number": number, + "scheduledAt": now.UTC().Format(constants.RFC3339Millis), + "disableWebhooks": request.DisableWebhooks, }) // Process the TestWorkflow diff --git a/pkg/testworkflows/testworkflowprocessor/container.go b/pkg/testworkflows/testworkflowprocessor/container.go index 1546965341b..fba2a2d4950 100644 --- a/pkg/testworkflows/testworkflowprocessor/container.go +++ b/pkg/testworkflows/testworkflowprocessor/container.go @@ -429,6 +429,7 @@ func (c *container) EnableToolkit(ref string) Container { "TK_EXN": "{{execution.name}}", "TK_EXC": "{{execution.number}}", "TK_EXS": "{{execution.scheduledAt}}", + "TK_DWH": "{{execution.disableWebhooks}}", "TK_EXI": "{{resource.id}}", "TK_EXR": "{{resource.root}}", "TK_FS": "{{resource.fsPrefix}}",