From cd50ec5a35d29a10aa50b9bd7c75ff014b624456 Mon Sep 17 00:00:00 2001 From: Lilla Vass Date: Fri, 7 Jun 2024 10:09:48 +0200 Subject: [PATCH] feat: [TKC-1948] disable workflow webhooks (#5550) * feat: disable workflow webhooks on execution * feat: disable workflow webhooks * fix: use correct data type * feat: update operator dependency --- api/v1/testkube.yaml | 26 ++++++++++++++ .../commands/testworkflows/create.go | 5 +++ .../commands/testworkflows/run.go | 19 ++++++++-- .../testworkflow-toolkit/commands/execute.go | 15 ++++---- go.mod | 2 +- go.sum | 4 +-- .../testkube/model_test_workflow_execution.go | 2 ++ .../model_test_workflow_execution_cr.go | 2 ++ .../model_test_workflow_execution_request.go | 2 ++ ..._test_workflow_independent_service_spec.go | 12 +++---- ...test_workflow_independent_step_parallel.go | 26 +++++++------- ...odel_test_workflow_notifications_config.go | 15 ++++++++ .../model_test_workflow_service_spec.go | 4 +-- .../v1/testkube/model_test_workflow_spec.go | 23 ++++++------ ...del_test_workflow_step_execute_test_ref.go | 12 +++---- ...workflow_step_execute_test_workflow_ref.go | 12 +++---- .../model_test_workflow_step_parallel.go | 35 ++++++++++--------- pkg/event/kind/webhook/listener.go | 3 ++ .../mapperstcl/testworkflows/kube_openapi.go | 29 +++++++++------ .../mapperstcl/testworkflows/openapi_kube.go | 17 ++++++--- .../testworkflowexecutor/executor.go | 6 ++++ 21 files changed, 183 insertions(+), 88 deletions(-) create mode 100644 pkg/api/v1/testkube/model_test_workflow_notifications_config.go diff --git a/api/v1/testkube.yaml b/api/v1/testkube.yaml index 502aa0f343b..f9fd410108f 100644 --- a/api/v1/testkube.yaml +++ b/api/v1/testkube.yaml @@ -7530,6 +7530,10 @@ components: testWorkflowExecutionName: type: string description: test workflow execution name started the test workflow execution + disableWebhooks: + type: boolean + description: whether webhooks on the executions of this test workflow are disabled + default: false TestWorkflowWithExecution: type: object @@ -7614,6 +7618,13 @@ components: testWorkflowExecutionName: type: string description: test workflow execution name started the test workflow execution + disableWebhooks: + type: boolean + description: whether webhooks on the executions of this test workflow are disabled + default: false + example: + - true + - false required: - id - name @@ -8146,6 +8157,9 @@ components: type: array items: $ref: "#/components/schemas/TestWorkflowEvent" + notifications: + $ref: "#/components/schemas/TestWorkflowNotificationsConfig" + TestWorkflowTemplateSpec: type: object @@ -8818,6 +8832,14 @@ components: items: $ref: "#/components/schemas/VolumeMount" + TestWorkflowNotificationsConfig: + type: object + properties: + disableWebhooks: + type: boolean + description: disable webhooks for this test workflow + default: false + TestWorkflowStepRun: type: object properties: @@ -8985,6 +9007,10 @@ components: status: $ref: "#/components/schemas/TestWorkflowExecutionStatusCR" description: test workflow execution status + disableWebhooks: + type: boolean + description: disable webhooks for this execution + default: false TestWorkflowExecutionStatusCR: type: object diff --git a/cmd/kubectl-testkube/commands/testworkflows/create.go b/cmd/kubectl-testkube/commands/testworkflows/create.go index 5615d42a291..bec338ef6cb 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/create.go +++ b/cmd/kubectl-testkube/commands/testworkflows/create.go @@ -61,6 +61,10 @@ func NewCreateTestWorkflowCmd() *cobra.Command { client, _, err := common.GetClient(cmd) ui.ExitOnError("getting client", err) + if cmd.Flag("disable-webhooks").Changed { + obj.Spec.Notifications.DisableWebhooks = true + } + workflow, _ := client.GetTestWorkflow(obj.Name) if workflow.Name != "" { if !update { @@ -80,6 +84,7 @@ func NewCreateTestWorkflowCmd() *cobra.Command { cmd.Flags().StringVar(&name, "name", "", "test workflow name") cmd.Flags().BoolVar(&update, "update", false, "update, if test workflow already exists") cmd.Flags().StringVarP(&filePath, "file", "f", "", "file path to get the test workflow specification") + cmd.Flags().Bool("disable-webhooks", false, "disable webhooks for this test workflow") return cmd } diff --git a/cmd/kubectl-testkube/commands/testworkflows/run.go b/cmd/kubectl-testkube/commands/testworkflows/run.go index 8739eade6ed..6dbe9f75bba 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/run.go +++ b/cmd/kubectl-testkube/commands/testworkflows/run.go @@ -34,6 +34,10 @@ func NewRunTestWorkflowCmd() *cobra.Command { Short: "Starts test workflow execution", Run: func(cmd *cobra.Command, args []string) { + if common.IsBothEnabledAndDisabledSet(cmd) { + ui.Failf("both --enable-webhooks and --disable-webhooks flags are set, please use only one") + } + outputFlag := cmd.Flag("output") outputType := render.OutputPretty if outputFlag != nil { @@ -45,10 +49,19 @@ func NewRunTestWorkflowCmd() *cobra.Command { client, _, err := common.GetClient(cmd) ui.ExitOnError("getting client", err) + var disableWebhooks bool + if cmd.Flag("enable-webhooks").Changed { + disableWebhooks = false + } + if cmd.Flag("disable-webhooks").Changed { + disableWebhooks = true + } + name := args[0] execution, err := client.ExecuteTestWorkflow(name, testkube.TestWorkflowExecutionRequest{ - Name: executionName, - Config: config, + Name: executionName, + Config: config, + DisableWebhooks: disableWebhooks, }) ui.ExitOnError("execute test workflow "+name+" from namespace "+namespace, err) err = renderer.PrintTestWorkflowExecution(cmd, os.Stdout, execution) @@ -74,6 +87,8 @@ func NewRunTestWorkflowCmd() *cobra.Command { cmd.Flags().StringVarP(&executionName, "name", "n", "", "execution name, if empty will be autogenerated") cmd.Flags().StringToStringVarP(&config, "config", "", map[string]string{}, "configuration variables in a form of name1=val1 passed to executor") cmd.Flags().BoolVarP(&watchEnabled, "watch", "f", false, "watch for changes after start") + cmd.Flags().Bool("disable-webhooks", false, "disable webhooks for this execution") + cmd.Flags().Bool("enable-webhooks", false, "enable webhooks for this execution") return cmd } diff --git a/cmd/tcl/testworkflow-toolkit/commands/execute.go b/cmd/tcl/testworkflow-toolkit/commands/execute.go index 69639fa1cc7..5ec1dd1164f 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 bool) (func() error, error) { +func buildTestExecution(test testworkflowsv1.StepExecuteTest, async, disableWebhooks bool) (func() error, error) { return func() (err error) { c := env.Testkube() @@ -84,6 +84,7 @@ func buildTestExecution(test testworkflowsv1.StepExecuteTest, async bool) (func( EnvConfigMaps: common.MapSlice(test.ExecutionRequest.EnvConfigMaps, testworkflows.MapTestEnvReferenceKubeToAPI), EnvSecrets: common.MapSlice(test.ExecutionRequest.EnvSecrets, testworkflows.MapTestEnvReferenceKubeToAPI), ExecutionNamespace: test.ExecutionRequest.ExecutionNamespace, + DisableWebhooks: disableWebhooks, }) execName := exec.Name if err != nil { @@ -255,10 +256,11 @@ func registerTransfer(transferSrv transfer.Server, request map[string]testworkfl func NewExecuteCmd() *cobra.Command { var ( - tests []string - workflows []string - parallelism int - async bool + tests []string + workflows []string + parallelism int + async bool + disableWebhooks bool ) cmd := &cobra.Command{ @@ -306,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) + fn, err := buildTestExecution(*spec, async, disableWebhooks) if err != nil { ui.Fail(err) } @@ -407,6 +409,7 @@ 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/go.mod b/go.mod index 53b3ee8231c..64760352d3e 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/kelseyhightower/envconfig v1.4.0 github.com/kubepug/kubepug v1.7.1 - github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240604113004-a56be5477d4f + github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240607075650-f76a84665689 github.com/minio/minio-go/v7 v7.0.47 github.com/montanaflynn/stats v0.6.6 github.com/moogar0880/problems v0.1.1 diff --git a/go.sum b/go.sum index 64f84b397cd..93f67175e9d 100644 --- a/go.sum +++ b/go.sum @@ -358,8 +358,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kubepug/kubepug v1.7.1 h1:LKhfSxS8Y5mXs50v+3Lpyec+cogErDLcV7CMUuiaisw= github.com/kubepug/kubepug v1.7.1/go.mod h1:lv+HxD0oTFL7ZWjj0u6HKhMbbTIId3eG7aWIW0gyF8g= -github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240604113004-a56be5477d4f h1:zXYCjLe15EzD26k5QEcFBwX3D7fod0goNBz7pIFL+/k= -github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240604113004-a56be5477d4f/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk= +github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240607075650-f76a84665689 h1:YVG675sarzcCDYcPH81tM5FpYReGgDoSbIShbpw7NNg= +github.com/kubeshop/testkube-operator v1.15.2-beta1.0.20240607075650-f76a84665689/go.mod h1:P47tw1nKQFufdsZndyq2HG2MSa0zK/lU0XpRfZtEmIk= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= diff --git a/pkg/api/v1/testkube/model_test_workflow_execution.go b/pkg/api/v1/testkube/model_test_workflow_execution.go index e4ebf39b57b..0c06aca5e27 100644 --- a/pkg/api/v1/testkube/model_test_workflow_execution.go +++ b/pkg/api/v1/testkube/model_test_workflow_execution.go @@ -37,4 +37,6 @@ type TestWorkflowExecution struct { ResolvedWorkflow *TestWorkflow `json:"resolvedWorkflow,omitempty"` // test workflow execution name started the test workflow execution TestWorkflowExecutionName string `json:"testWorkflowExecutionName,omitempty"` + // whether webhooks on the executions of this test workflow are disabled + DisableWebhooks bool `json:"disableWebhooks,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_execution_cr.go b/pkg/api/v1/testkube/model_test_workflow_execution_cr.go index a80bad3d99a..347122569aa 100644 --- a/pkg/api/v1/testkube/model_test_workflow_execution_cr.go +++ b/pkg/api/v1/testkube/model_test_workflow_execution_cr.go @@ -13,4 +13,6 @@ type TestWorkflowExecutionCr struct { TestWorkflow *ObjectRef `json:"testWorkflow"` ExecutionRequest *TestWorkflowExecutionRequest `json:"executionRequest,omitempty"` Status *TestWorkflowExecutionStatusCr `json:"status,omitempty"` + // disable webhooks for this execution + DisableWebhooks bool `json:"disableWebhooks,omitempty"` } 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 7b86a2c2417..d3ed46b6979 100644 --- a/pkg/api/v1/testkube/model_test_workflow_execution_request.go +++ b/pkg/api/v1/testkube/model_test_workflow_execution_request.go @@ -15,4 +15,6 @@ type TestWorkflowExecutionRequest struct { Config map[string]string `json:"config,omitempty"` // test workflow execution name started the test workflow execution TestWorkflowExecutionName string `json:"testWorkflowExecutionName,omitempty"` + // whether webhooks on the executions of this test workflow are disabled + DisableWebhooks bool `json:"disableWebhooks,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_independent_service_spec.go b/pkg/api/v1/testkube/model_test_workflow_independent_service_spec.go index 192eeadb608..6be427954f2 100644 --- a/pkg/api/v1/testkube/model_test_workflow_independent_service_spec.go +++ b/pkg/api/v1/testkube/model_test_workflow_independent_service_spec.go @@ -25,6 +25,12 @@ type TestWorkflowIndependentServiceSpec struct { SecurityContext *SecurityContext `json:"securityContext,omitempty"` // volumes to mount to the container VolumeMounts []VolumeMount `json:"volumeMounts,omitempty"` + Count *BoxedString `json:"count,omitempty"` + MaxCount *BoxedString `json:"maxCount,omitempty"` + // matrix of parameters to spawn instances + Matrix map[string]interface{} `json:"matrix,omitempty"` + // parameters that should be distributed across sharded instances + Shards map[string]interface{} `json:"shards,omitempty"` // service description to display Description string `json:"description,omitempty"` // maximum time until reaching readiness @@ -36,10 +42,4 @@ type TestWorkflowIndependentServiceSpec struct { Logs *BoxedString `json:"logs,omitempty"` RestartPolicy string `json:"restartPolicy,omitempty"` ReadinessProbe *Probe `json:"readinessProbe,omitempty"` - Count *BoxedString `json:"count,omitempty"` - MaxCount *BoxedString `json:"maxCount,omitempty"` - // matrix of parameters to spawn instances - Matrix map[string]interface{} `json:"matrix,omitempty"` - // parameters that should be distributed across sharded instances - Shards map[string]interface{} `json:"shards,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_independent_step_parallel.go b/pkg/api/v1/testkube/model_test_workflow_independent_step_parallel.go index 3ca736332e0..c1ac53328aa 100644 --- a/pkg/api/v1/testkube/model_test_workflow_independent_step_parallel.go +++ b/pkg/api/v1/testkube/model_test_workflow_independent_step_parallel.go @@ -28,19 +28,10 @@ type TestWorkflowIndependentStepParallel struct { // delay before the step Delay string `json:"delay,omitempty"` // script to run in a default shell for the container - Shell string `json:"shell,omitempty"` - Run *TestWorkflowStepRun `json:"run,omitempty"` - Execute *TestWorkflowStepExecute `json:"execute,omitempty"` - Artifacts *TestWorkflowStepArtifacts `json:"artifacts,omitempty"` - // how many resources could be scheduled in parallel - Parallelism int32 `json:"parallelism,omitempty"` - // worker description to display - Description string `json:"description,omitempty"` - Logs *BoxedString `json:"logs,omitempty"` - // list of files to send to parallel steps - Transfer []TestWorkflowStepParallelTransfer `json:"transfer,omitempty"` - // list of files to fetch from parallel steps - Fetch []TestWorkflowStepParallelFetch `json:"fetch,omitempty"` + Shell string `json:"shell,omitempty"` + Run *TestWorkflowStepRun `json:"run,omitempty"` + Execute *TestWorkflowStepExecute `json:"execute,omitempty"` + Artifacts *TestWorkflowStepArtifacts `json:"artifacts,omitempty"` Config map[string]TestWorkflowParameterSchema `json:"config,omitempty"` Content *TestWorkflowContent `json:"content,omitempty"` Services map[string]TestWorkflowIndependentServiceSpec `json:"services,omitempty"` @@ -51,4 +42,13 @@ type TestWorkflowIndependentStepParallel struct { Steps []TestWorkflowIndependentStep `json:"steps,omitempty"` After []TestWorkflowIndependentStep `json:"after,omitempty"` Events []TestWorkflowEvent `json:"events,omitempty"` + // how many resources could be scheduled in parallel + Parallelism int32 `json:"parallelism,omitempty"` + // worker description to display + Description string `json:"description,omitempty"` + Logs *BoxedString `json:"logs,omitempty"` + // list of files to send to parallel steps + Transfer []TestWorkflowStepParallelTransfer `json:"transfer,omitempty"` + // list of files to fetch from parallel steps + Fetch []TestWorkflowStepParallelFetch `json:"fetch,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_notifications_config.go b/pkg/api/v1/testkube/model_test_workflow_notifications_config.go new file mode 100644 index 00000000000..14f34fa8dc5 --- /dev/null +++ b/pkg/api/v1/testkube/model_test_workflow_notifications_config.go @@ -0,0 +1,15 @@ +/* + * Testkube API + * + * Testkube provides a Kubernetes-native framework for test definition, execution and results + * + * API version: 1.0.0 + * Contact: testkube@kubeshop.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package testkube + +type TestWorkflowNotificationsConfig struct { + // disable webhooks for this test workflow + DisableWebhooks bool `json:"disableWebhooks,omitempty"` +} diff --git a/pkg/api/v1/testkube/model_test_workflow_service_spec.go b/pkg/api/v1/testkube/model_test_workflow_service_spec.go index ad915dd162e..671cf96a65e 100644 --- a/pkg/api/v1/testkube/model_test_workflow_service_spec.go +++ b/pkg/api/v1/testkube/model_test_workflow_service_spec.go @@ -36,11 +36,11 @@ type TestWorkflowServiceSpec struct { Logs *BoxedString `json:"logs,omitempty"` RestartPolicy string `json:"restartPolicy,omitempty"` ReadinessProbe *Probe `json:"readinessProbe,omitempty"` - Use []TestWorkflowTemplateRef `json:"use,omitempty"` Count *BoxedString `json:"count,omitempty"` MaxCount *BoxedString `json:"maxCount,omitempty"` // matrix of parameters to spawn instances Matrix map[string]interface{} `json:"matrix,omitempty"` // parameters that should be distributed across sharded instances - Shards map[string]interface{} `json:"shards,omitempty"` + Shards map[string]interface{} `json:"shards,omitempty"` + Use []TestWorkflowTemplateRef `json:"use,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_spec.go b/pkg/api/v1/testkube/model_test_workflow_spec.go index dace346a30d..e61d0fe83a5 100644 --- a/pkg/api/v1/testkube/model_test_workflow_spec.go +++ b/pkg/api/v1/testkube/model_test_workflow_spec.go @@ -10,15 +10,16 @@ package testkube type TestWorkflowSpec struct { - Use []TestWorkflowTemplateRef `json:"use,omitempty"` - Config map[string]TestWorkflowParameterSchema `json:"config,omitempty"` - Content *TestWorkflowContent `json:"content,omitempty"` - Services map[string]TestWorkflowServiceSpec `json:"services,omitempty"` - Container *TestWorkflowContainerConfig `json:"container,omitempty"` - Job *TestWorkflowJobConfig `json:"job,omitempty"` - Pod *TestWorkflowPodConfig `json:"pod,omitempty"` - Setup []TestWorkflowStep `json:"setup,omitempty"` - Steps []TestWorkflowStep `json:"steps,omitempty"` - After []TestWorkflowStep `json:"after,omitempty"` - Events []TestWorkflowEvent `json:"events,omitempty"` + Use []TestWorkflowTemplateRef `json:"use,omitempty"` + Config map[string]TestWorkflowParameterSchema `json:"config,omitempty"` + Content *TestWorkflowContent `json:"content,omitempty"` + Services map[string]TestWorkflowServiceSpec `json:"services,omitempty"` + Container *TestWorkflowContainerConfig `json:"container,omitempty"` + Job *TestWorkflowJobConfig `json:"job,omitempty"` + Pod *TestWorkflowPodConfig `json:"pod,omitempty"` + Setup []TestWorkflowStep `json:"setup,omitempty"` + Steps []TestWorkflowStep `json:"steps,omitempty"` + After []TestWorkflowStep `json:"after,omitempty"` + Events []TestWorkflowEvent `json:"events,omitempty"` + Notifications *TestWorkflowNotificationsConfig `json:"notifications,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_step_execute_test_ref.go b/pkg/api/v1/testkube/model_test_workflow_step_execute_test_ref.go index d9943d51ddc..974209ed35b 100644 --- a/pkg/api/v1/testkube/model_test_workflow_step_execute_test_ref.go +++ b/pkg/api/v1/testkube/model_test_workflow_step_execute_test_ref.go @@ -10,16 +10,16 @@ package testkube type TestWorkflowStepExecuteTestRef struct { + Count *BoxedString `json:"count,omitempty"` + MaxCount *BoxedString `json:"maxCount,omitempty"` + // matrix of parameters to spawn instances + Matrix map[string]interface{} `json:"matrix,omitempty"` + // parameters that should be distributed across sharded instances + Shards map[string]interface{} `json:"shards,omitempty"` // test name to schedule Name string `json:"name,omitempty"` // test execution description to display Description string `json:"description,omitempty"` - Count *BoxedString `json:"count,omitempty"` - MaxCount *BoxedString `json:"maxCount,omitempty"` ExecutionRequest *TestWorkflowStepExecuteTestExecutionRequest `json:"executionRequest,omitempty"` Tarball map[string]TestWorkflowTarballRequest `json:"tarball,omitempty"` - // matrix of parameters to spawn instances - Matrix map[string]interface{} `json:"matrix,omitempty"` - // parameters that should be distributed across sharded instances - Shards map[string]interface{} `json:"shards,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_step_execute_test_workflow_ref.go b/pkg/api/v1/testkube/model_test_workflow_step_execute_test_workflow_ref.go index c2bcd5b1d1f..f2e131a22e2 100644 --- a/pkg/api/v1/testkube/model_test_workflow_step_execute_test_workflow_ref.go +++ b/pkg/api/v1/testkube/model_test_workflow_step_execute_test_workflow_ref.go @@ -10,6 +10,12 @@ package testkube type TestWorkflowStepExecuteTestWorkflowRef struct { + Count *BoxedString `json:"count,omitempty"` + MaxCount *BoxedString `json:"maxCount,omitempty"` + // matrix of parameters to spawn instances + Matrix map[string]interface{} `json:"matrix,omitempty"` + // parameters that should be distributed across sharded instances + Shards map[string]interface{} `json:"shards,omitempty"` // TestWorkflow name to include Name string `json:"name,omitempty"` // TestWorkflow execution description to display @@ -18,10 +24,4 @@ type TestWorkflowStepExecuteTestWorkflowRef struct { ExecutionName string `json:"executionName,omitempty"` Tarball map[string]TestWorkflowTarballRequest `json:"tarball,omitempty"` Config map[string]string `json:"config,omitempty"` - Count *BoxedString `json:"count,omitempty"` - MaxCount *BoxedString `json:"maxCount,omitempty"` - // matrix of parameters to spawn instances - Matrix map[string]interface{} `json:"matrix,omitempty"` - // parameters that should be distributed across sharded instances - Shards map[string]interface{} `json:"shards,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_step_parallel.go b/pkg/api/v1/testkube/model_test_workflow_step_parallel.go index d8b4de8e7ff..b296a1e92dc 100644 --- a/pkg/api/v1/testkube/model_test_workflow_step_parallel.go +++ b/pkg/api/v1/testkube/model_test_workflow_step_parallel.go @@ -28,10 +28,22 @@ type TestWorkflowStepParallel struct { // delay before the step Delay string `json:"delay,omitempty"` // script to run in a default shell for the container - Shell string `json:"shell,omitempty"` - Run *TestWorkflowStepRun `json:"run,omitempty"` - Execute *TestWorkflowStepExecute `json:"execute,omitempty"` - Artifacts *TestWorkflowStepArtifacts `json:"artifacts,omitempty"` + Shell string `json:"shell,omitempty"` + Run *TestWorkflowStepRun `json:"run,omitempty"` + Execute *TestWorkflowStepExecute `json:"execute,omitempty"` + Artifacts *TestWorkflowStepArtifacts `json:"artifacts,omitempty"` + Use []TestWorkflowTemplateRef `json:"use,omitempty"` + Config map[string]TestWorkflowParameterSchema `json:"config,omitempty"` + Content *TestWorkflowContent `json:"content,omitempty"` + Services map[string]TestWorkflowServiceSpec `json:"services,omitempty"` + Container *TestWorkflowContainerConfig `json:"container,omitempty"` + Job *TestWorkflowJobConfig `json:"job,omitempty"` + Pod *TestWorkflowPodConfig `json:"pod,omitempty"` + Setup []TestWorkflowStep `json:"setup,omitempty"` + Steps []TestWorkflowStep `json:"steps,omitempty"` + After []TestWorkflowStep `json:"after,omitempty"` + Events []TestWorkflowEvent `json:"events,omitempty"` + Notifications *TestWorkflowNotificationsConfig `json:"notifications,omitempty"` // how many resources could be scheduled in parallel Parallelism int32 `json:"parallelism,omitempty"` // worker description to display @@ -40,17 +52,6 @@ type TestWorkflowStepParallel struct { // list of files to send to parallel steps Transfer []TestWorkflowStepParallelTransfer `json:"transfer,omitempty"` // list of files to fetch from parallel steps - Fetch []TestWorkflowStepParallelFetch `json:"fetch,omitempty"` - Template *TestWorkflowTemplateRef `json:"template,omitempty"` - Use []TestWorkflowTemplateRef `json:"use,omitempty"` - Config map[string]TestWorkflowParameterSchema `json:"config,omitempty"` - Content *TestWorkflowContent `json:"content,omitempty"` - Services map[string]TestWorkflowServiceSpec `json:"services,omitempty"` - Container *TestWorkflowContainerConfig `json:"container,omitempty"` - Job *TestWorkflowJobConfig `json:"job,omitempty"` - Pod *TestWorkflowPodConfig `json:"pod,omitempty"` - Setup []TestWorkflowStep `json:"setup,omitempty"` - Steps []TestWorkflowStep `json:"steps,omitempty"` - After []TestWorkflowStep `json:"after,omitempty"` - Events []TestWorkflowEvent `json:"events,omitempty"` + Fetch []TestWorkflowStepParallelFetch `json:"fetch,omitempty"` + Template *TestWorkflowTemplateRef `json:"template,omitempty"` } diff --git a/pkg/event/kind/webhook/listener.go b/pkg/event/kind/webhook/listener.go index d5337b6f795..bfb37dd3b6f 100644 --- a/pkg/event/kind/webhook/listener.go +++ b/pkg/event/kind/webhook/listener.go @@ -101,6 +101,9 @@ func (l *WebhookListener) Notify(event testkube.Event) (result testkube.EventRes case event.TestSuiteExecution != nil && event.TestSuiteExecution.DisableWebhooks: l.Log.With(event.Log()...).Debug("webhook listener is disabled for test suite execution") return testkube.NewSuccessEventResult(event.Id, "webhook listener is disabled for test suite execution") + case event.TestWorkflowExecution != nil && event.TestWorkflowExecution.DisableWebhooks: + l.Log.With(event.Log()...).Debug("webhook listener is disabled for test workflow execution") + return testkube.NewSuccessEventResult(event.Id, "webhook listener is disabled for test workflow execution") } body := bytes.NewBuffer([]byte{}) diff --git a/pkg/tcl/mapperstcl/testworkflows/kube_openapi.go b/pkg/tcl/mapperstcl/testworkflows/kube_openapi.go index 19a5b2c8f30..7173ab52515 100644 --- a/pkg/tcl/mapperstcl/testworkflows/kube_openapi.go +++ b/pkg/tcl/mapperstcl/testworkflows/kube_openapi.go @@ -1090,17 +1090,18 @@ func MapIndependentStepKubeToAPI(v testworkflowsv1.IndependentStep) testkube.Tes func MapSpecKubeToAPI(v testworkflowsv1.TestWorkflowSpec) testkube.TestWorkflowSpec { return testkube.TestWorkflowSpec{ - Use: common.MapSlice(v.Use, MapTemplateRefKubeToAPI), - Config: common.MapMap(v.Config, MapParameterSchemaKubeToAPI), - Content: common.MapPtr(v.Content, MapContentKubeToAPI), - Services: common.MapMap(v.Services, MapServiceSpecKubeToAPI), - Container: common.MapPtr(v.Container, MapContainerConfigKubeToAPI), - Job: common.MapPtr(v.Job, MapJobConfigKubeToAPI), - Pod: common.MapPtr(v.Pod, MapPodConfigKubeToAPI), - Setup: common.MapSlice(v.Setup, MapStepKubeToAPI), - Steps: common.MapSlice(v.Steps, MapStepKubeToAPI), - After: common.MapSlice(v.After, MapStepKubeToAPI), - Events: common.MapSlice(v.Events, MapEventKubeToAPI), + Use: common.MapSlice(v.Use, MapTemplateRefKubeToAPI), + Config: common.MapMap(v.Config, MapParameterSchemaKubeToAPI), + Content: common.MapPtr(v.Content, MapContentKubeToAPI), + Services: common.MapMap(v.Services, MapServiceSpecKubeToAPI), + Container: common.MapPtr(v.Container, MapContainerConfigKubeToAPI), + Job: common.MapPtr(v.Job, MapJobConfigKubeToAPI), + Pod: common.MapPtr(v.Pod, MapPodConfigKubeToAPI), + Setup: common.MapSlice(v.Setup, MapStepKubeToAPI), + Steps: common.MapSlice(v.Steps, MapStepKubeToAPI), + After: common.MapSlice(v.After, MapStepKubeToAPI), + Events: common.MapSlice(v.Events, MapEventKubeToAPI), + Notifications: common.MapPtr(v.Notifications, MapNotificationsConfigKubeToAPI), } } @@ -1165,3 +1166,9 @@ func MapTemplateListKubeToAPI(v *testworkflowsv1.TestWorkflowTemplateList) []tes } return workflows } + +func MapNotificationsConfigKubeToAPI(v testworkflowsv1.NotificationsConfig) testkube.TestWorkflowNotificationsConfig { + return testkube.TestWorkflowNotificationsConfig{ + DisableWebhooks: v.DisableWebhooks, + } +} diff --git a/pkg/tcl/mapperstcl/testworkflows/openapi_kube.go b/pkg/tcl/mapperstcl/testworkflows/openapi_kube.go index dcaa4cdeb1a..b13c7061373 100644 --- a/pkg/tcl/mapperstcl/testworkflows/openapi_kube.go +++ b/pkg/tcl/mapperstcl/testworkflows/openapi_kube.go @@ -916,11 +916,12 @@ func MapStepParallelAPIToKube(v testkube.TestWorkflowStepParallel) testworkflows Fetch: common.MapSlice(v.Fetch, MapStepParallelFetchAPIToKube), TestWorkflowSpec: testworkflowsv1.TestWorkflowSpec{ TestWorkflowSpecBase: testworkflowsv1.TestWorkflowSpecBase{ - Config: common.MapMap(v.Config, MapParameterSchemaAPIToKube), - Content: common.MapPtr(v.Content, MapContentAPIToKube), - Container: common.MapPtr(v.Container, MapContainerConfigAPIToKube), - Job: common.MapPtr(v.Job, MapJobConfigAPIToKube), - Pod: common.MapPtr(v.Pod, MapPodConfigAPIToKube), + Config: common.MapMap(v.Config, MapParameterSchemaAPIToKube), + Content: common.MapPtr(v.Content, MapContentAPIToKube), + Container: common.MapPtr(v.Container, MapContainerConfigAPIToKube), + Job: common.MapPtr(v.Job, MapJobConfigAPIToKube), + Pod: common.MapPtr(v.Pod, MapPodConfigAPIToKube), + Notifications: common.MapPtr(v.Notifications, MapNotificationsAPIToKube), }, Use: common.MapSlice(v.Use, MapTemplateRefAPIToKube), Setup: common.MapSlice(v.Setup, MapStepAPIToKube), @@ -1432,3 +1433,9 @@ func MapTestWorkflowAPIToKubeTestWorkflowSummary(v testkube.TestWorkflow) testwo Annotations: v.Annotations, } } + +func MapNotificationsAPIToKube(v testkube.TestWorkflowNotificationsConfig) testworkflowsv1.NotificationsConfig { + return testworkflowsv1.NotificationsConfig{ + DisableWebhooks: v.DisableWebhooks, + } +} diff --git a/pkg/tcl/testworkflowstcl/testworkflowexecutor/executor.go b/pkg/tcl/testworkflowstcl/testworkflowexecutor/executor.go index bcef240dc28..496a5815818 100644 --- a/pkg/tcl/testworkflowstcl/testworkflowexecutor/executor.go +++ b/pkg/tcl/testworkflowstcl/testworkflowexecutor/executor.go @@ -382,6 +382,11 @@ func (e *executor) Execute(ctx context.Context, workflow testworkflowsv1.TestWor return execution, fmt.Errorf("not supported execution namespace %s", namespace) } + disableWebhooks := request.DisableWebhooks + if !disableWebhooks && workflow.Spec.Notifications != nil { + disableWebhooks = workflow.Spec.Notifications.DisableWebhooks + } + // Build the basic Execution data id := primitive.NewObjectID().Hex() now := time.Now() @@ -503,6 +508,7 @@ func (e *executor) Execute(ctx context.Context, workflow testworkflowsv1.TestWor Workflow: testworkflowmappers.MapKubeToAPI(initialWorkflow), ResolvedWorkflow: testworkflowmappers.MapKubeToAPI(resolvedWorkflow), TestWorkflowExecutionName: testWorkflowExecutionName, + DisableWebhooks: disableWebhooks, } err = e.repository.Insert(ctx, execution) if err != nil {