From e1aa357d2f2853211695caa91ad4f0469387188e Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Fri, 8 Mar 2024 01:02:07 +0100 Subject: [PATCH] feat: add notification router (#758) --- ...oyments.plural.sh_notificationrouters.yaml | 289 +++++++++++++++++ ...ployments.plural.sh_notificationsinks.yaml | 4 +- charts/controller/templates/manager-rbac.yaml | 26 ++ controller/PROJECT | 9 + .../api/v1alpha1/notificationrouter_types.go | 98 ++++++ .../api/v1alpha1/notificationsink_types.go | 2 +- .../api/v1alpha1/zz_generated.deepcopy.go | 131 ++++++++ ...oyments.plural.sh_notificationrouters.yaml | 289 +++++++++++++++++ ...ployments.plural.sh_notificationsinks.yaml | 4 +- .../rbac/notificationrouter_editor_role.yaml | 31 ++ .../rbac/notificationrouter_viewer_role.yaml | 27 ++ controller/config/rbac/role.yaml | 26 ++ ...ployments_v1alpha1_notificationrouter.yaml | 14 + controller/go.mod | 2 +- controller/go.sum | 4 +- controller/internal/client/console.go | 4 + controller/internal/client/notification.go | 46 +++ .../notificationrouter_controller.go | 302 ++++++++++++++++++ .../controller/notificationrouter_scope.go | 40 +++ .../controller/notificationsink_controller.go | 4 +- .../internal/test/mocks/ConsoleClient_mock.go | 224 +++++++++++++ controller/internal/types/reconciler.go | 11 +- ...oyments.plural.sh_notificationrouters.yaml | 289 +++++++++++++++++ ...ployments.plural.sh_notificationsinks.yaml | 4 +- 24 files changed, 1867 insertions(+), 13 deletions(-) create mode 100644 charts/controller/crds/deployments.plural.sh_notificationrouters.yaml create mode 100644 controller/api/v1alpha1/notificationrouter_types.go create mode 100644 controller/config/crd/bases/deployments.plural.sh_notificationrouters.yaml create mode 100644 controller/config/rbac/notificationrouter_editor_role.yaml create mode 100644 controller/config/rbac/notificationrouter_viewer_role.yaml create mode 100644 controller/config/samples/deployments_v1alpha1_notificationrouter.yaml create mode 100644 controller/internal/controller/notificationrouter_controller.go create mode 100644 controller/internal/controller/notificationrouter_scope.go create mode 100644 plural/helm/console/crds/deployments.plural.sh_notificationrouters.yaml diff --git a/charts/controller/crds/deployments.plural.sh_notificationrouters.yaml b/charts/controller/crds/deployments.plural.sh_notificationrouters.yaml new file mode 100644 index 0000000000..cd72e8e75e --- /dev/null +++ b/charts/controller/crds/deployments.plural.sh_notificationrouters.yaml @@ -0,0 +1,289 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: notificationrouters.deployments.plural.sh +spec: + group: deployments.plural.sh + names: + kind: NotificationRouter + listKind: NotificationRouterList + plural: notificationrouters + singular: notificationrouter + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: NotificationRouter is the Schema for the notificationrouters + API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: NotificationRouterSpec defines the desired state of NotificationRouter + properties: + events: + description: Events the events to trigger, or use * for any + items: + type: string + type: array + filters: + description: Filters filters by object type + items: + properties: + clusterRef: + description: ClusterRef whether to enable delivery for events + associated with this cluster + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + pipelineRef: + description: PipelineRef whether to enable delivery for events + associated with this pipeline + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + regex: + description: Regex a regex for filtering by things like pr url + type: string + serviceRef: + description: ServiceRef whether to enable delivery for events + associated with this service + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + type: object + type: array + name: + description: Name the name of this router, if not provided NotificationRouter's + own name from NotificationRouter.ObjectMeta will be used. + type: string + routerSinks: + description: RouterSinks sinks to deliver notifications to + items: + type: string + type: array + type: object + status: + properties: + conditions: + description: Represents the observations of a PrAutomation's current + state. + items: + description: "Condition contains details for one aspect of the current + state of this API Resource.\n---\nThis struct is intended for + direct use as an array at the field path .status.conditions. For + example,\n\n\n\ttype FooStatus struct{\n\t // Represents the + observations of a foo's current state.\n\t // Known .status.conditions.type + are: \"Available\", \"Progressing\", and \"Degraded\"\n\t // + +patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t + \ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\" + patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t + \ // other fields\n\t}" + properties: + lastTransitionTime: + description: |- + lastTransitionTime is the last time the condition transitioned from one status to another. + This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. + format: date-time + type: string + message: + description: |- + message is a human readable message indicating details about the transition. + This may be an empty string. + maxLength: 32768 + type: string + observedGeneration: + description: |- + observedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + minimum: 0 + type: integer + reason: + description: |- + reason contains a programmatic identifier indicating the reason for the condition's last transition. + Producers of specific condition types may define expected values and meanings for this field, + and whether the values are considered a guaranteed API. + The value should be a CamelCase string. + This field may not be empty. + maxLength: 1024 + minLength: 1 + pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ + type: string + status: + description: status of the condition, one of True, False, Unknown. + enum: + - "True" + - "False" + - Unknown + type: string + type: + description: |- + type of condition in CamelCase or in foo.example.com/CamelCase. + --- + Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be + useful (see .node.status.conditions), the ability to deconflict is important. + The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) + maxLength: 316 + pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ + type: string + required: + - lastTransitionTime + - message + - reason + - status + - type + type: object + type: array + x-kubernetes-list-map-keys: + - type + x-kubernetes-list-type: map + id: + description: ID of the resource in the Console API. + type: string + sha: + description: SHA of last applied configuration. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/charts/controller/crds/deployments.plural.sh_notificationsinks.yaml b/charts/controller/crds/deployments.plural.sh_notificationsinks.yaml index ebde261c94..9ce483fcc9 100644 --- a/charts/controller/crds/deployments.plural.sh_notificationsinks.yaml +++ b/charts/controller/crds/deployments.plural.sh_notificationsinks.yaml @@ -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. diff --git a/charts/controller/templates/manager-rbac.yaml b/charts/controller/templates/manager-rbac.yaml index f129b2e39c..618680f5bf 100644 --- a/charts/controller/templates/manager-rbac.yaml +++ b/charts/controller/templates/manager-rbac.yaml @@ -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: diff --git a/controller/PROJECT b/controller/PROJECT index dbd073f917..5cbcaa1899 100644 --- a/controller/PROJECT +++ b/controller/PROJECT @@ -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" diff --git a/controller/api/v1alpha1/notificationrouter_types.go b/controller/api/v1alpha1/notificationrouter_types.go new file mode 100644 index 0000000000..d812cfe223 --- /dev/null +++ b/controller/api/v1alpha1/notificationrouter_types.go @@ -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 +} diff --git a/controller/api/v1alpha1/notificationsink_types.go b/controller/api/v1alpha1/notificationsink_types.go index 733ed404a2..77be1619bc 100644 --- a/controller/api/v1alpha1/notificationsink_types.go +++ b/controller/api/v1alpha1/notificationsink_types.go @@ -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"` diff --git a/controller/api/v1alpha1/zz_generated.deepcopy.go b/controller/api/v1alpha1/zz_generated.deepcopy.go index 10480e79c6..35f8ad7c7e 100644 --- a/controller/api/v1alpha1/zz_generated.deepcopy.go +++ b/controller/api/v1alpha1/zz_generated.deepcopy.go @@ -1027,6 +1027,102 @@ func (in *NamespacedName) DeepCopy() *NamespacedName { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NotificationRouter) DeepCopyInto(out *NotificationRouter) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NotificationRouter. +func (in *NotificationRouter) DeepCopy() *NotificationRouter { + if in == nil { + return nil + } + out := new(NotificationRouter) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NotificationRouter) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NotificationRouterList) DeepCopyInto(out *NotificationRouterList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NotificationRouter, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NotificationRouterList. +func (in *NotificationRouterList) DeepCopy() *NotificationRouterList { + if in == nil { + return nil + } + out := new(NotificationRouterList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NotificationRouterList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NotificationRouterSpec) DeepCopyInto(out *NotificationRouterSpec) { + *out = *in + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } + if in.Events != nil { + in, out := &in.Events, &out.Events + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Filters != nil { + in, out := &in.Filters, &out.Filters + *out = make([]RouterFilters, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.RouterSinks != nil { + in, out := &in.RouterSinks, &out.RouterSinks + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NotificationRouterSpec. +func (in *NotificationRouterSpec) DeepCopy() *NotificationRouterSpec { + if in == nil { + return nil + } + out := new(NotificationRouterSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NotificationSink) DeepCopyInto(out *NotificationSink) { *out = *in @@ -1924,6 +2020,41 @@ func (in *RegexReplacement) DeepCopy() *RegexReplacement { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RouterFilters) DeepCopyInto(out *RouterFilters) { + *out = *in + if in.Regex != nil { + in, out := &in.Regex, &out.Regex + *out = new(string) + **out = **in + } + if in.ServiceRef != nil { + in, out := &in.ServiceRef, &out.ServiceRef + *out = new(v1.ObjectReference) + **out = **in + } + if in.ClusterRef != nil { + in, out := &in.ClusterRef, &out.ClusterRef + *out = new(v1.ObjectReference) + **out = **in + } + if in.PipelineRef != nil { + in, out := &in.PipelineRef, &out.PipelineRef + *out = new(v1.ObjectReference) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RouterFilters. +func (in *RouterFilters) DeepCopy() *RouterFilters { + if in == nil { + return nil + } + out := new(RouterFilters) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ScmConnection) DeepCopyInto(out *ScmConnection) { *out = *in diff --git a/controller/config/crd/bases/deployments.plural.sh_notificationrouters.yaml b/controller/config/crd/bases/deployments.plural.sh_notificationrouters.yaml new file mode 100644 index 0000000000..cd72e8e75e --- /dev/null +++ b/controller/config/crd/bases/deployments.plural.sh_notificationrouters.yaml @@ -0,0 +1,289 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: notificationrouters.deployments.plural.sh +spec: + group: deployments.plural.sh + names: + kind: NotificationRouter + listKind: NotificationRouterList + plural: notificationrouters + singular: notificationrouter + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: NotificationRouter is the Schema for the notificationrouters + API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: NotificationRouterSpec defines the desired state of NotificationRouter + properties: + events: + description: Events the events to trigger, or use * for any + items: + type: string + type: array + filters: + description: Filters filters by object type + items: + properties: + clusterRef: + description: ClusterRef whether to enable delivery for events + associated with this cluster + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + pipelineRef: + description: PipelineRef whether to enable delivery for events + associated with this pipeline + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + regex: + description: Regex a regex for filtering by things like pr url + type: string + serviceRef: + description: ServiceRef whether to enable delivery for events + associated with this service + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + type: object + type: array + name: + description: Name the name of this router, if not provided NotificationRouter's + own name from NotificationRouter.ObjectMeta will be used. + type: string + routerSinks: + description: RouterSinks sinks to deliver notifications to + items: + type: string + type: array + type: object + status: + properties: + conditions: + description: Represents the observations of a PrAutomation's current + state. + items: + description: "Condition contains details for one aspect of the current + state of this API Resource.\n---\nThis struct is intended for + direct use as an array at the field path .status.conditions. For + example,\n\n\n\ttype FooStatus struct{\n\t // Represents the + observations of a foo's current state.\n\t // Known .status.conditions.type + are: \"Available\", \"Progressing\", and \"Degraded\"\n\t // + +patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t + \ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\" + patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t + \ // other fields\n\t}" + properties: + lastTransitionTime: + description: |- + lastTransitionTime is the last time the condition transitioned from one status to another. + This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. + format: date-time + type: string + message: + description: |- + message is a human readable message indicating details about the transition. + This may be an empty string. + maxLength: 32768 + type: string + observedGeneration: + description: |- + observedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + minimum: 0 + type: integer + reason: + description: |- + reason contains a programmatic identifier indicating the reason for the condition's last transition. + Producers of specific condition types may define expected values and meanings for this field, + and whether the values are considered a guaranteed API. + The value should be a CamelCase string. + This field may not be empty. + maxLength: 1024 + minLength: 1 + pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ + type: string + status: + description: status of the condition, one of True, False, Unknown. + enum: + - "True" + - "False" + - Unknown + type: string + type: + description: |- + type of condition in CamelCase or in foo.example.com/CamelCase. + --- + Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be + useful (see .node.status.conditions), the ability to deconflict is important. + The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) + maxLength: 316 + pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ + type: string + required: + - lastTransitionTime + - message + - reason + - status + - type + type: object + type: array + x-kubernetes-list-map-keys: + - type + x-kubernetes-list-type: map + id: + description: ID of the resource in the Console API. + type: string + sha: + description: SHA of last applied configuration. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/controller/config/crd/bases/deployments.plural.sh_notificationsinks.yaml b/controller/config/crd/bases/deployments.plural.sh_notificationsinks.yaml index ebde261c94..9ce483fcc9 100644 --- a/controller/config/crd/bases/deployments.plural.sh_notificationsinks.yaml +++ b/controller/config/crd/bases/deployments.plural.sh_notificationsinks.yaml @@ -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. diff --git a/controller/config/rbac/notificationrouter_editor_role.yaml b/controller/config/rbac/notificationrouter_editor_role.yaml new file mode 100644 index 0000000000..8d790acafb --- /dev/null +++ b/controller/config/rbac/notificationrouter_editor_role.yaml @@ -0,0 +1,31 @@ +# permissions for end users to edit notificationrouters. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: notificationrouter-editor-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: controller + app.kubernetes.io/part-of: controller + app.kubernetes.io/managed-by: kustomize + name: notificationrouter-editor-role +rules: +- apiGroups: + - deployments.plural.sh + resources: + - notificationrouters + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - deployments.plural.sh + resources: + - notificationrouters/status + verbs: + - get diff --git a/controller/config/rbac/notificationrouter_viewer_role.yaml b/controller/config/rbac/notificationrouter_viewer_role.yaml new file mode 100644 index 0000000000..8681e84a6b --- /dev/null +++ b/controller/config/rbac/notificationrouter_viewer_role.yaml @@ -0,0 +1,27 @@ +# permissions for end users to view notificationrouters. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: notificationrouter-viewer-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: controller + app.kubernetes.io/part-of: controller + app.kubernetes.io/managed-by: kustomize + name: notificationrouter-viewer-role +rules: +- apiGroups: + - deployments.plural.sh + resources: + - notificationrouters + verbs: + - get + - list + - watch +- apiGroups: + - deployments.plural.sh + resources: + - notificationrouters/status + verbs: + - get diff --git a/controller/config/rbac/role.yaml b/controller/config/rbac/role.yaml index 3886b54ac5..1d136d90cb 100644 --- a/controller/config/rbac/role.yaml +++ b/controller/config/rbac/role.yaml @@ -152,6 +152,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: diff --git a/controller/config/samples/deployments_v1alpha1_notificationrouter.yaml b/controller/config/samples/deployments_v1alpha1_notificationrouter.yaml new file mode 100644 index 0000000000..2511b2a49f --- /dev/null +++ b/controller/config/samples/deployments_v1alpha1_notificationrouter.yaml @@ -0,0 +1,14 @@ +apiVersion: deployments.plural.sh/v1alpha1 +kind: NotificationRouter +metadata: + labels: + app.kubernetes.io/name: notificationrouter + app.kubernetes.io/instance: notificationrouter-sample + app.kubernetes.io/part-of: controller + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: controller + name: notificationrouter-sample +spec: + name: test + + diff --git a/controller/go.mod b/controller/go.mod index c0744266d0..1e525c2330 100644 --- a/controller/go.mod +++ b/controller/go.mod @@ -7,7 +7,7 @@ toolchain go1.21.1 // Dependencies require ( github.com/Yamashou/gqlgenc v0.18.1 - github.com/pluralsh/console-client-go v0.1.3 + github.com/pluralsh/console-client-go v0.1.6 github.com/pluralsh/polly v0.1.5 github.com/samber/lo v1.39.0 github.com/spf13/pflag v1.0.5 diff --git a/controller/go.sum b/controller/go.sum index 4f97e95044..03f67c4f08 100644 --- a/controller/go.sum +++ b/controller/go.sum @@ -607,8 +607,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= -github.com/pluralsh/console-client-go v0.1.3 h1:Nzg6qYKvLpOxNGMypMQ75h9qGTnRhYS+wtDMpK7ybhE= -github.com/pluralsh/console-client-go v0.1.3/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= +github.com/pluralsh/console-client-go v0.1.6 h1:koJLZuOIGKz7xC6FF14FBBp9LCMeci0iuiAKniniGsQ= +github.com/pluralsh/console-client-go v0.1.6/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= github.com/pluralsh/polly v0.1.5 h1:ztDafEsVL3wtqcx3QkzHLkTUKdk38qfflgQxFfH1rio= github.com/pluralsh/polly v0.1.5/go.mod h1:Yo1/jcW+4xwhWG+ZJikZy4J4HJkMNPZ7sq5auL2c/tY= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/controller/internal/client/console.go b/controller/internal/client/console.go index 8b06be4b02..f38c2c18b1 100644 --- a/controller/internal/client/console.go +++ b/controller/internal/client/console.go @@ -88,6 +88,10 @@ type ConsoleClient interface { DeleteNotificationSink(ctx context.Context, id string) error UpsertNotificationSink(ctx context.Context, attr console.NotificationSinkAttributes) (*console.NotificationSinkFragment, error) GetNotificationSinkByName(ctx context.Context, name string) (*console.NotificationSinkFragment, error) + DeleteNotificationRouter(ctx context.Context, id string) error + GetNotificationRouterByName(ctx context.Context, name string) (*console.NotificationRouterFragment, error) + GetNotificationRouter(ctx context.Context, id string) (*console.NotificationRouterFragment, error) + UpsertNotificationRouter(ctx context.Context, attr console.NotificationRouterAttributes) (*console.NotificationRouterFragment, error) } func New(url, token string) ConsoleClient { diff --git a/controller/internal/client/notification.go b/controller/internal/client/notification.go index 74c4824cdb..ff7949a774 100644 --- a/controller/internal/client/notification.go +++ b/controller/internal/client/notification.go @@ -54,3 +54,49 @@ func (c *client) DeleteNotificationSink(ctx context.Context, id string) error { } return nil } + +func (c *client) GetNotificationRouter(ctx context.Context, id string) (*console.NotificationRouterFragment, error) { + response, err := c.consoleClient.GetNotificationRouter(ctx, id) + if internalerror.IsNotFound(err) { + return nil, errors.NewNotFound(schema.GroupResource{}, id) + } + if err == nil && (response == nil || response.NotificationRouter == nil) { + return nil, errors.NewNotFound(schema.GroupResource{}, id) + } + if response == nil { + return nil, err + } + + return response.NotificationRouter, err +} + +func (c *client) GetNotificationRouterByName(ctx context.Context, name string) (*console.NotificationRouterFragment, error) { + response, err := c.consoleClient.GetNotificationRouterByName(ctx, &name) + if internalerror.IsNotFound(err) { + return nil, errors.NewNotFound(schema.GroupResource{}, name) + } + if err == nil && (response == nil || response.NotificationRouter == nil) { + return nil, errors.NewNotFound(schema.GroupResource{}, name) + } + if response == nil { + return nil, err + } + + return response.NotificationRouter, err +} + +func (c *client) DeleteNotificationRouter(ctx context.Context, id string) error { + _, err := c.consoleClient.DeleteNotificationRouter(ctx, id) + if err != nil { + return err + } + return nil +} + +func (c *client) UpsertNotificationRouter(ctx context.Context, attr console.NotificationRouterAttributes) (*console.NotificationRouterFragment, error) { + response, err := c.consoleClient.UpsertNotificationRouter(ctx, attr) + if err != nil { + return nil, err + } + return response.UpsertNotificationRouter, nil +} diff --git a/controller/internal/controller/notificationrouter_controller.go b/controller/internal/controller/notificationrouter_controller.go new file mode 100644 index 0000000000..2b6338856a --- /dev/null +++ b/controller/internal/controller/notificationrouter_controller.go @@ -0,0 +1,302 @@ +/* +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 controller + +import ( + "context" + "fmt" + + console "github.com/pluralsh/console-client-go" + "github.com/pluralsh/console/controller/api/v1alpha1" + consoleclient "github.com/pluralsh/console/controller/internal/client" + "github.com/pluralsh/console/controller/internal/utils" + "github.com/pluralsh/polly/containers" + "github.com/samber/lo" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/log" +) + +const NotificationRouterFinalizer = "deployments.plural.sh/notification-router-protection" + +// NotificationRouterReconciler reconciles a NotificationRouter object +type NotificationRouterReconciler struct { + client.Client + ConsoleClient consoleclient.ConsoleClient + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=deployments.plural.sh,resources=notificationrouters,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=deployments.plural.sh,resources=notificationrouters/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=deployments.plural.sh,resources=notificationrouters/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.16.3/pkg/reconcile +func (r *NotificationRouterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) { + logger := log.FromContext(ctx) + + notificationRouter := &v1alpha1.NotificationRouter{} + if err := r.Get(ctx, req.NamespacedName, notificationRouter); err != nil { + return ctrl.Result{}, client.IgnoreNotFound(err) + } + scope, err := NewNotificationRouterScope(ctx, r.Client, notificationRouter) + if err != nil { + logger.Error(err, "failed to create scope") + utils.MarkCondition(notificationRouter.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, err.Error()) + return ctrl.Result{}, err + } + // Always patch object when exiting this function, so we can persist any object changes. + defer func() { + if err := scope.PatchObject(); err != nil && reterr == nil { + reterr = err + } + }() + + if !notificationRouter.GetDeletionTimestamp().IsZero() { + return ctrl.Result{}, r.handleDelete(ctx, notificationRouter) + } + + ro, err := r.isReadOnly(ctx, notificationRouter) + if err != nil { + if err != nil { + utils.MarkCondition(notificationRouter.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, err.Error()) + return ctrl.Result{}, fmt.Errorf("could not check if notification router is existing resource, got error: %+v", err) + } + } + if ro { + logger.V(9).Info("Notification Router already exists in the API, running in read-only mode") + utils.MarkCondition(notificationRouter.SetCondition, v1alpha1.ReadonlyConditionType, v1.ConditionTrue, v1alpha1.ReadonlyConditionReason, v1alpha1.ReadonlyTrueConditionMessage.String()) + return r.handleExisting(ctx, notificationRouter) + } + + // Mark resource as managed by this operator. + utils.MarkCondition(notificationRouter.SetCondition, v1alpha1.ReadonlyConditionType, v1.ConditionFalse, v1alpha1.ReadonlyConditionReason, "") + + sha, err := utils.HashObject(notificationRouter.Spec) + if err != nil { + return ctrl.Result{}, err + } + // Check if resource already exists in the API and only sync the ID + exists, err := r.isAlreadyExists(ctx, notificationRouter) + if err != nil { + utils.MarkCondition(notificationRouter.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, err.Error()) + return ctrl.Result{}, err + } + if !exists || !notificationRouter.Status.IsSHAEqual(sha) { + logger.Info("upsert notification router", "name", notificationRouter.NotificationName()) + attr, err := r.genNotificationRouterAttr(ctx, notificationRouter) + if err != nil { + utils.MarkCondition(notificationRouter.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, err.Error()) + return ctrl.Result{}, err + } + ns, err := r.ConsoleClient.UpsertNotificationRouter(ctx, *attr) + if err != nil { + utils.MarkCondition(notificationRouter.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, err.Error()) + return ctrl.Result{}, err + } + notificationRouter.Status.ID = lo.ToPtr(ns.ID) + notificationRouter.Status.SHA = lo.ToPtr(sha) + controllerutil.AddFinalizer(notificationRouter, NotificationRouterFinalizer) + } + + utils.MarkCondition(notificationRouter.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionTrue, v1alpha1.SynchronizedConditionReason, "") + utils.MarkCondition(notificationRouter.SetCondition, v1alpha1.ReadyConditionType, v1.ConditionTrue, v1alpha1.ReadyConditionReason, "") + + return ctrl.Result{}, nil +} + +func (r *NotificationRouterReconciler) genNotificationRouterAttr(ctx context.Context, router *v1alpha1.NotificationRouter) (*console.NotificationRouterAttributes, error) { + attr := &console.NotificationRouterAttributes{ + Name: router.NotificationName(), + } + events := containers.NewSet[string]() + events.Add("*") + for _, event := range router.Spec.Events { + events.Add(event) + } + attr.Events = events.List() + + if len(router.Spec.Filters) > 0 { + attr.Filters = []*console.RouterFilterAttributes{} + } + if len(router.Spec.RouterSinks) > 0 { + attr.RouterSinks = []*console.RouterSinkAttributes{} + } + for _, filter := range router.Spec.Filters { + clusterID, err := r.getClusterID(ctx, filter.ClusterRef) + if err != nil { + return nil, err + } + serviceID, err := r.getServiceID(ctx, filter.ServiceRef) + if err != nil { + return nil, err + } + pipelineID, err := r.getPipelineID(ctx, filter.PipelineRef) + if err != nil { + return nil, err + } + attr.Filters = append(attr.Filters, &console.RouterFilterAttributes{ + Regex: filter.Regex, + ServiceID: serviceID, + ClusterID: clusterID, + PipelineID: pipelineID, + }) + } + for _, sink := range router.Spec.RouterSinks { + attr.RouterSinks = append(attr.RouterSinks, &console.RouterSinkAttributes{SinkID: sink}) + } + + return attr, nil +} + +func (r *NotificationRouterReconciler) getClusterID(ctx context.Context, obj *corev1.ObjectReference) (*string, error) { + if obj == nil { + return nil, nil + } + cluster := &v1alpha1.Cluster{} + if err := r.Get(ctx, client.ObjectKey{Name: obj.Name, Namespace: obj.Namespace}, cluster); err != nil { + return nil, err + } + if !cluster.Status.HasID() { + return nil, fmt.Errorf("cluster is not ready yet") + } + return cluster.Status.ID, nil +} + +func (r *NotificationRouterReconciler) getServiceID(ctx context.Context, objRef *corev1.ObjectReference) (*string, error) { + if objRef == nil { + return nil, nil + } + resource := &v1alpha1.ServiceDeployment{} + if err := r.Get(ctx, client.ObjectKey{Name: objRef.Name, Namespace: objRef.Namespace}, resource); err != nil { + return nil, err + } + if !resource.Status.HasID() { + return nil, fmt.Errorf("cluster is not ready yet") + } + return resource.Status.ID, nil +} + +func (r *NotificationRouterReconciler) getPipelineID(ctx context.Context, objRef *corev1.ObjectReference) (*string, error) { + if objRef == nil { + return nil, nil + } + resource := &v1alpha1.Pipeline{} + if err := r.Get(ctx, client.ObjectKey{Name: objRef.Name, Namespace: objRef.Namespace}, resource); err != nil { + return nil, err + } + if !resource.Status.HasID() { + return nil, fmt.Errorf("pipeline is not ready yet") + } + return resource.Status.ID, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *NotificationRouterReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&v1alpha1.NotificationRouter{}). + Complete(r) +} + +func (r *NotificationRouterReconciler) handleDelete(ctx context.Context, router *v1alpha1.NotificationRouter) error { + logger := log.FromContext(ctx) + if controllerutil.ContainsFinalizer(router, NotificationRouterFinalizer) { + logger.Info("try to delete notification router") + if router.Status.GetID() != "" { + existingNotificationSink, err := r.ConsoleClient.GetNotificationRouter(ctx, router.Status.GetID()) + if err != nil && !errors.IsNotFound(err) { + utils.MarkCondition(router.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, err.Error()) + return err + } + if existingNotificationSink != nil { + if err := r.ConsoleClient.DeleteNotificationRouter(ctx, *router.Status.ID); err != nil { + utils.MarkCondition(router.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, err.Error()) + return err + } + } + } + controllerutil.RemoveFinalizer(router, NotificationRouterFinalizer) + } + return nil +} + +func (r *NotificationRouterReconciler) isReadOnly(ctx context.Context, router *v1alpha1.NotificationRouter) (bool, error) { + if router.Status.HasReadonlyCondition() { + return router.Status.IsReadonly(), nil + } + + if controllerutil.ContainsFinalizer(router, NotificationRouterFinalizer) { + return false, nil + } + + if !router.Spec.HasName() { + return false, nil + } + + _, err := r.ConsoleClient.GetNotificationRouterByName(ctx, *router.Spec.Name) + if err != nil { + if errors.IsNotFound(err) { + return false, nil + } + return false, err + } + + return true, nil +} + +func (r *NotificationRouterReconciler) handleExisting(ctx context.Context, router *v1alpha1.NotificationRouter) (ctrl.Result, error) { + logger := log.FromContext(ctx) + logger.Info("handle existing notification router", "name", *router.Spec.Name) + existing, err := r.ConsoleClient.GetNotificationRouterByName(ctx, *router.Spec.Name) + if errors.IsNotFound(err) { + router.Status.ID = nil + utils.MarkCondition(router.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonNotFound, "Could not find NotificationSink in Console API") + return ctrl.Result{}, nil + } + if err != nil { + utils.MarkCondition(router.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, err.Error()) + return ctrl.Result{}, err + } + router.Status.ID = &existing.ID + utils.MarkCondition(router.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionTrue, v1alpha1.SynchronizedConditionReason, "") + + return requeue, nil +} + +func (r *NotificationRouterReconciler) isAlreadyExists(ctx context.Context, router *v1alpha1.NotificationRouter) (bool, error) { + if !router.Status.HasID() { + return false, nil + } + + _, err := r.ConsoleClient.GetNotificationRouter(ctx, router.Status.GetID()) + if err != nil { + if errors.IsNotFound(err) { + return false, nil + } + return false, err + } + + return true, nil +} diff --git a/controller/internal/controller/notificationrouter_scope.go b/controller/internal/controller/notificationrouter_scope.go new file mode 100644 index 0000000000..265b787009 --- /dev/null +++ b/controller/internal/controller/notificationrouter_scope.go @@ -0,0 +1,40 @@ +package controller + +import ( + "context" + "errors" + "fmt" + + "github.com/pluralsh/console/controller/api/v1alpha1" + "sigs.k8s.io/cluster-api/util/patch" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +type NotificationRouterScope struct { + Client client.Client + NotificationRouter *v1alpha1.NotificationRouter + ctx context.Context + patchHelper *patch.Helper +} + +func (p *NotificationRouterScope) PatchObject() error { + return p.patchHelper.Patch(p.ctx, p.NotificationRouter) +} + +func NewNotificationRouterScope(ctx context.Context, client client.Client, notification *v1alpha1.NotificationRouter) (*NotificationRouterScope, error) { + if notification == nil { + return nil, errors.New("failed to create new notificationRouter scope, got nil notificationRouter") + } + + helper, err := patch.NewHelper(notification, client) + if err != nil { + return nil, fmt.Errorf("failed to create new notification router scope, go error: %s", err) + } + + return &NotificationRouterScope{ + Client: client, + NotificationRouter: notification, + ctx: ctx, + patchHelper: helper, + }, nil +} diff --git a/controller/internal/controller/notificationsink_controller.go b/controller/internal/controller/notificationsink_controller.go index fd67c08bda..f7256679e8 100644 --- a/controller/internal/controller/notificationsink_controller.go +++ b/controller/internal/controller/notificationsink_controller.go @@ -106,7 +106,7 @@ func (r *NotificationSinkReconciler) Reconcile(ctx context.Context, req ctrl.Req } if !exists || !notificationSink.Status.IsSHAEqual(sha) { logger.Info("upsert notification sink", "name", notificationSink.NotificationName()) - ns, err := r.ConsoleClient.UpsertNotificationSink(ctx, genAttr(notificationSink)) + ns, err := r.ConsoleClient.UpsertNotificationSink(ctx, genNotificationSinkAttr(notificationSink)) if err != nil { utils.MarkCondition(notificationSink.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonError, err.Error()) return ctrl.Result{}, err @@ -224,7 +224,7 @@ func (r *NotificationSinkReconciler) SetupWithManager(mgr ctrl.Manager) error { Complete(r) } -func genAttr(notificationSink *v1alpha1.NotificationSink) console.NotificationSinkAttributes { +func genNotificationSinkAttr(notificationSink *v1alpha1.NotificationSink) console.NotificationSinkAttributes { attr := console.NotificationSinkAttributes{ Name: notificationSink.NotificationName(), Type: notificationSink.Spec.Type, diff --git a/controller/internal/test/mocks/ConsoleClient_mock.go b/controller/internal/test/mocks/ConsoleClient_mock.go index e72b446af0..9965d6786c 100644 --- a/controller/internal/test/mocks/ConsoleClient_mock.go +++ b/controller/internal/test/mocks/ConsoleClient_mock.go @@ -723,6 +723,53 @@ func (_c *ConsoleClientMock_DeleteGlobalService_Call) RunAndReturn(run func(stri return _c } +// DeleteNotificationRouter provides a mock function with given fields: ctx, id +func (_m *ConsoleClientMock) DeleteNotificationRouter(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for DeleteNotificationRouter") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ConsoleClientMock_DeleteNotificationRouter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteNotificationRouter' +type ConsoleClientMock_DeleteNotificationRouter_Call struct { + *mock.Call +} + +// DeleteNotificationRouter is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *ConsoleClientMock_Expecter) DeleteNotificationRouter(ctx interface{}, id interface{}) *ConsoleClientMock_DeleteNotificationRouter_Call { + return &ConsoleClientMock_DeleteNotificationRouter_Call{Call: _e.mock.On("DeleteNotificationRouter", ctx, id)} +} + +func (_c *ConsoleClientMock_DeleteNotificationRouter_Call) Run(run func(ctx context.Context, id string)) *ConsoleClientMock_DeleteNotificationRouter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *ConsoleClientMock_DeleteNotificationRouter_Call) Return(_a0 error) *ConsoleClientMock_DeleteNotificationRouter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ConsoleClientMock_DeleteNotificationRouter_Call) RunAndReturn(run func(context.Context, string) error) *ConsoleClientMock_DeleteNotificationRouter_Call { + _c.Call.Return(run) + return _c +} + // DeleteNotificationSink provides a mock function with given fields: ctx, id func (_m *ConsoleClientMock) DeleteNotificationSink(ctx context.Context, id string) error { ret := _m.Called(ctx, id) @@ -1412,6 +1459,124 @@ func (_c *ConsoleClientMock_GetGroup_Call) RunAndReturn(run func(string) (*gqlcl return _c } +// GetNotificationRouter provides a mock function with given fields: ctx, id +func (_m *ConsoleClientMock) GetNotificationRouter(ctx context.Context, id string) (*gqlclient.NotificationRouterFragment, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetNotificationRouter") + } + + var r0 *gqlclient.NotificationRouterFragment + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*gqlclient.NotificationRouterFragment, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *gqlclient.NotificationRouterFragment); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gqlclient.NotificationRouterFragment) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ConsoleClientMock_GetNotificationRouter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNotificationRouter' +type ConsoleClientMock_GetNotificationRouter_Call struct { + *mock.Call +} + +// GetNotificationRouter is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *ConsoleClientMock_Expecter) GetNotificationRouter(ctx interface{}, id interface{}) *ConsoleClientMock_GetNotificationRouter_Call { + return &ConsoleClientMock_GetNotificationRouter_Call{Call: _e.mock.On("GetNotificationRouter", ctx, id)} +} + +func (_c *ConsoleClientMock_GetNotificationRouter_Call) Run(run func(ctx context.Context, id string)) *ConsoleClientMock_GetNotificationRouter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *ConsoleClientMock_GetNotificationRouter_Call) Return(_a0 *gqlclient.NotificationRouterFragment, _a1 error) *ConsoleClientMock_GetNotificationRouter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ConsoleClientMock_GetNotificationRouter_Call) RunAndReturn(run func(context.Context, string) (*gqlclient.NotificationRouterFragment, error)) *ConsoleClientMock_GetNotificationRouter_Call { + _c.Call.Return(run) + return _c +} + +// GetNotificationRouterByName provides a mock function with given fields: ctx, name +func (_m *ConsoleClientMock) GetNotificationRouterByName(ctx context.Context, name string) (*gqlclient.NotificationRouterFragment, error) { + ret := _m.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for GetNotificationRouterByName") + } + + var r0 *gqlclient.NotificationRouterFragment + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*gqlclient.NotificationRouterFragment, error)); ok { + return rf(ctx, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *gqlclient.NotificationRouterFragment); ok { + r0 = rf(ctx, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gqlclient.NotificationRouterFragment) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ConsoleClientMock_GetNotificationRouterByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNotificationRouterByName' +type ConsoleClientMock_GetNotificationRouterByName_Call struct { + *mock.Call +} + +// GetNotificationRouterByName is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *ConsoleClientMock_Expecter) GetNotificationRouterByName(ctx interface{}, name interface{}) *ConsoleClientMock_GetNotificationRouterByName_Call { + return &ConsoleClientMock_GetNotificationRouterByName_Call{Call: _e.mock.On("GetNotificationRouterByName", ctx, name)} +} + +func (_c *ConsoleClientMock_GetNotificationRouterByName_Call) Run(run func(ctx context.Context, name string)) *ConsoleClientMock_GetNotificationRouterByName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *ConsoleClientMock_GetNotificationRouterByName_Call) Return(_a0 *gqlclient.NotificationRouterFragment, _a1 error) *ConsoleClientMock_GetNotificationRouterByName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ConsoleClientMock_GetNotificationRouterByName_Call) RunAndReturn(run func(context.Context, string) (*gqlclient.NotificationRouterFragment, error)) *ConsoleClientMock_GetNotificationRouterByName_Call { + _c.Call.Return(run) + return _c +} + // GetNotificationSink provides a mock function with given fields: ctx, id func (_m *ConsoleClientMock) GetNotificationSink(ctx context.Context, id string) (*gqlclient.NotificationSinkFragment, error) { ret := _m.Called(ctx, id) @@ -3453,6 +3618,65 @@ func (_c *ConsoleClientMock_UpdateService_Call) RunAndReturn(run func(string, gq return _c } +// UpsertNotificationRouter provides a mock function with given fields: ctx, attr +func (_m *ConsoleClientMock) UpsertNotificationRouter(ctx context.Context, attr gqlclient.NotificationRouterAttributes) (*gqlclient.NotificationRouterFragment, error) { + ret := _m.Called(ctx, attr) + + if len(ret) == 0 { + panic("no return value specified for UpsertNotificationRouter") + } + + var r0 *gqlclient.NotificationRouterFragment + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gqlclient.NotificationRouterAttributes) (*gqlclient.NotificationRouterFragment, error)); ok { + return rf(ctx, attr) + } + if rf, ok := ret.Get(0).(func(context.Context, gqlclient.NotificationRouterAttributes) *gqlclient.NotificationRouterFragment); ok { + r0 = rf(ctx, attr) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gqlclient.NotificationRouterFragment) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gqlclient.NotificationRouterAttributes) error); ok { + r1 = rf(ctx, attr) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ConsoleClientMock_UpsertNotificationRouter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpsertNotificationRouter' +type ConsoleClientMock_UpsertNotificationRouter_Call struct { + *mock.Call +} + +// UpsertNotificationRouter is a helper method to define mock.On call +// - ctx context.Context +// - attr gqlclient.NotificationRouterAttributes +func (_e *ConsoleClientMock_Expecter) UpsertNotificationRouter(ctx interface{}, attr interface{}) *ConsoleClientMock_UpsertNotificationRouter_Call { + return &ConsoleClientMock_UpsertNotificationRouter_Call{Call: _e.mock.On("UpsertNotificationRouter", ctx, attr)} +} + +func (_c *ConsoleClientMock_UpsertNotificationRouter_Call) Run(run func(ctx context.Context, attr gqlclient.NotificationRouterAttributes)) *ConsoleClientMock_UpsertNotificationRouter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gqlclient.NotificationRouterAttributes)) + }) + return _c +} + +func (_c *ConsoleClientMock_UpsertNotificationRouter_Call) Return(_a0 *gqlclient.NotificationRouterFragment, _a1 error) *ConsoleClientMock_UpsertNotificationRouter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ConsoleClientMock_UpsertNotificationRouter_Call) RunAndReturn(run func(context.Context, gqlclient.NotificationRouterAttributes) (*gqlclient.NotificationRouterFragment, error)) *ConsoleClientMock_UpsertNotificationRouter_Call { + _c.Call.Return(run) + return _c +} + // UpsertNotificationSink provides a mock function with given fields: ctx, attr func (_m *ConsoleClientMock) UpsertNotificationSink(ctx context.Context, attr gqlclient.NotificationSinkAttributes) (*gqlclient.NotificationSinkFragment, error) { ret := _m.Called(ctx, attr) diff --git a/controller/internal/types/reconciler.go b/controller/internal/types/reconciler.go index fea1582e64..495d0be137 100644 --- a/controller/internal/types/reconciler.go +++ b/controller/internal/types/reconciler.go @@ -26,6 +26,7 @@ const ( ClusterRestoreTriggerReconciler Reconciler = "restoretrigger" PrAutomationTriggerReconciler Reconciler = "prautomationtrigger" NotificationSinkReconciler Reconciler = "notificationsink" + NotificationRouterReconciler Reconciler = "notificationrouter" ) // ToReconciler maps reconciler string to a Reconciler type. @@ -55,6 +56,8 @@ func ToReconciler(reconciler string) (Reconciler, error) { fallthrough case NotificationSinkReconciler: fallthrough + case NotificationRouterReconciler: + fallthrough case ProviderReconciler: return Reconciler(reconciler), nil } @@ -143,6 +146,12 @@ func (sc Reconciler) ToController(mgr ctrl.Manager, consoleClient client.Console ConsoleClient: consoleClient, Scheme: mgr.GetScheme(), }, nil + case NotificationRouterReconciler: + return &controller.NotificationRouterReconciler{ + Client: mgr.GetClient(), + ConsoleClient: consoleClient, + Scheme: mgr.GetScheme(), + }, nil default: return nil, fmt.Errorf("reconciler %q is not supported", sc) } @@ -155,7 +164,7 @@ type ReconcilerList []Reconciler // Reconcilers defines a list of reconcilers that will be started by default // if '--reconcilers=...' flag is not provided. func Reconcilers() ReconcilerList { - return []Reconciler{GitRepositoryReconciler, ProviderReconciler, ClusterReconciler, ServiceDeploymentReconciler, GlobalServiceReconciler, PipelineReconciler, ScmConnectionReconciler, PrAutomationReconciler, PipelineContextReconciler, PrAutomationTriggerReconciler, ClusterRestoreTriggerReconciler, NotificationSinkReconciler} + return []Reconciler{GitRepositoryReconciler, ProviderReconciler, ClusterReconciler, ServiceDeploymentReconciler, GlobalServiceReconciler, PipelineReconciler, ScmConnectionReconciler, PrAutomationReconciler, PipelineContextReconciler, PrAutomationTriggerReconciler, ClusterRestoreTriggerReconciler, NotificationSinkReconciler, NotificationRouterReconciler} } // ToControllers returns a list of Controller instances based on this Reconciler array. diff --git a/plural/helm/console/crds/deployments.plural.sh_notificationrouters.yaml b/plural/helm/console/crds/deployments.plural.sh_notificationrouters.yaml new file mode 100644 index 0000000000..cd72e8e75e --- /dev/null +++ b/plural/helm/console/crds/deployments.plural.sh_notificationrouters.yaml @@ -0,0 +1,289 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: notificationrouters.deployments.plural.sh +spec: + group: deployments.plural.sh + names: + kind: NotificationRouter + listKind: NotificationRouterList + plural: notificationrouters + singular: notificationrouter + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: NotificationRouter is the Schema for the notificationrouters + API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: NotificationRouterSpec defines the desired state of NotificationRouter + properties: + events: + description: Events the events to trigger, or use * for any + items: + type: string + type: array + filters: + description: Filters filters by object type + items: + properties: + clusterRef: + description: ClusterRef whether to enable delivery for events + associated with this cluster + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + pipelineRef: + description: PipelineRef whether to enable delivery for events + associated with this pipeline + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + regex: + description: Regex a regex for filtering by things like pr url + type: string + serviceRef: + description: ServiceRef whether to enable delivery for events + associated with this service + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: |- + If referring to a piece of an object instead of an entire object, this string + should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within a pod, this would take on a value like: + "spec.containers{name}" (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" (container with + index 2 in this pod). This syntax is chosen only to have some well-defined way of + referencing a part of an object. + TODO: this design is not final and this field is subject to change in the future. + type: string + kind: + description: |- + Kind of the referent. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + namespace: + description: |- + Namespace of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ + type: string + resourceVersion: + description: |- + Specific resourceVersion to which this reference is made, if any. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency + type: string + uid: + description: |- + UID of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids + type: string + type: object + x-kubernetes-map-type: atomic + type: object + type: array + name: + description: Name the name of this router, if not provided NotificationRouter's + own name from NotificationRouter.ObjectMeta will be used. + type: string + routerSinks: + description: RouterSinks sinks to deliver notifications to + items: + type: string + type: array + type: object + status: + properties: + conditions: + description: Represents the observations of a PrAutomation's current + state. + items: + description: "Condition contains details for one aspect of the current + state of this API Resource.\n---\nThis struct is intended for + direct use as an array at the field path .status.conditions. For + example,\n\n\n\ttype FooStatus struct{\n\t // Represents the + observations of a foo's current state.\n\t // Known .status.conditions.type + are: \"Available\", \"Progressing\", and \"Degraded\"\n\t // + +patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t + \ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\" + patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t + \ // other fields\n\t}" + properties: + lastTransitionTime: + description: |- + lastTransitionTime is the last time the condition transitioned from one status to another. + This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. + format: date-time + type: string + message: + description: |- + message is a human readable message indicating details about the transition. + This may be an empty string. + maxLength: 32768 + type: string + observedGeneration: + description: |- + observedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + minimum: 0 + type: integer + reason: + description: |- + reason contains a programmatic identifier indicating the reason for the condition's last transition. + Producers of specific condition types may define expected values and meanings for this field, + and whether the values are considered a guaranteed API. + The value should be a CamelCase string. + This field may not be empty. + maxLength: 1024 + minLength: 1 + pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ + type: string + status: + description: status of the condition, one of True, False, Unknown. + enum: + - "True" + - "False" + - Unknown + type: string + type: + description: |- + type of condition in CamelCase or in foo.example.com/CamelCase. + --- + Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be + useful (see .node.status.conditions), the ability to deconflict is important. + The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) + maxLength: 316 + pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ + type: string + required: + - lastTransitionTime + - message + - reason + - status + - type + type: object + type: array + x-kubernetes-list-map-keys: + - type + x-kubernetes-list-type: map + id: + description: ID of the resource in the Console API. + type: string + sha: + description: SHA of last applied configuration. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/plural/helm/console/crds/deployments.plural.sh_notificationsinks.yaml b/plural/helm/console/crds/deployments.plural.sh_notificationsinks.yaml index ebde261c94..9ce483fcc9 100644 --- a/plural/helm/console/crds/deployments.plural.sh_notificationsinks.yaml +++ b/plural/helm/console/crds/deployments.plural.sh_notificationsinks.yaml @@ -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.