44 "context"
55 "time"
66
7- "github.com/openshift/ocm-agent/pkg/ocm"
8-
97 "github.com/prometheus/alertmanager/template"
108 corev1 "k8s.io/api/core/v1"
119 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -14,6 +12,7 @@ import (
1412 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
1513
1614 ocmagentv1alpha1 "github.com/openshift/ocm-agent-operator/api/v1alpha1"
15+ "github.com/openshift/ocm-agent/pkg/ocm"
1716)
1817
1918const (
5958 },
6059 },
6160 }
62- TestFleetNotification = ocmagentv1alpha1.FleetNotification {
63- Name : TestNotificationName ,
64- Summary : "test-summary" ,
65- NotificationMessage : "test-notification" ,
66- Severity : "test-severity" ,
67- ResendWait : 1 ,
68- }
69- TestManagedFleetNotification = ocmagentv1alpha1.ManagedFleetNotification {
70- ObjectMeta : metav1.ObjectMeta {
71- Name : "test-mfn" ,
72- Namespace : "openshift-ocm-agent-operator" ,
73- },
74- Spec : ocmagentv1alpha1.ManagedFleetNotificationSpec {
75- FleetNotification : TestFleetNotification ,
76- },
77- }
78- TestManagedFleetNotificationRecord = ocmagentv1alpha1.ManagedFleetNotificationRecord {
79- ObjectMeta : metav1.ObjectMeta {
80- Name : TestManagedClusterID ,
81- Namespace : "openshift-ocm-agent-operator" ,
82- },
83- Status : ocmagentv1alpha1.ManagedFleetNotificationRecordStatus {},
84- }
8561 TestManagedNotification = ocmagentv1alpha1.ManagedNotification {
8662 ObjectMeta : metav1.ObjectMeta {
8763 Name : "test-mn" ,
@@ -105,46 +81,54 @@ var (
10581 Notifications : []ocmagentv1alpha1.Notification {TestNotification },
10682 },
10783 }
108- TestAlert = template.Alert {
109- Status : "firing" ,
110- Labels : map [string ]string {
111- "managed_notification_template" : TestNotificationName ,
112- "send_managed_notification" : "true" ,
113- "alertname" : "TestAlertName" ,
114- "alertstate" : "firing" ,
115- "namespace" : "openshift-monitoring" ,
116- "openshift_io_alert_source" : "platform" ,
117- "prometheus" : "openshift-monitoring/k8s" ,
118- "severity" : "info" ,
84+ TestManagedNotificationList = & ocmagentv1alpha1.ManagedNotificationList {
85+ Items : []ocmagentv1alpha1.ManagedNotification {
86+ TestManagedNotification ,
11987 },
120- StartsAt : time .Now (),
121- EndsAt : time.Time {},
12288 }
123- TestFleetAlert = template.Alert {
124- Status : "firing" ,
125- Labels : map [string ]string {
126- "managed_notification_template" : TestNotificationName ,
127- "send_managed_notification" : "true" ,
128- "alertname" : "TestAlertName" ,
129- "alertstate" : "firing" ,
130- "namespace" : "openshift-monitoring" ,
131- "openshift_io_alert_source" : "platform" ,
132- "prometheus" : "openshift-monitoring/k8s" ,
133- "severity" : "info" ,
134- "source" : "HCP" ,
135- "_mc_id" : TestManagedClusterID ,
136- "_id" : TestHostedClusterID ,
89+ )
90+
91+ func NewFleetNotification () ocmagentv1alpha1.FleetNotification {
92+ return ocmagentv1alpha1.FleetNotification {
93+ Name : TestNotificationName ,
94+ Summary : "test-summary" ,
95+ NotificationMessage : "test-notification" ,
96+ Severity : "test-severity" ,
97+ ResendWait : 1 ,
98+ }
99+ }
100+
101+ func NewManagedFleetNotification () ocmagentv1alpha1.ManagedFleetNotification {
102+ return ocmagentv1alpha1.ManagedFleetNotification {
103+ ObjectMeta : metav1.ObjectMeta {
104+ Name : "test-mfn" ,
105+ Namespace : "openshift-ocm-agent-operator" ,
106+ },
107+ Spec : ocmagentv1alpha1.ManagedFleetNotificationSpec {
108+ FleetNotification : NewFleetNotification (),
109+ },
110+ }
111+ }
112+
113+ func NewManagedFleetNotificationRecord () ocmagentv1alpha1.ManagedFleetNotificationRecord {
114+ return ocmagentv1alpha1.ManagedFleetNotificationRecord {
115+ ObjectMeta : metav1.ObjectMeta {
116+ Name : TestManagedClusterID ,
117+ Namespace : "openshift-ocm-agent-operator" ,
118+ },
119+ Status : ocmagentv1alpha1.ManagedFleetNotificationRecordStatus {
120+ ManagementCluster : TestManagedClusterID ,
121+ NotificationRecordByName : nil ,
137122 },
138- StartsAt : time .Now (),
139- EndsAt : time.Time {},
140123 }
141- TestAlertResolved = template.Alert {
142- Status : "resolved" ,
124+ }
125+
126+ func NewTestAlert (resolved , fleet bool ) template.Alert {
127+ alert := template.Alert {
143128 Labels : map [string ]string {
144129 "managed_notification_template" : TestNotificationName ,
145130 "send_managed_notification" : "true" ,
146131 "alertname" : "TestAlertName" ,
147- "alertstate" : "resolved" ,
148132 "namespace" : "openshift-monitoring" ,
149133 "openshift_io_alert_source" : "platform" ,
150134 "prometheus" : "openshift-monitoring/k8s" ,
@@ -153,26 +137,27 @@ var (
153137 StartsAt : time .Now (),
154138 EndsAt : time.Time {},
155139 }
156- TestManagedNotificationList = & ocmagentv1alpha1.ManagedNotificationList {
157- Items : []ocmagentv1alpha1.ManagedNotification {
158- TestManagedNotification ,
159- },
140+ if resolved {
141+ alert .Status = "resolved"
142+ alert .Labels ["alertstate" ] = "resolved"
160143 }
161- TestActiveServiceLog = ocm.ServiceLog {
162- ServiceName : "SREManualAction" ,
163- ClusterUUID : "ddb5e04c-87ea-4fcd-b1f9-640981726cc5" ,
164- Summary : "Test SL Summary" ,
165- InternalOnly : false ,
166- Description : TestNotification .ActiveDesc ,
144+ if fleet {
145+ alert .Labels ["source" ] = "HCP"
146+ alert .Labels ["_mc_id" ] = TestManagedClusterID
147+ alert .Labels ["_id" ] = TestHostedClusterID
167148 }
168- TestResolvedServiceLog = ocm.ServiceLog {
149+ return alert
150+ }
151+
152+ func NewServiceLog (summary , desc string ) ocm.ServiceLog {
153+ return ocm.ServiceLog {
169154 ServiceName : "SREManualAction" ,
170155 ClusterUUID : "ddb5e04c-87ea-4fcd-b1f9-640981726cc5" ,
171- Summary : "Test SL Summary" ,
156+ Summary : summary ,
172157 InternalOnly : false ,
173- Description : TestNotification . ResolvedDesc ,
158+ Description : desc ,
174159 }
175- )
160+ }
176161
177162func setScheme (scheme * runtime.Scheme ) * runtime.Scheme {
178163 utilruntime .Must (clientgoscheme .AddToScheme (scheme ))
0 commit comments