Skip to content

Commit

Permalink
feat: add notification router (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz authored Mar 8, 2024
1 parent 8259f3c commit e1aa357
Show file tree
Hide file tree
Showing 24 changed files with 1,867 additions and 13 deletions.
289 changes: 289 additions & 0 deletions charts/controller/crds/deployments.plural.sh_notificationrouters.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ spec:
type: object
type: object
name:
description: Name the name of this service, if not provided ServiceDeployment's
own name from ServiceDeployment.ObjectMeta will be used.
description: Name the name of this service, if not provided NotificationSink's
own name from NotificationSink.ObjectMeta will be used.
type: string
type:
description: Type the channel type of this sink.
Expand Down
26 changes: 26 additions & 0 deletions charts/controller/templates/manager-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ rules:
- get
- patch
- update
- apiGroups:
- deployments.plural.sh
resources:
- notificationrouters
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- deployments.plural.sh
resources:
- notificationrouters/finalizers
verbs:
- update
- apiGroups:
- deployments.plural.sh
resources:
- notificationrouters/status
verbs:
- get
- patch
- update
- apiGroups:
- deployments.plural.sh
resources:
Expand Down
9 changes: 9 additions & 0 deletions controller/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,13 @@ resources:
kind: NotificationSink
path: github.com/pluralsh/console/controller/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: plural.sh
group: deployments
kind: NotificationRouter
path: github.com/pluralsh/console/controller/api/v1alpha1
version: v1alpha1
version: "3"
98 changes: 98 additions & 0 deletions controller/api/v1alpha1/notificationrouter_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NotificationRouterSpec defines the desired state of NotificationRouter
type NotificationRouterSpec struct {
// Name the name of this router, if not provided NotificationRouter's own name from NotificationRouter.ObjectMeta will be used.
// +kubebuilder:validation:Optional
Name *string `json:"name,omitempty"`

// Events the events to trigger, or use * for any
Events []string `json:"events,omitempty"`

// Filters filters by object type
// +kubebuilder:validation:Optional
Filters []RouterFilters `json:"filters,omitempty"`

// RouterSinks sinks to deliver notifications to
// +kubebuilder:validation:Optional
RouterSinks []string `json:"routerSinks,omitempty"`
}

type RouterFilters struct {
// Regex a regex for filtering by things like pr url
// +kubebuilder:validation:Optional
Regex *string `json:"regex,omitempty"`
// ServiceRef whether to enable delivery for events associated with this service
// +kubebuilder:validation:Optional
ServiceRef *corev1.ObjectReference `json:"serviceRef,omitempty"`
// ClusterRef whether to enable delivery for events associated with this cluster
// +kubebuilder:validation:Optional
ClusterRef *corev1.ObjectReference `json:"clusterRef,omitempty"`
// PipelineRef whether to enable delivery for events associated with this pipeline
// +kubebuilder:validation:Optional
PipelineRef *corev1.ObjectReference `json:"pipelineRef,omitempty"`
}

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

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

Spec NotificationRouterSpec `json:"spec,omitempty"`
Status Status `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&NotificationRouter{}, &NotificationRouterList{})
}

func (p *NotificationRouter) SetCondition(condition metav1.Condition) {
meta.SetStatusCondition(&p.Status.Conditions, condition)
}

// NotificationName implements NamespacedPluralResource interface
func (p *NotificationRouter) NotificationName() string {
if p.Spec.Name != nil && len(*p.Spec.Name) > 0 {
return *p.Spec.Name
}

return p.Name
}

func (p *NotificationRouterSpec) HasName() bool {
return p.Name != nil
}
2 changes: 1 addition & 1 deletion controller/api/v1alpha1/notificationsink_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// NotificationSinkSpec defines the desired state of NotificationSink
type NotificationSinkSpec struct {
// Name the name of this service, if not provided ServiceDeployment's own name from ServiceDeployment.ObjectMeta will be used.
// Name the name of this service, if not provided NotificationSink's own name from NotificationSink.ObjectMeta will be used.
// +kubebuilder:validation:Optional
Name *string `json:"name,omitempty"`

Expand Down
131 changes: 131 additions & 0 deletions controller/api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit e1aa357

Please sign in to comment.