|
| 1 | +/* |
| 2 | +Copyright 2023 The Flux authors |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1beta4 |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/fluxcd/pkg/apis/meta" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | + |
| 23 | + v1 "github.com/fluxcd/notification-controller/api/v1" |
| 24 | +) |
| 25 | + |
| 26 | +const ( |
| 27 | + AlertKind string = "Alert" |
| 28 | +) |
| 29 | + |
| 30 | +// AlertSpec defines an alerting rule for events involving a list of objects. |
| 31 | +type AlertSpec struct { |
| 32 | + // ProviderRef specifies which Provider this Alert should use. |
| 33 | + // +required |
| 34 | + ProviderRef meta.NamespacedObjectReference `json:"providerRef"` |
| 35 | + |
| 36 | + // EventSeverity specifies how to filter events based on severity. |
| 37 | + // If set to 'info' no events will be filtered. |
| 38 | + // +kubebuilder:validation:Enum=info;error |
| 39 | + // +kubebuilder:default:=info |
| 40 | + // +optional |
| 41 | + EventSeverity string `json:"eventSeverity,omitempty"` |
| 42 | + |
| 43 | + // EventSources specifies how to filter events based |
| 44 | + // on the involved object kind, name and namespace. |
| 45 | + // +required |
| 46 | + EventSources []v1.CrossNamespaceObjectReference `json:"eventSources"` |
| 47 | + |
| 48 | + // InclusionList specifies a list of Golang regular expressions |
| 49 | + // to be used for including messages. |
| 50 | + // +optional |
| 51 | + InclusionList []string `json:"inclusionList,omitempty"` |
| 52 | + |
| 53 | + // EventMetadata is an optional field for adding metadata to events dispatched by the |
| 54 | + // controller. This can be used for enhancing the context of the event. If a field |
| 55 | + // would override one already present on the original event as generated by the emitter, |
| 56 | + // then the override doesn't happen, i.e. the original value is preserved, and an info |
| 57 | + // log is printed. |
| 58 | + // +optional |
| 59 | + EventMetadata map[string]string `json:"eventMetadata,omitempty"` |
| 60 | + |
| 61 | + // ExclusionList specifies a list of Golang regular expressions |
| 62 | + // to be used for excluding messages. |
| 63 | + // +optional |
| 64 | + ExclusionList []string `json:"exclusionList,omitempty"` |
| 65 | + |
| 66 | + // Summary holds a short description of the impact and affected cluster. |
| 67 | + // +kubebuilder:validation:MaxLength:=255 |
| 68 | + // +optional |
| 69 | + Summary string `json:"summary,omitempty"` |
| 70 | + |
| 71 | + // Suspend tells the controller to suspend subsequent |
| 72 | + // events handling for this Alert. |
| 73 | + // +optional |
| 74 | + Suspend bool `json:"suspend,omitempty"` |
| 75 | + |
| 76 | + // Channel specifies the destination channel where events should be posted. |
| 77 | + // This will override any default channel that might be set in the provider |
| 78 | + // +kubebuilder:validation:MaxLength:=2048 |
| 79 | + // +optional |
| 80 | + Channel string `json:"channel,omitempty"` |
| 81 | +} |
| 82 | + |
| 83 | +// +genclient |
| 84 | +// +genclient:Namespaced |
| 85 | +// +kubebuilder:storageversion |
| 86 | +// +kubebuilder:object:root=true |
| 87 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="" |
| 88 | + |
| 89 | +// Alert is the Schema for the alerts API |
| 90 | +type Alert struct { |
| 91 | + metav1.TypeMeta `json:",inline"` |
| 92 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 93 | + |
| 94 | + Spec AlertSpec `json:"spec,omitempty"` |
| 95 | +} |
| 96 | + |
| 97 | +//+kubebuilder:object:root=true |
| 98 | + |
| 99 | +// AlertList contains a list of Alert |
| 100 | +type AlertList struct { |
| 101 | + metav1.TypeMeta `json:",inline"` |
| 102 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 103 | + Items []Alert `json:"items"` |
| 104 | +} |
| 105 | + |
| 106 | +func init() { |
| 107 | + SchemeBuilder.Register(&Alert{}, &AlertList{}) |
| 108 | +} |
0 commit comments