From 0fe88b54c319f876a473cb97620dd4b5048a6e73 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Fri, 20 Dec 2024 17:00:14 +0300 Subject: [PATCH] feat: webhook config Signed-off-by: Vladislav Sukhin --- api/executor/v1/webhook_types.go | 44 +++++++++ api/executor/v1/zz_generated.deepcopy.go | 94 +++++++++++++++++++ .../bases/executor.testkube.io_webhooks.yaml | 58 ++++++++++++ 3 files changed, 196 insertions(+) diff --git a/api/executor/v1/webhook_types.go b/api/executor/v1/webhook_types.go index 70613e09..255c4d75 100644 --- a/api/executor/v1/webhook_types.go +++ b/api/executor/v1/webhook_types.go @@ -47,6 +47,50 @@ type WebhookSpec struct { // OnStateChange will trigger the webhook only when the result of the current execution differs from the previous result of the same test/test suite/workflow // Deprecated: field is not used OnStateChange bool `json:"onStateChange,omitempty"` + // webhook parameter configuration + WebhookConfig map[string]WebhookParameterSchema `json:"webhookConfig,omitempty"` + // webhook template reference + WebhookTemplateRef *WebhookTemplateRef `json:"webhookTemplateRef,omitempty"` +} + +// webhook parameter schema +type WebhookParameterSchema struct { + // description for the property + Description string `json:"description,omitempty"` + // whether parameter is required + Required bool `json:"required,omitempty"` + // example value for the parameter + Example string `json:"example,omitempty"` + // default parameter value + Default_ *string `json:"default,omitempty"` + // regular expression to match + Pattern string `json:"pattern,omitempty"` +} + +// webhook template reference +type WebhookTemplateRef struct { + // webhook template name to include + Name string `json:"name"` + // webhook config to use in webhook template + Config map[string]WebhookConfigValue `json:"config,omitempty"` +} + +// webhook configuration value +type WebhookConfigValue struct { + // public value to use in webhook template + Public *string `json:"public,omitempty"` + // private value stored in secret to use in webhook template + Private *SecretRef `json:"private,omitempty"` +} + +// Testkube internal reference for secret storage in Kubernetes secrets +type SecretRef struct { + // object kubernetes namespace + Namespace string `json:"namespace,omitempty"` + // object name + Name string `json:"name"` + // object key + Key string `json:"key"` } // +kubebuilder:validation:Enum=start-test;end-test-success;end-test-failed;end-test-aborted;end-test-timeout;become-test-up;become-test-down;become-test-failed;become-test-aborted;become-test-timeout;start-testsuite;end-testsuite-success;end-testsuite-failed;end-testsuite-aborted;end-testsuite-timeout;become-testsuite-up;become-testsuite-down;become-testsuite-failed;become-testsuite-aborted;become-testsuite-timeout;start-testworkflow;queue-testworkflow;end-testworkflow-success;end-testworkflow-failed;end-testworkflow-aborted;become-testworkflow-up;become-testworkflow-down;become-testworkflow-failed;become-testworkflow-aborted diff --git a/api/executor/v1/zz_generated.deepcopy.go b/api/executor/v1/zz_generated.deepcopy.go index dda0d45a..46a926e0 100644 --- a/api/executor/v1/zz_generated.deepcopy.go +++ b/api/executor/v1/zz_generated.deepcopy.go @@ -191,6 +191,21 @@ func (in *Runner) DeepCopy() *Runner { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SecretRef) DeepCopyInto(out *SecretRef) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretRef. +func (in *SecretRef) DeepCopy() *SecretRef { + if in == nil { + return nil + } + out := new(SecretRef) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SlavesMeta) DeepCopyInto(out *SlavesMeta) { *out = *in @@ -233,6 +248,31 @@ func (in *Webhook) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WebhookConfigValue) DeepCopyInto(out *WebhookConfigValue) { + *out = *in + if in.Public != nil { + in, out := &in.Public, &out.Public + *out = new(string) + **out = **in + } + if in.Private != nil { + in, out := &in.Private, &out.Private + *out = new(SecretRef) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WebhookConfigValue. +func (in *WebhookConfigValue) DeepCopy() *WebhookConfigValue { + if in == nil { + return nil + } + out := new(WebhookConfigValue) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WebhookList) DeepCopyInto(out *WebhookList) { *out = *in @@ -265,6 +305,26 @@ func (in *WebhookList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WebhookParameterSchema) DeepCopyInto(out *WebhookParameterSchema) { + *out = *in + if in.Default_ != nil { + in, out := &in.Default_, &out.Default_ + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WebhookParameterSchema. +func (in *WebhookParameterSchema) DeepCopy() *WebhookParameterSchema { + if in == nil { + return nil + } + out := new(WebhookParameterSchema) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WebhookSpec) DeepCopyInto(out *WebhookSpec) { *out = *in @@ -280,6 +340,18 @@ func (in *WebhookSpec) DeepCopyInto(out *WebhookSpec) { (*out)[key] = val } } + if in.WebhookConfig != nil { + in, out := &in.WebhookConfig, &out.WebhookConfig + *out = make(map[string]WebhookParameterSchema, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() + } + } + if in.WebhookTemplateRef != nil { + in, out := &in.WebhookTemplateRef, &out.WebhookTemplateRef + *out = new(WebhookTemplateRef) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WebhookSpec. @@ -306,3 +378,25 @@ func (in *WebhookStatus) DeepCopy() *WebhookStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WebhookTemplateRef) DeepCopyInto(out *WebhookTemplateRef) { + *out = *in + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = make(map[string]WebhookConfigValue, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WebhookTemplateRef. +func (in *WebhookTemplateRef) DeepCopy() *WebhookTemplateRef { + if in == nil { + return nil + } + out := new(WebhookTemplateRef) + in.DeepCopyInto(out) + return out +} diff --git a/config/crd/bases/executor.testkube.io_webhooks.yaml b/config/crd/bases/executor.testkube.io_webhooks.yaml index b5803d26..1f10d636 100644 --- a/config/crd/bases/executor.testkube.io_webhooks.yaml +++ b/config/crd/bases/executor.testkube.io_webhooks.yaml @@ -105,6 +105,64 @@ spec: description: Uri is address where webhook should be made (golang template supported) type: string + webhookConfig: + additionalProperties: + description: webhook parameter schema + properties: + default: + description: default parameter value + type: string + description: + description: description for the property + type: string + example: + description: example value for the parameter + type: string + pattern: + description: regular expression to match + type: string + required: + description: whether parameter is required + type: boolean + type: object + description: webhook parameter configuration + type: object + webhookTemplateRef: + description: webhook template reference + properties: + config: + additionalProperties: + description: webhook configuration value + properties: + private: + description: private value stored in secret to use in webhook + template + properties: + key: + description: object key + type: string + name: + description: object name + type: string + namespace: + description: object kubernetes namespace + type: string + required: + - key + - name + type: object + public: + description: public value to use in webhook template + type: string + type: object + description: ' webhook config to use in webhook template' + type: object + name: + description: webhook template name to include + type: string + required: + - name + type: object type: object status: description: WebhookStatus defines the observed state of Webhook