diff --git a/cmd/kubectl-testkube/commands/webhooks/common.go b/cmd/kubectl-testkube/commands/webhooks/common.go index 561355417d7..15c4262b460 100644 --- a/cmd/kubectl-testkube/commands/webhooks/common.go +++ b/cmd/kubectl-testkube/commands/webhooks/common.go @@ -47,6 +47,11 @@ func NewCreateWebhookOptionsFromFlags(cmd *cobra.Command) (options apiv1.CreateW return options, err } + disabled, err := cmd.Flags().GetBool("disable") + if err != nil { + return options, err + } + payloadTemplateReference := cmd.Flag("payload-template-reference").Value.String() options = apiv1.CreateWebhookOptions{ Name: name, @@ -60,13 +65,7 @@ func NewCreateWebhookOptionsFromFlags(cmd *cobra.Command) (options apiv1.CreateW Headers: headers, PayloadTemplateReference: payloadTemplateReference, OnStateChange: onStateChange, - } - - if cmd.Flag("enable").Changed { - options.Disabled = false - } - if cmd.Flag("disable").Changed { - options.Disabled = true + Disabled: disabled, } return options, nil @@ -150,13 +149,12 @@ func NewUpdateWebhookOptionsFromFlags(cmd *cobra.Command) (options apiv1.UpdateW options.Headers = &headers } - if cmd.Flag("enable").Changed { - options.Disabled = new(bool) - *options.Disabled = false - } if cmd.Flag("disable").Changed { - options.Disabled = new(bool) - *options.Disabled = true + disabled, err := cmd.Flags().GetBool("disable") + if err != nil { + return options, err + } + options.Disabled = &disabled } if cmd.Flag("on-state-change").Changed { @@ -169,7 +167,3 @@ func NewUpdateWebhookOptionsFromFlags(cmd *cobra.Command) (options apiv1.UpdateW return options, nil } - -func isBothEnabledAndDisabledSet(cmd *cobra.Command) bool { - return cmd.Flag("enable").Changed && cmd.Flag("disable").Changed -} diff --git a/cmd/kubectl-testkube/commands/webhooks/create.go b/cmd/kubectl-testkube/commands/webhooks/create.go index 5727c23cfdc..4bf8d798e2b 100644 --- a/cmd/kubectl-testkube/commands/webhooks/create.go +++ b/cmd/kubectl-testkube/commands/webhooks/create.go @@ -23,6 +23,7 @@ func NewCreateWebhookCmd() *cobra.Command { headers map[string]string payloadTemplateReference string update bool + disable bool onStateChange bool ) @@ -39,10 +40,6 @@ func NewCreateWebhookCmd() *cobra.Command { ui.Failf("pass valid name (in '--name' flag)") } - if isBothEnabledAndDisabledSet(cmd) { - ui.Failf("both --enable and --disable flags are set, please use only one") - } - namespace := cmd.Flag("namespace").Value.String() var client apiv1.Client if !crdOnly { @@ -50,13 +47,6 @@ func NewCreateWebhookCmd() *cobra.Command { ui.ExitOnError("getting client", err) webhook, _ := client.GetWebhook(name) - if cmd.Flag("enable").Changed { - webhook.Disabled = false - } - if cmd.Flag("disable").Changed { - webhook.Disabled = true - } - if name == webhook.Name { if cmd.Flag("update").Changed { if !update { @@ -111,8 +101,8 @@ func NewCreateWebhookCmd() *cobra.Command { cmd.Flags().StringToStringVarP(&headers, "header", "", nil, "webhook header value pair (golang template supported): --header Content-Type=application/xml") cmd.Flags().StringVar(&payloadTemplateReference, "payload-template-reference", "", "reference to payload template to use for the webhook") cmd.Flags().BoolVar(&update, "update", false, "update, if webhook already exists") - cmd.Flags().Bool("disable", false, "disable webhook") - cmd.Flags().Bool("enable", false, "enable webhook") + cmd.Flags().BoolVar(&disable, "disable", false, "disable webhook") + cmd.Flags().MarkDeprecated("enable", "enable webhook is deprecated") cmd.Flags().BoolVar(&onStateChange, "on-state-change", false, "specify whether webhook should be triggered only on a state change") return cmd diff --git a/cmd/kubectl-testkube/commands/webhooks/update.go b/cmd/kubectl-testkube/commands/webhooks/update.go index 2f3f9405f5f..90ff196ea66 100644 --- a/cmd/kubectl-testkube/commands/webhooks/update.go +++ b/cmd/kubectl-testkube/commands/webhooks/update.go @@ -17,7 +17,6 @@ func UpdateWebhookCmd() *cobra.Command { payloadTemplate string headers map[string]string payloadTemplateReference string - enable bool disable bool onStateChange bool ) @@ -32,10 +31,6 @@ func UpdateWebhookCmd() *cobra.Command { ui.Failf("pass valid name (in '--name' flag)") } - if isBothEnabledAndDisabledSet(cmd) { - ui.Failf("both --enable and --disable flags are set, please use only one") - } - client, namespace, err := common.GetClient(cmd) ui.ExitOnError("getting client", err) @@ -64,7 +59,7 @@ func UpdateWebhookCmd() *cobra.Command { cmd.Flags().StringToStringVarP(&headers, "header", "", nil, "webhook header value pair (golang template supported): --header Content-Type=application/xml") cmd.Flags().StringVar(&payloadTemplateReference, "payload-template-reference", "", "reference to payload template to use for the webhook") cmd.Flags().BoolVar(&disable, "disable", false, "disable webhook") - cmd.Flags().BoolVar(&enable, "enable", false, "enable webhook") + cmd.Flags().MarkDeprecated("enable", "enable webhook is depecated") cmd.Flags().BoolVar(&onStateChange, "on-state-change", false, "specify whether webhook should be triggered only on a state change") return cmd diff --git a/docs/docs/cli/testkube_create_webhook.md b/docs/docs/cli/testkube_create_webhook.md index 9162f023c09..08897f7f0d4 100644 --- a/docs/docs/cli/testkube_create_webhook.md +++ b/docs/docs/cli/testkube_create_webhook.md @@ -14,7 +14,6 @@ testkube create webhook [flags] ``` --disable disable webhook - --enable enable webhook -e, --events stringArray event types handled by webhook e.g. start-test|end-test --header stringToString webhook header value pair (golang template supported): --header Content-Type=application/xml (default []) -h, --help help for webhook diff --git a/docs/docs/cli/testkube_update_webhook.md b/docs/docs/cli/testkube_update_webhook.md index ef33811851c..1bb3168c87e 100644 --- a/docs/docs/cli/testkube_update_webhook.md +++ b/docs/docs/cli/testkube_update_webhook.md @@ -14,7 +14,6 @@ testkube update webhook [flags] ``` --disable disable webhook - --enable enable webhook -e, --events stringArray event types handled by webhook e.g. start-test|end-test --header stringToString webhook header value pair (golang template supported): --header Content-Type=application/xml (default []) -h, --help help for webhook