Skip to content

Commit

Permalink
fix: pass disable webhooks flag to execute operation
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Jul 15, 2024
1 parent 5d84c36 commit 614fbd3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
22 changes: 10 additions & 12 deletions cmd/tcl/testworkflow-toolkit/commands/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -410,7 +409,6 @@ func NewExecuteCmd() *cobra.Command {
cmd.Flags().StringArrayVarP(&workflows, "workflow", "w", nil, "workflows to run")
cmd.Flags().IntVarP(&parallelism, "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
}
9 changes: 5 additions & 4 deletions cmd/tcl/testworkflow-toolkit/spawn/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}

Expand Down
21 changes: 13 additions & 8 deletions cmd/testworkflow-toolkit/env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -145,6 +146,10 @@ func ExecutionScheduledAt() time.Time {
return t
}

func ExecutionDisableWebhooks() bool {
return Config().Execution.disableWebhooks
}

func JUnitParserEnabled() bool {
return Config().Features.EnableJUnitParser
}
18 changes: 10 additions & 8 deletions pkg/testworkflows/testworkflowexecutor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<mock_name>",
"number": "1",
"scheduledAt": now.UTC().Format(constants.RFC3339Millis),
"id": id,
"name": "<mock_name>",
"number": "1",
"scheduledAt": now.UTC().Format(constants.RFC3339Millis),
"disableWebhooks": request.DisableWebhooks,
})

// Preserve resolved TestWorkflow
Expand Down Expand Up @@ -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
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 @@ -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}}",
Expand Down

0 comments on commit 614fbd3

Please sign in to comment.