Skip to content

Commit

Permalink
feat: WebhookTemplate CRD
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Jan 10, 2025
1 parent f0f08f7 commit 329a067
Show file tree
Hide file tree
Showing 26 changed files with 1,182 additions and 5 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
60 changes: 58 additions & 2 deletions api/executor/v1/webhook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,36 @@ type WebhookSpec struct {
Parameters map[string]WebhookParameterSchema `json:"parameters,omitempty"`
// webhook template reference
WebhookTemplateRef *WebhookTemplateRef `json:"webhookTemplateRef,omitempty"`
// whether webhook is used as a template
IsTemplate bool `json:"isTemplate,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"`
// 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 map[string]WebhookParameterSchema `json:"parameters,omitempty"`
}

// webhook parameter schema
Expand Down Expand Up @@ -137,6 +165,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 @@ -149,6 +183,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 @@ -158,6 +204,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{})
}
115 changes: 115 additions & 0 deletions api/executor/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Webhook")
os.Exit(1)
}
if err = (&executorcontrollers.WebhookTemplateReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "WebhookTemplate")
os.Exit(1)
}
if err = (&testsourcecontrollers.TestSourceReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Expand Down
3 changes: 0 additions & 3 deletions config/crd/bases/executor.testkube.io_webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ spec:
type: string
description: webhook headers (golang template supported)
type: object
isTemplate:
description: whether webhook is used as a template
type: boolean
onStateChange:
description: |-
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
Expand Down
Loading

0 comments on commit 329a067

Please sign in to comment.