@@ -86,6 +86,7 @@ func Test_sync_with_cv(t *testing.T) {
86
86
name string
87
87
cvProgressing * configv1.ClusterOperatorStatusCondition
88
88
cvHistory []configv1.UpdateHistory
89
+ cvAnnotations map [string ]string
89
90
90
91
expectedMsgs map [string ]ControlPlaneInsight
91
92
}{
@@ -193,11 +194,72 @@ func Test_sync_with_cv(t *testing.T) {
193
194
},
194
195
},
195
196
},
197
+ {
198
+ name : "Cluster during a standard update with forced health insight" ,
199
+ cvProgressing : & progressingTrue ,
200
+ cvHistory : []configv1.UpdateHistory {inProgress419 , completed418 },
201
+ cvAnnotations : map [string ]string {
202
+ uscForceHealthInsightAnnotation : "value-does-not-matter" ,
203
+ },
204
+ expectedMsgs : map [string ]ControlPlaneInsight {
205
+ "usc-0kmuaUQRUJDOAIAF1KWTmg" : {
206
+ UID : "usc-0kmuaUQRUJDOAIAF1KWTmg" ,
207
+ AcquiredAt : now ,
208
+ ControlPlaneInsightUnion : ControlPlaneInsightUnion {
209
+ Type : HealthInsightType ,
210
+ HealthInsight : & HealthInsight {
211
+ StartedAt : now ,
212
+ Scope : InsightScope {
213
+ Type : ControlPlaneScope ,
214
+ Resources : []ResourceRef {
215
+ cvRef ,
216
+ },
217
+ },
218
+ Impact : InsightImpact {
219
+ Level : InfoImpactLevel ,
220
+ Type : NoneImpactType ,
221
+ Summary : "Forced health insight for ClusterVersion version" ,
222
+ Description : "The resource has a \" usc.openshift.io/force-health-insight\" annotation which forces USC to generate this health insight for testing purposes." ,
223
+ },
224
+ Remediation : InsightRemediation {
225
+ Reference : "https://issues.redhat.com/browse/OTA-1418" ,
226
+ },
227
+ },
228
+ },
229
+ },
230
+ "usc-cv-version" : {
231
+ UID : "usc-cv-version" ,
232
+ AcquiredAt : now ,
233
+ ControlPlaneInsightUnion : ControlPlaneInsightUnion {
234
+ Type : ClusterVersionStatusInsightType ,
235
+ ClusterVersionStatusInsight : & ClusterVersionStatusInsight {
236
+ Resource : cvRef ,
237
+ Assessment : ControlPlaneAssessmentProgressing ,
238
+ Versions : ControlPlaneUpdateVersions {
239
+ Target : Version {Version : "4.19.0" },
240
+ Previous : Version {Version : "4.18.0" },
241
+ },
242
+ Completion : 0 ,
243
+ StartedAt : minutesAgo [60 ],
244
+ EstimatedCompletedAt : & now ,
245
+ Conditions : []metav1.Condition {
246
+ newClusterVersionStatusInsightUpdating (
247
+ metav1 .ConditionTrue ,
248
+ ClusterVersionProgressing ,
249
+ "ClusterVersion has Progressing=True(Reason=ProgressingTrue) | Message='Cluster is progressing'" ,
250
+ now ,
251
+ ),
252
+ },
253
+ },
254
+ },
255
+ },
256
+ },
257
+ },
196
258
}
197
259
198
260
for _ , tc := range testCases {
199
261
t .Run (tc .name , func (t * testing.T ) {
200
- cv := makeTestClusterVersion (tc .cvProgressing , tc .cvHistory )
262
+ cv := makeTestClusterVersion (tc .cvProgressing , tc .cvHistory , tc . cvAnnotations )
201
263
202
264
cvIndexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {})
203
265
if err := cvIndexer .Add (cv ); err != nil {
@@ -235,7 +297,10 @@ func Test_sync_with_cv(t *testing.T) {
235
297
})
236
298
}
237
299
238
- if diff := cmp .Diff (expectedMsgs , actualMsgs , cmp .AllowUnexported (informerMsg {})); diff != "" {
300
+ ignoreOrder := cmpopts .SortSlices (func (a , b informerMsg ) bool {
301
+ return a .uid < b .uid
302
+ })
303
+ if diff := cmp .Diff (expectedMsgs , actualMsgs , ignoreOrder , cmp .AllowUnexported (informerMsg {})); diff != "" {
239
304
t .Errorf ("Sync messages differ from expected:\n %s" , diff )
240
305
}
241
306
})
@@ -531,9 +596,16 @@ func Test_sync_with_co(t *testing.T) {
531
596
}
532
597
}
533
598
534
- func makeTestClusterVersion (progressing * configv1.ClusterOperatorStatusCondition , history []configv1.UpdateHistory ) * configv1.ClusterVersion {
599
+ func makeTestClusterVersion (
600
+ progressing * configv1.ClusterOperatorStatusCondition ,
601
+ history []configv1.UpdateHistory ,
602
+ annotations map [string ]string ,
603
+ ) * configv1.ClusterVersion {
535
604
cv := & configv1.ClusterVersion {
536
- ObjectMeta : metav1.ObjectMeta {Name : "version" },
605
+ ObjectMeta : metav1.ObjectMeta {
606
+ Name : "version" ,
607
+ Annotations : annotations ,
608
+ },
537
609
Status : configv1.ClusterVersionStatus {
538
610
Conditions : []configv1.ClusterOperatorStatusCondition {},
539
611
History : []configv1.UpdateHistory {},
@@ -554,6 +626,7 @@ type testSyncContext struct {
554
626
queue workqueue.TypedRateLimitingInterface [any ]
555
627
}
556
628
629
+ //goland:noinspection GoDeprecation
557
630
func (c testSyncContext ) Queue () workqueue.RateLimitingInterface { //nolint:staticcheck
558
631
return c .queue
559
632
}
@@ -933,7 +1006,7 @@ func Test_assessClusterOperator(t *testing.T) {
933
1006
}
934
1007
}
935
1008
936
- func Test_assessClusterVersion (t * testing.T ) {
1009
+ func Test_assessClusterVersion_cvStatusInsight (t * testing.T ) {
937
1010
now := metav1 .Now ()
938
1011
var minutesAgo [120 ]metav1.Time
939
1012
for i := range minutesAgo {
@@ -1244,10 +1317,88 @@ func Test_assessClusterVersion(t *testing.T) {
1244
1317
Conditions : []configv1.ClusterOperatorStatusCondition {tc .cvProgressing },
1245
1318
},
1246
1319
}
1247
- actual := assessClusterVersion (cv , now )
1248
- if diff := cmp .Diff (tc .expected , actual , cmpopts . IgnoreFields (metav1. Condition {}, "LastTransitionTime" ) ); diff != "" {
1320
+ actualCvStatusInsight , healthInsights := assessClusterVersion (cv , now )
1321
+ if diff := cmp .Diff (tc .expected , actualCvStatusInsight ); diff != "" {
1249
1322
t .Errorf ("CV Status Insight differs from expected:\n %s" , diff )
1250
1323
}
1324
+
1325
+ if diff := cmp .Diff ([]* HealthInsight (nil ), healthInsights ); diff != "" {
1326
+ t .Errorf ("Unexpected health insights:\n %s" , diff )
1327
+ }
1328
+ })
1329
+ }
1330
+ }
1331
+
1332
+ func Test_assessClusterVersion_testingHealthInsight (t * testing.T ) {
1333
+ now := metav1 .Now ()
1334
+ var minutesAgo [30 ]metav1.Time
1335
+ for i := range minutesAgo {
1336
+ minutesAgo [i ] = metav1 .NewTime (now .Add (- time .Duration (i ) * time .Minute ))
1337
+ }
1338
+
1339
+ cvReference := ResourceRef {
1340
+ Resource : "clusterversions" ,
1341
+ Group : "config.openshift.io" ,
1342
+ Name : "version" ,
1343
+ }
1344
+
1345
+ testCases := []struct {
1346
+ name string
1347
+
1348
+ cvAnnotations map [string ]string
1349
+
1350
+ expected []* HealthInsight
1351
+ }{
1352
+ {
1353
+ name : "no annotations -> no insight" ,
1354
+ cvAnnotations : nil ,
1355
+ expected : nil ,
1356
+ },
1357
+ {
1358
+ name : "unrelated annotations -> no insight" ,
1359
+ cvAnnotations : map [string ]string {
1360
+ "foo" : "bar" ,
1361
+ },
1362
+ expected : nil ,
1363
+ },
1364
+ {
1365
+ name : "usc.openshift.io/force-health-insight=true -> health insight" ,
1366
+ cvAnnotations : map [string ]string {
1367
+ "usc.openshift.io/force-health-insight" : "value-does-not-matter" ,
1368
+ },
1369
+ expected : []* HealthInsight {
1370
+ {
1371
+ StartedAt : now ,
1372
+ Scope : InsightScope {
1373
+ Type : ControlPlaneScope ,
1374
+ Resources : []ResourceRef {cvReference },
1375
+ },
1376
+ Impact : InsightImpact {
1377
+ Level : InfoImpactLevel ,
1378
+ Type : NoneImpactType ,
1379
+ Summary : "Forced health insight for ClusterVersion version" ,
1380
+ Description : "The resource has a \" usc.openshift.io/force-health-insight\" annotation which forces USC to generate this health insight for testing purposes." ,
1381
+ },
1382
+ Remediation : InsightRemediation {
1383
+ Reference : "https://issues.redhat.com/browse/OTA-1418" ,
1384
+ },
1385
+ },
1386
+ },
1387
+ },
1388
+ }
1389
+ for _ , tc := range testCases {
1390
+ t .Run (tc .name , func (t * testing.T ) {
1391
+ cv := & configv1.ClusterVersion {
1392
+ ObjectMeta : metav1.ObjectMeta {
1393
+ Name : "version" ,
1394
+ Annotations : tc .cvAnnotations ,
1395
+ },
1396
+ }
1397
+ _ , healthInsights := assessClusterVersion (cv , now )
1398
+
1399
+ if diff := cmp .Diff (tc .expected , healthInsights ); diff != "" {
1400
+ t .Errorf ("Health insights differ from expected:\n %s" , diff )
1401
+ }
1251
1402
})
1252
1403
}
1253
1404
}
0 commit comments