Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [TKC-2208] refactor webhook disabling #5658

Merged
merged 18 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6595,7 +6595,7 @@ components:
description: running context for the test execution
disableWebhooks:
type: boolean
description: whether webhooks on the executions of this step are disabled
description: whether webhooks on the execution of this step are disabled
default: false
example:
- true
Expand Down Expand Up @@ -6703,7 +6703,7 @@ components:
description: test suite execution name started the test suite execution
disableWebhooks:
type: boolean
description: whether webhooks on the executions of this test suite are disabled
description: whether webhooks on the execution of this test suite are disabled
default: false
example:
- true
Expand Down Expand Up @@ -7872,7 +7872,7 @@ components:
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
description: whether webhooks on the execution of this test workflow are disabled
default: false

TestWorkflowWithExecution:
Expand Down Expand Up @@ -7960,7 +7960,7 @@ components:
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
description: whether webhooks on the execution of this test workflow are disabled
default: false
example:
- true
Expand Down Expand Up @@ -8500,9 +8500,6 @@ components:
type: array
items:
$ref: "#/components/schemas/TestWorkflowEvent"
notifications:
$ref: "#/components/schemas/TestWorkflowNotificationsConfig"


TestWorkflowTemplateSpec:
type: object
Expand Down Expand Up @@ -9175,14 +9172,6 @@ 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 @@ -9350,10 +9339,6 @@ 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
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
8 changes: 2 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,8 @@ 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")
cmd.Flags().MarkDeprecated("disable-webhooks", "disable-webhooks is deprecated")
cmd.Flags().MarkDeprecated("enable-webhooks", "enable-webhooks is deprecated")
}

func validateExecutorTypeAndContent(executorType, contentType string, executors testkube.ExecutorsDetails) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func ExecutionRenderer(client client.Client, ui *ui.UI, obj interface{}) error {
ui.Warn(" Auth type: ", execution.Content.Repository.AuthType)
}

ui.Warn("Disabled webhooks:", fmt.Sprint(execution.DisableWebhooks))
if err := render.RenderExecutionResult(client, &execution, false, true); err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/kubectl-testkube/commands/tests/renderer/test_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ func TestRenderer(client client.Client, ui *ui.UI, obj interface{}) error {
ui.NL()
ui.Warn(" Variable secrets: ", variableSecrets...)
}

ui.Warn(" Disable webhooks: ", fmt.Sprint(test.ExecutionRequest.DisableWebhooks))
}

return nil
Expand Down
17 changes: 4 additions & 13 deletions cmd/kubectl-testkube/commands/tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func NewRunTestCmd() *cobra.Command {
executionNamespace string
attachDebugger bool
debugFile string
disableWebhooks bool
)

cmd := &cobra.Command{
Expand All @@ -95,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 Expand Up @@ -150,13 +147,7 @@ func NewRunTestCmd() *cobra.Command {
ExecutePostRunScriptBeforeScraping: executePostRunScriptBeforeScraping,
SourceScripts: sourceScripts,
ExecutionNamespace: executionNamespace,
}

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 @@ -480,8 +471,8 @@ func NewRunTestCmd() *cobra.Command {
cmd.Flags().StringVar(&executionNamespace, "execution-namespace", "", "namespace for test execution (Pro edition only)")
cmd.Flags().StringVar(&debugFile, "debugger-file", "", "store debug info into file, stdout by default")
cmd.Flags().BoolVar(&attachDebugger, "attach-debugger", false, "attach simple debugger for job, need KUBECONFIG for the agent to be active")
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")
cmd.Flags().MarkDeprecated("enable-webhooks", "enable-webhooks is deprecated")

return cmd
}
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
4 changes: 2 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,8 @@ 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")
cmd.Flags().MarkDeprecated("disable-webhooks", "disable-webhooks is deprecated")
cmd.Flags().MarkDeprecated("enable-webhooks", "enable-webhooks is deprecated")

return cmd
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestSuiteExecutionRenderer(client client.Client, ui *ui.UI, obj interface{}
ui.Warn("Context:", execution.RunningContext.Context)
}

ui.Warn("Disabled webhooks:", fmt.Sprint(execution.DisableWebhooks))
info, err := client.GetServerInfo()
ui.ExitOnError("getting server info", err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func TestSuiteRenderer(client client.Client, ui *ui.UI, obj interface{}) error {
if ts.ExecutionRequest.PvcTemplateReference != "" {
ui.Warn(" PVC template reference: ", ts.ExecutionRequest.PvcTemplateReference)
}
ui.Warn(" Disable webhooks: ", fmt.Sprint(ts.ExecutionRequest.DisableWebhooks))
}

batches := append(ts.Before, ts.Steps...)
Expand Down
17 changes: 4 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,8 @@ 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")
cmd.Flags().MarkDeprecated("enable-webhooks", "enable-webhooks is deprecated")

return cmd
}
4 changes: 2 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,8 @@ 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")
cmd.Flags().MarkDeprecated("disable-webhooks", "disable-webhooks is deprecated")
cmd.Flags().MarkDeprecated("enable-webhooks", "enable-webhooks is deprecated")

return cmd
}
8 changes: 1 addition & 7 deletions cmd/kubectl-testkube/commands/testworkflows/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ func NewCreateTestWorkflowCmd() *cobra.Command {
client, _, err := common.GetClient(cmd)
ui.ExitOnError("getting client", err)

if cmd.Flag("disable-webhooks").Changed {
obj.Spec.Notifications = &testworkflowsv1.NotificationsConfig{
DisableWebhooks: true,
}
}

workflow, err := client.GetTestWorkflow(obj.Name)
if err != nil {
if update {
Expand Down Expand Up @@ -94,7 +88,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")
cmd.Flags().MarkDeprecated("disable-webhooks", "disable-webhooks is deprecated")

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func printPrettyOutput(ui *ui.UI, execution testkube.TestWorkflowExecution) {
ui.Warn("Execution number: ", fmt.Sprintf("%d", execution.Number))
}
ui.Warn("Requested at: ", execution.ScheduledAt.String())
ui.Warn("Disabled webhooks: ", fmt.Sprint(execution.DisableWebhooks))
if execution.Result != nil && execution.Result.Status != nil {
ui.Warn("Status: ", string(*execution.Result.Status))
if !execution.Result.QueuedAt.IsZero() {
Expand Down
Loading
Loading