Skip to content

Commit

Permalink
feat: [TKC-2933] add webhook config (#310)
Browse files Browse the repository at this point in the history
* feat: webhook config

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: tune conig

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: update crd

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: add isTemplate field

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: rename fields

Signed-off-by: Vladislav Sukhin <[email protected]>

* feat: WebhookTemplate CRD

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: remove deprecated field

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: use list for parameters

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: change description

Signed-off-by: Vladislav Sukhin <[email protected]>

* fix: add backend team

Signed-off-by: Vladislav Sukhin <[email protected]>

---------

Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin authored Jan 20, 2025
1 parent 2e5dd8b commit 7fac440
Show file tree
Hide file tree
Showing 26 changed files with 1,382 additions and 0 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ resources:
kind: Webhook
path: github.com/kubeshop/testkube-operator/api/executor/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: testkube.io
group: executor
kind: WebhookTemplate
path: github.com/kubeshop/testkube-operator/api/executor/v1
version: v1
- api:
crdVersion: v1
namespaced: true
Expand Down
6 changes: 6 additions & 0 deletions api/executor/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ var (
// WebhookResource corresponds to the CRD Kind
WebhookResource = "Webhook"

// WebhookTemplateResource corresponds to the CRD Kind
WebhookTemplateResource = "WebhookTemplate"

// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: Group, Version: Version}

Expand All @@ -46,6 +49,9 @@ var (
// WebhookGroupVersionResource is group, version and resource used to register these objects
WebhookGroupVersionResource = schema.GroupVersionResource{Group: Group, Version: Version, Resource: WebhookResource}

// WebhookTemplateGroupVersionResource is group, version and resource used to register these objects
WebhookTemplateGroupVersionResource = schema.GroupVersionResource{Group: Group, Version: Version, Resource: WebhookTemplateResource}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

Expand Down
101 changes: 101 additions & 0 deletions api/executor/v1/webhook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,79 @@ 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 configuration
Config map[string]WebhookConfigValue `json:"config,omitempty"`
// webhook parameters
Parameters []WebhookParameterSchema `json:"parameters,omitempty"`
// webhook template reference
WebhookTemplateRef *WebhookTemplateRef `json:"webhookTemplateRef,omitempty"`
}

// WebhookTemplateSpec defines the desired state of Webhook Template
type WebhookTemplateSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Uri is address where webhook should be made (golang template supported)
Uri string `json:"uri,omitempty"`
// Events declare list if events on which webhook should be called
Events []EventType `json:"events,omitempty"`
// Labels to filter for tests and test suites
Selector string `json:"selector,omitempty"`
// will load the generated payload for notification inside the object
PayloadObjectField string `json:"payloadObjectField,omitempty"`
// golang based template for notification payload
PayloadTemplate string `json:"payloadTemplate,omitempty"`
// name of the template resource
PayloadTemplateReference string `json:"payloadTemplateReference,omitempty"`
// webhook headers (golang template supported)
Headers map[string]string `json:"headers,omitempty"`
// Disabled will disable the webhook
Disabled bool `json:"disabled,omitempty"`
// webhook configuration
Config map[string]WebhookConfigValue `json:"config,omitempty"`
// webhook parameters
Parameters []WebhookParameterSchema `json:"parameters,omitempty"`
}

// webhook parameter schema
type WebhookParameterSchema struct {
// unique parameter name
Name string `json:"name"`
// description for the parameter
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 configuration value
type WebhookConfigValue struct {
// public value to use in webhook template
Value *string `json:"value,omitempty"`
// private value stored in secret to use in webhook template
Secret *SecretRef `json:"secret,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
Expand Down Expand Up @@ -91,6 +164,12 @@ type WebhookStatus struct {
// Important: Run "make" to regenerate code after modifying this file
}

// WebhookTemplateStatus defines the observed state of Webhook Template
type WebhookTemplateStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand All @@ -103,6 +182,18 @@ type Webhook struct {
Status WebhookStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// WebhookTemplate is the Schema for the webhook templates API
type WebhookTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec WebhookTemplateSpec `json:"spec,omitempty"`
Status WebhookTemplateStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// WebhookList contains a list of Webhook
Expand All @@ -112,6 +203,16 @@ type WebhookList struct {
Items []Webhook `json:"items"`
}

//+kubebuilder:object:root=true

// WebhookTemplateList contains a list of Webhook Template
type WebhookTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []WebhookTemplate `json:"items"`
}

func init() {
SchemeBuilder.Register(&Webhook{}, &WebhookList{})
SchemeBuilder.Register(&WebhookTemplate{}, &WebhookTemplateList{})
}
Loading

0 comments on commit 7fac440

Please sign in to comment.