|
| 1 | +/* |
| 2 | +Copyright 2022 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 v1beta2 |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/fluxcd/pkg/apis/meta" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | +) |
| 23 | + |
| 24 | +const ( |
| 25 | + AlertKind string = "Alert" |
| 26 | +) |
| 27 | + |
| 28 | +// AlertSpec defines an alerting rule for events involving a list of objects. |
| 29 | +type AlertSpec struct { |
| 30 | + // ProviderRef specifies which Provider this Alert should use. |
| 31 | + // +required |
| 32 | + ProviderRef meta.LocalObjectReference `json:"providerRef"` |
| 33 | + |
| 34 | + // EventSeverity specifies how to filter events based on severity. |
| 35 | + // If set to 'info' no events will be filtered. |
| 36 | + // +kubebuilder:validation:Enum=info;error |
| 37 | + // +kubebuilder:default:=info |
| 38 | + // +optional |
| 39 | + EventSeverity string `json:"eventSeverity,omitempty"` |
| 40 | + |
| 41 | + // EventSources specifies how to filter events based |
| 42 | + // on the involved object kind, name and namespace. |
| 43 | + // +required |
| 44 | + EventSources []CrossNamespaceObjectReference `json:"eventSources"` |
| 45 | + |
| 46 | + // ExclusionList specifies a list of Golang regular expressions |
| 47 | + // to be used for excluding messages. |
| 48 | + // +optional |
| 49 | + ExclusionList []string `json:"exclusionList,omitempty"` |
| 50 | + |
| 51 | + // Summary holds a short description of the impact and affected cluster. |
| 52 | + // +kubebuilder:validation:MaxLength:=255 |
| 53 | + // +optional |
| 54 | + Summary string `json:"summary,omitempty"` |
| 55 | + |
| 56 | + // Suspend tells the controller to suspend subsequent |
| 57 | + // events handling for this Alert. |
| 58 | + // +optional |
| 59 | + Suspend bool `json:"suspend,omitempty"` |
| 60 | +} |
| 61 | + |
| 62 | +// AlertStatus defines the observed state of the Alert. |
| 63 | +type AlertStatus struct { |
| 64 | + meta.ReconcileRequestStatus `json:",inline"` |
| 65 | + |
| 66 | + // Conditions holds the conditions for the Alert. |
| 67 | + // +optional |
| 68 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 69 | + |
| 70 | + // ObservedGeneration is the last observed generation. |
| 71 | + // +optional |
| 72 | + ObservedGeneration int64 `json:"observedGeneration,omitempty"` |
| 73 | +} |
| 74 | + |
| 75 | +// +genclient |
| 76 | +// +genclient:Namespaced |
| 77 | +// +kubebuilder:storageversion |
| 78 | +// +kubebuilder:object:root=true |
| 79 | +// +kubebuilder:subresource:status |
| 80 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="" |
| 81 | +// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description="" |
| 82 | +// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description="" |
| 83 | + |
| 84 | +// Alert is the Schema for the alerts API |
| 85 | +type Alert struct { |
| 86 | + metav1.TypeMeta `json:",inline"` |
| 87 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 88 | + |
| 89 | + Spec AlertSpec `json:"spec,omitempty"` |
| 90 | + // +kubebuilder:default:={"observedGeneration":-1} |
| 91 | + Status AlertStatus `json:"status,omitempty"` |
| 92 | +} |
| 93 | + |
| 94 | +// GetConditions returns the status conditions of the object. |
| 95 | +func (in *Alert) GetConditions() []metav1.Condition { |
| 96 | + return in.Status.Conditions |
| 97 | +} |
| 98 | + |
| 99 | +// SetConditions sets the status conditions on the object. |
| 100 | +func (in *Alert) SetConditions(conditions []metav1.Condition) { |
| 101 | + in.Status.Conditions = conditions |
| 102 | +} |
| 103 | + |
| 104 | +// +kubebuilder:object:root=true |
| 105 | + |
| 106 | +// AlertList contains a list of Alerts. |
| 107 | +type AlertList struct { |
| 108 | + metav1.TypeMeta `json:",inline"` |
| 109 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 110 | + Items []Alert `json:"items"` |
| 111 | +} |
| 112 | + |
| 113 | +func init() { |
| 114 | + SchemeBuilder.Register(&Alert{}, &AlertList{}) |
| 115 | +} |
0 commit comments