Skip to content

Commit

Permalink
fix: remove enable flag
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Jul 12, 2024
1 parent 235e03d commit 11cbc23
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 38 deletions.
28 changes: 11 additions & 17 deletions cmd/kubectl-testkube/commands/webhooks/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
16 changes: 3 additions & 13 deletions cmd/kubectl-testkube/commands/webhooks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewCreateWebhookCmd() *cobra.Command {
headers map[string]string
payloadTemplateReference string
update bool
disable bool
onStateChange bool
)

Expand All @@ -39,24 +40,13 @@ 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 {
client, namespace, err = common.GetClient(cmd)
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 {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions cmd/kubectl-testkube/commands/webhooks/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func UpdateWebhookCmd() *cobra.Command {
payloadTemplate string
headers map[string]string
payloadTemplateReference string
enable bool
disable bool
onStateChange bool
)
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion docs/docs/cli/testkube_create_webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion docs/docs/cli/testkube_update_webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11cbc23

Please sign in to comment.