Skip to content

Commit

Permalink
feat: [TKC-1948] disable workflow webhooks (#5550)
Browse files Browse the repository at this point in the history
* feat: disable workflow webhooks on execution

* feat: disable workflow webhooks

* fix: use correct data type

* feat: update operator dependency
  • Loading branch information
vLia authored Jun 7, 2024
1 parent 11d3271 commit cd50ec5
Show file tree
Hide file tree
Showing 21 changed files with 183 additions and 88 deletions.
26 changes: 26 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -8146,6 +8157,9 @@ components:
type: array
items:
$ref: "#/components/schemas/TestWorkflowEvent"
notifications:
$ref: "#/components/schemas/TestWorkflowNotificationsConfig"


TestWorkflowTemplateSpec:
type: object
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cmd/kubectl-testkube/commands/testworkflows/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
19 changes: 17 additions & 2 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}
Expand Down
15 changes: 9 additions & 6 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 bool) (func() error, error) {
func buildTestExecution(test testworkflowsv1.StepExecuteTest, async, disableWebhooks bool) (func() error, error) {
return func() (err error) {
c := env.Testkube()

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -407,6 +409,7 @@ 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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
2 changes: 2 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_execution_cr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
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 @@ -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"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
}
15 changes: 15 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_notifications_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Testkube API
*
* Testkube provides a Kubernetes-native framework for test definition, execution and results
*
* API version: 1.0.0
* Contact: [email protected]
* 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"`
}
4 changes: 2 additions & 2 deletions pkg/api/v1/testkube/model_test_workflow_service_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
23 changes: 12 additions & 11 deletions pkg/api/v1/testkube/model_test_workflow_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
12 changes: 6 additions & 6 deletions pkg/api/v1/testkube/model_test_workflow_step_execute_test_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}
Loading

0 comments on commit cd50ec5

Please sign in to comment.