Skip to content

Commit

Permalink
featL refactor disable webhooks
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Jul 11, 2024
1 parent 080f05c commit 2dc5cb8
Show file tree
Hide file tree
Showing 26 changed files with 14 additions and 141 deletions.
4 changes: 0 additions & 4 deletions cmd/kubectl-testkube/commands/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ func ProcessMasterFlags(cmd *cobra.Command, opts *HelmOptions, cfg *config.Data)

}

func IsBothEnabledAndDisabledSet(cmd *cobra.Command) bool {
return cmd.Flag("enable-webhooks").Changed && cmd.Flag("disable-webhooks").Changed
}

// CommaList is a custom flag type for features
type CommaList []string

Expand Down
18 changes: 0 additions & 18 deletions cmd/kubectl-testkube/commands/tests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,6 @@ func newExecutionRequestFromFlags(cmd *cobra.Command) (request *testkube.Executi
return nil, err
}

if cmd.Flag("enable-webhooks").Changed {
request.DisableWebhooks = false
}
if cmd.Flag("disable-webhooks").Changed {
request.DisableWebhooks = true
}

return request, nil
}

Expand Down Expand Up @@ -1255,17 +1248,6 @@ func newExecutionUpdateRequestFromFlags(cmd *cobra.Command) (request *testkube.E
request.SlavePodRequest = &emptyPodRequest
}

disableWebhooks := false
if cmd.Flag("enable-webhooks").Changed {
request.DisableWebhooks = &disableWebhooks
nonEmpty = true
}
if cmd.Flag("disable-webhooks").Changed {
disableWebhooks = true
request.DisableWebhooks = &disableWebhooks
nonEmpty = true
}

if nonEmpty {
return request, nil
}
Expand Down
6 changes: 0 additions & 6 deletions cmd/kubectl-testkube/commands/tests/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ func NewCreateTestsCmd() *cobra.Command {
ui.Failf("pass valid test name (in '--name' flag)")
}

if common.IsBothEnabledAndDisabledSet(cmd) {
ui.Failf("both --enable-webhooks and --disable-webhooks flags are set, please use only one")
}

namespace := cmd.Flag("namespace").Value.String()
var client client.Client
if !crdOnly {
Expand Down Expand Up @@ -288,8 +284,6 @@ func AddCreateFlags(cmd *cobra.Command, flags *CreateCommonFlags) {
cmd.Flags().StringVar(&flags.SlavePodTemplate, "slave-pod-template", "", "slave pod template file path for extensions to slave pod template")
cmd.Flags().StringVar(&flags.SlavePodTemplateReference, "slave-pod-template-reference", "", "reference to slave pod template to use for the test")
cmd.Flags().StringVar(&flags.ExecutionNamespace, "execution-namespace", "", "namespace for test execution (Pro edition only)")
cmd.Flags().Bool("disable-webhooks", false, "disable webhooks")
cmd.Flags().Bool("enable-webhooks", false, "enable webhooks")
}

func validateExecutorTypeAndContent(executorType, contentType string, executors testkube.ExecutorsDetails) error {
Expand Down
4 changes: 0 additions & 4 deletions cmd/kubectl-testkube/commands/tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ func NewRunTestCmd() *cobra.Command {
watchEnabled = true
}

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 Down
4 changes: 0 additions & 4 deletions cmd/kubectl-testkube/commands/tests/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func NewUpdateTestsCmd() *cobra.Command {
ui.Failf("pass valid test name (in '--name' flag)")
}

if common.IsBothEnabledAndDisabledSet(cmd) {
ui.Failf("both --enable-webhooks and --disable-webhooks flags are set, please use only one")
}

client, namespace, err := common.GetClient(cmd)
ui.ExitOnError("getting client", err)

Expand Down
27 changes: 0 additions & 27 deletions cmd/kubectl-testkube/commands/testsuites/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ func uiShellTestSuiteWatchCommandBlock(id string) {

// NewTestSuiteUpsertOptionsFromFlags creates test suite upsert options from command flags
func NewTestSuiteUpsertOptionsFromFlags(cmd *cobra.Command) (options apiclientv1.UpsertTestSuiteOptions, err error) {
if common.IsBothEnabledAndDisabledSet(cmd) {
ui.Failf("both --enable-webhooks and --disable-webhooks flags are set, please use only one")
}

data, err := common.NewDataFromFlags(cmd)
if err != nil {
return options, err
Expand Down Expand Up @@ -260,22 +256,11 @@ func NewTestSuiteUpsertOptionsFromFlags(cmd *cobra.Command) (options apiclientv1
}
}

if cmd.Flag("enable-webhooks").Changed {
options.ExecutionRequest.DisableWebhooks = false
}
if cmd.Flag("disable-webhooks").Changed {
options.ExecutionRequest.DisableWebhooks = true
}

return options, nil
}

// NewTestSuiteUpdateOptionsFromFlags creates test suite update options from command flags
func NewTestSuiteUpdateOptionsFromFlags(cmd *cobra.Command) (options apiclientv1.UpdateTestSuiteOptions, err error) {
if common.IsBothEnabledAndDisabledSet(cmd) {
ui.Failf("both --enable-webhooks and --disable-webhooks flags are set, please use only one")
}

data, err := common.NewDataFromFlags(cmd)
if err != nil {
return options, err
Expand Down Expand Up @@ -379,18 +364,6 @@ func NewTestSuiteUpdateOptionsFromFlags(cmd *cobra.Command) (options apiclientv1
nonEmpty = true
}

var disableWebhook bool
if cmd.Flag("enable-webhooks").Changed {
nonEmpty = true
disableWebhook = false
executionRequest.DisableWebhooks = &disableWebhook
}
if cmd.Flag("disable-webhooks").Changed {
nonEmpty = true
disableWebhook = true
executionRequest.DisableWebhooks = &disableWebhook
}

var values = []struct {
source string
destination **string
Expand Down
2 changes: 0 additions & 2 deletions cmd/kubectl-testkube/commands/testsuites/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ func NewCreateTestSuitesCmd() *cobra.Command {
cmd.Flags().StringVar(&scraperTemplateReference, "scraper-template-reference", "", "reference to scraper template to use for the test")
cmd.Flags().StringVar(&pvcTemplateReference, "pvc-template-reference", "", "reference to pvc template to use for the test")
cmd.Flags().BoolVar(&update, "update", false, "update, if test suite already exists")
cmd.Flags().Bool("disable-webhooks", false, "disable webhooks")
cmd.Flags().Bool("enable-webhooks", false, "enable webhooks")

return cmd
}
Expand Down
16 changes: 3 additions & 13 deletions cmd/kubectl-testkube/commands/testsuites/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func NewRunTestSuiteCmd() *cobra.Command {
format string
masks []string
silentMode bool
disableWebhooks bool
)

cmd := &cobra.Command{
Expand All @@ -67,10 +68,6 @@ func NewRunTestSuiteCmd() *cobra.Command {
client, namespace, err := common.GetClient(cmd)
ui.ExitOnError("getting client", err)

if common.IsBothEnabledAndDisabledSet(cmd) {
ui.Failf("both --enable-webhooks and --disable-webhooks flags are set, please use only one")
}

var executions []testkube.TestSuiteExecution

options := apiv1.ExecuteTestSuiteOptions{
Expand All @@ -85,13 +82,7 @@ func NewRunTestSuiteCmd() *cobra.Command {
JobTemplateReference: jobTemplateReference,
ScraperTemplateReference: scraperTemplateReference,
PvcTemplateReference: pvcTemplateReference,
}

if cmd.Flag("enable-webhooks").Changed {
options.DisableWebhooks = false
}
if cmd.Flag("disable-webhooks").Changed {
options.DisableWebhooks = true
DisableWebhooks: disableWebhooks,
}

var fields = []struct {
Expand Down Expand Up @@ -245,8 +236,7 @@ func NewRunTestSuiteCmd() *cobra.Command {
cmd.Flags().StringVar(&format, "format", "folder", "data format for storing files, one of folder|archive")
cmd.Flags().StringArrayVarP(&masks, "mask", "", []string{}, "regexp to filter downloaded files, single or comma separated, like report/.* or .*\\.json,.*\\.js$")
cmd.Flags().BoolVarP(&silentMode, "silent", "", false, "don't print intermediate test suite execution")
cmd.Flags().Bool("disable-webhooks", false, "disable webhooks")
cmd.Flags().Bool("enable-webhooks", false, "enable webhooks")
cmd.Flags().BoolVar(&disableWebhooks, "disable-webhooks", false, "disable webhooks")

return cmd
}
2 changes: 0 additions & 2 deletions cmd/kubectl-testkube/commands/testsuites/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ func UpdateTestSuitesCmd() *cobra.Command {
cmd.Flags().StringVar(&cronJobTemplateReference, "cronjob-template-reference", "", "reference to cron job template to use for the test")
cmd.Flags().StringVar(&scraperTemplateReference, "scraper-template-reference", "", "reference to scraper template to use for the test")
cmd.Flags().StringVar(&pvcTemplateReference, "pvc-template-reference", "", "reference to pvc template to use for the test")
cmd.Flags().Bool("disable-webhooks", false, "disable webhooks")
cmd.Flags().Bool("enable-webhooks", false, "enable webhooks")

return cmd
}
22 changes: 5 additions & 17 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ var (

func NewRunTestWorkflowCmd() *cobra.Command {
var (
executionName string
config map[string]string
watchEnabled bool
executionName string
config map[string]string
watchEnabled bool
disableWebhooks bool
)

cmd := &cobra.Command{
Expand All @@ -43,10 +44,6 @@ 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 @@ -58,14 +55,6 @@ 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,
Expand Down Expand Up @@ -114,8 +103,7 @@ 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")
cmd.Flags().BoolVar(&disableWebhooks, "disable-webhooks", false, "disable webhooks for this execution")

return cmd
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/tcl/testworkflow-toolkit/commands/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ func buildTestExecution(test testworkflowsv1.StepExecuteTest, async, disableWebh
}, nil
}

func buildWorkflowExecution(workflow testworkflowsv1.StepExecuteWorkflow, async bool) (func() error, error) {
func buildWorkflowExecution(workflow testworkflowsv1.StepExecuteWorkflow, async, disableWebhooks 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),
Name: workflow.ExecutionName,
Config: testworkflows.MapConfigValueKubeToAPI(workflow.Config),
DisableWebhooks: disableWebhooks,
})
execName := exec.Name
if err != nil {
Expand Down Expand Up @@ -346,7 +347,7 @@ func NewExecuteCmd() *cobra.Command {
if err != nil {
ui.Fail(errors.Wrapf(err, "'%s' workflow: computing execution", spec.Name))
}
fn, err := buildWorkflowExecution(*spec, async)
fn, err := buildWorkflowExecution(*spec, async, disableWebhooks)
if err != nil {
ui.Fail(err)
}
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/cli/testkube_create_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ testkube create test [flags]
--cronjob-template string cron job template file path for extensions to cron job template
--cronjob-template-reference string reference to cron job template to use for the test
--description string test description
--disable-webhooks disable webhooks
--enable-webhooks enable webhooks
--env stringToString envs in a form of name1=val1 passed to executor (default [])
--execute-postrun-script-before-scraping whether to execute postrun scipt before scraping or not (prebuilt executor only)
--execution-name string execution name, if empty will be autogenerated
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/cli/testkube_create_testsuite.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ testkube create testsuite [flags]
```
--cronjob-template string cron job template file path for extensions to cron job template
--cronjob-template-reference string reference to cron job template to use for the test
--disable-webhooks disable webhooks
--enable-webhooks enable webhooks
--execution-name string execution name, if empty will be autogenerated
-f, --file string JSON test suite file - will be read from stdin if not specified, look at testkube.TestUpsertRequest
-h, --help help for testsuite
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/cli/testkube_generate_tests-crds.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ testkube generate tests-crds <manifestDirectory> [flags]
--cronjob-template string cron job template file path for extensions to cron job template
--cronjob-template-reference string reference to cron job template to use for the test
--description string test description
--disable-webhooks disable webhooks
--enable-webhooks enable webhooks
--env stringToString envs in a form of name1=val1 passed to executor (default [])
--execute-postrun-script-before-scraping whether to execute postrun scipt before scraping or not (prebuilt executor only)
--execution-name string execution name, if empty will be autogenerated
Expand Down
1 change: 0 additions & 1 deletion docs/docs/cli/testkube_run_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ testkube run test <testName> [flags]
--disable-webhooks disable webhooks
-d, --download-artifacts download artifacts automatically
--download-dir string download dir (default "artifacts")
--enable-webhooks enable webhooks
--execute-postrun-script-before-scraping whether to execute postrun scipt before scraping or not (prebuilt executor only)
--execution-label stringToString execution-label key value pair: --execution-label key1=value1 (default [])
--execution-namespace string namespace for test execution (Pro edition only)
Expand Down
1 change: 0 additions & 1 deletion docs/docs/cli/testkube_run_testsuite.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ testkube run testsuite <testSuiteName> [flags]
--disable-webhooks disable webhooks
-d, --download-artifacts download artifacts automatically
--download-dir string download dir (default "artifacts")
--enable-webhooks enable webhooks
--execution-label stringToString execution-label adds a label to execution in form of key value pair: --execution-label key1=value1 (default [])
--format string data format for storing files, one of folder|archive (default "folder")
--git-branch string if uri is git repository we can set additional branch parameter
Expand Down
1 change: 0 additions & 1 deletion docs/docs/cli/testkube_run_testworkflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ testkube run testworkflow [name] [flags]
```
--config stringToString configuration variables in a form of name1=val1 passed to executor (default [])
--disable-webhooks disable webhooks for this execution
--enable-webhooks enable webhooks for this execution
-h, --help help for testworkflow
-n, --name string execution name, if empty will be autogenerated
-f, --watch watch for changes after start
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/cli/testkube_update_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ testkube update test [flags]
--cronjob-template string cron job template file path for extensions to cron job template
--cronjob-template-reference string reference to cron job template to use for the test
--description string test description
--disable-webhooks disable webhooks
--enable-webhooks enable webhooks
--env stringToString envs in a form of name1=val1 passed to executor (default [])
--execute-postrun-script-before-scraping whether to execute postrun scipt before scraping or not (prebuilt executor only)
--execution-name string execution name, if empty will be autogenerated
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/cli/testkube_update_testsuite.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ testkube update testsuite [flags]
```
--cronjob-template string cron job template file path for extensions to cron job template
--cronjob-template-reference string reference to cron job template to use for the test
--disable-webhooks disable webhooks
--enable-webhooks enable webhooks
--execution-name string execution name, if empty will be autogenerated
-f, --file string JSON test file - will be read from stdin if not specified, look at testkube.TestUpsertRequest
-h, --help help for testsuite
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1/testkube/model_test_suite_execution_extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func NewStartedTestSuiteExecution(testSuite TestSuite, request TestSuiteExecutio
Variables: map[string]Variable{},
RunningContext: request.RunningContext,
TestSuiteExecutionName: request.TestSuiteExecutionName,
DisableWebhooks: request.DisableWebhooks,
}

if testSuite.ExecutionRequest != nil {
testExecution.Variables = testSuite.ExecutionRequest.Variables
testExecution.DisableWebhooks = testSuite.ExecutionRequest.DisableWebhooks
}

// override variables from request
Expand Down
2 changes: 0 additions & 2 deletions pkg/mapper/tests/kube_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func MapExecutionRequestFromSpec(specExecutionRequest *testsv3.ExecutionRequest)
EnvConfigMaps: MapEnvReferences(specExecutionRequest.EnvConfigMaps),
EnvSecrets: MapEnvReferences(specExecutionRequest.EnvSecrets),
SlavePodRequest: podRequest,
DisableWebhooks: specExecutionRequest.DisableWebhooks,
}

// Pro edition only (tcl protected code)
Expand Down Expand Up @@ -527,7 +526,6 @@ func MapSpecExecutionRequestToExecutionUpdateRequest(
executionRequest.EnvSecrets = &envSecrets
executionRequest.ExecutePostRunScriptBeforeScraping = &request.ExecutePostRunScriptBeforeScraping
executionRequest.SourceScripts = &request.SourceScripts
executionRequest.DisableWebhooks = &request.DisableWebhooks

// Pro edition only (tcl protected code)
mappertcl.MapSpecExecutionRequestToExecutionUpdateRequest(request, executionRequest)
Expand Down
6 changes: 0 additions & 6 deletions pkg/mapper/tests/openapi_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func MapExecutionRequestToSpecExecutionRequest(executionRequest *testkube.Execut
EnvConfigMaps: mapEnvReferences(executionRequest.EnvConfigMaps),
EnvSecrets: mapEnvReferences(executionRequest.EnvSecrets),
SlavePodRequest: podRequest,
DisableWebhooks: executionRequest.DisableWebhooks,
}

// Pro edition only (tcl protected code)
Expand Down Expand Up @@ -635,11 +634,6 @@ func MapExecutionUpdateRequestToSpecExecutionRequest(executionRequest *testkube.
emptyExecution = false
}

if executionRequest.DisableWebhooks != nil {
request.DisableWebhooks = *executionRequest.DisableWebhooks
emptyExecution = false
}

// Pro edition only (tcl protected code)
if !mappertcl.MapExecutionUpdateRequestToSpecExecutionRequest(executionRequest, request) {
emptyExecution = false
Expand Down
Loading

0 comments on commit 2dc5cb8

Please sign in to comment.