@@ -92,6 +92,13 @@ func osusWithSingleConditionalEdge() (*httptest.Server, clusterconditions.Condit
92
92
},
93
93
},
94
94
Conditions : []metav1.Condition {
95
+ {
96
+ Type : "recommended/FourFiveSix" ,
97
+ Status : metav1 .ConditionFalse ,
98
+ Reason : "FourFiveSix" ,
99
+ Message : "Four Five Five is just fine https://example.com/" + to ,
100
+ LastTransitionTime : metav1 .Now (),
101
+ },
95
102
{
96
103
Type : "Recommended" ,
97
104
Status : metav1 .ConditionFalse ,
@@ -233,8 +240,10 @@ func TestSyncAvailableUpdates_ConditionalUpdateRecommendedConditions(t *testing.
233
240
availableUpdates , optr := newOperator (fakeOsus .URL , version , mockPromql )
234
241
optr .availableUpdates = availableUpdates
235
242
optr .availableUpdates .ConditionalUpdates = conditionalUpdates
236
- expectedConditions := []metav1.Condition {{}}
237
- conditionalUpdates [0 ].Conditions [0 ].DeepCopyInto (& expectedConditions [0 ])
243
+ expectedConditions := make ([]metav1.Condition , 0 , len (conditionalUpdates [0 ].Conditions ))
244
+ for _ , condition := range conditionalUpdates [0 ].Conditions {
245
+ expectedConditions = append (expectedConditions , * condition .DeepCopy ())
246
+ }
238
247
cv := cvFixture .DeepCopy ()
239
248
tc .modifyOriginalState (optr )
240
249
tc .modifyCV (cv , conditionalUpdates [0 ])
@@ -268,16 +277,16 @@ func TestEvaluateConditionalUpdate(t *testing.T) {
268
277
name string
269
278
risks []configv1.ConditionalUpdateRisk
270
279
mockPromql clusterconditions.Condition
271
- expected metav1.Condition
280
+ expected [] metav1.Condition
272
281
}{
273
282
{
274
283
name : "no risks" ,
275
- expected : metav1.Condition {
284
+ expected : [] metav1.Condition { {
276
285
Type : "Recommended" ,
277
286
Status : metav1 .ConditionTrue ,
278
287
Reason : recommendedReasonRisksNotExposed ,
279
288
Message : "The update is recommended, because none of the conditional update risks apply to this cluster." ,
280
- },
289
+ }} ,
281
290
},
282
291
{
283
292
name : "one risk that does not match" ,
@@ -293,12 +302,12 @@ func TestEvaluateConditionalUpdate(t *testing.T) {
293
302
ValidQueue : []error {nil },
294
303
MatchQueue : []mock.MatchResult {{Match : false , Error : nil }},
295
304
},
296
- expected : metav1.Condition {
305
+ expected : [] metav1.Condition { {
297
306
Type : "Recommended" ,
298
307
Status : metav1 .ConditionTrue ,
299
308
Reason : recommendedReasonRisksNotExposed ,
300
309
Message : "The update is recommended, because none of the conditional update risks apply to this cluster." ,
301
- },
310
+ }} ,
302
311
},
303
312
{
304
313
name : "one risk that matches" ,
@@ -314,12 +323,17 @@ func TestEvaluateConditionalUpdate(t *testing.T) {
314
323
ValidQueue : []error {nil },
315
324
MatchQueue : []mock.MatchResult {{Match : true , Error : nil }},
316
325
},
317
- expected : metav1.Condition {
326
+ expected : []metav1.Condition {{
327
+ Type : "recommended/RiskThatApplies" ,
328
+ Status : metav1 .ConditionFalse ,
329
+ Reason : "RiskThatApplies" ,
330
+ Message : "This is a risk! https://match.es" ,
331
+ }, {
318
332
Type : "Recommended" ,
319
333
Status : metav1 .ConditionFalse ,
320
334
Reason : "RiskThatApplies" ,
321
335
Message : "This is a risk! https://match.es" ,
322
- },
336
+ }} ,
323
337
},
324
338
{
325
339
name : "matching risk with name that cannot be used as a condition reason" ,
@@ -335,12 +349,17 @@ func TestEvaluateConditionalUpdate(t *testing.T) {
335
349
ValidQueue : []error {nil },
336
350
MatchQueue : []mock.MatchResult {{Match : true , Error : nil }},
337
351
},
338
- expected : metav1.Condition {
352
+ expected : []metav1.Condition {{
353
+ Type : "recommended/RISKTHATAPPLIES" ,
354
+ Status : metav1 .ConditionFalse ,
355
+ Reason : recommendedReasonExposed ,
356
+ Message : "This is a risk! https://match.es" ,
357
+ }, {
339
358
Type : "Recommended" ,
340
359
Status : metav1 .ConditionFalse ,
341
360
Reason : recommendedReasonExposed ,
342
361
Message : "This is a risk! https://match.es" ,
343
- },
362
+ }} ,
344
363
},
345
364
{
346
365
name : "two risks that match" ,
@@ -362,12 +381,22 @@ func TestEvaluateConditionalUpdate(t *testing.T) {
362
381
ValidQueue : []error {nil , nil },
363
382
MatchQueue : []mock.MatchResult {{Match : true , Error : nil }, {Match : true , Error : nil }},
364
383
},
365
- expected : metav1.Condition {
384
+ expected : []metav1.Condition {{
385
+ Type : "recommended/RiskThatApplies" ,
386
+ Status : metav1 .ConditionFalse ,
387
+ Reason : "RiskThatApplies" ,
388
+ Message : "This is a risk! https://match.es" ,
389
+ }, {
390
+ Type : "recommended/RiskThatAppliesToo" ,
391
+ Status : metav1 .ConditionFalse ,
392
+ Reason : "RiskThatAppliesToo" ,
393
+ Message : "This is a risk too! https://match.es/too" ,
394
+ }, {
366
395
Type : "Recommended" ,
367
396
Status : metav1 .ConditionFalse ,
368
397
Reason : recommendedReasonMultiple ,
369
398
Message : "This is a risk! https://match.es\n \n This is a risk too! https://match.es/too" ,
370
- },
399
+ }} ,
371
400
},
372
401
{
373
402
name : "first risk matches, second fails to evaluate" ,
@@ -389,15 +418,27 @@ func TestEvaluateConditionalUpdate(t *testing.T) {
389
418
ValidQueue : []error {nil , nil },
390
419
MatchQueue : []mock.MatchResult {{Match : true , Error : nil }, {Match : false , Error : errors .New ("ERROR" )}},
391
420
},
392
- expected : metav1.Condition {
421
+ expected : []metav1.Condition {{
422
+ Type : "recommended/RiskThatApplies" ,
423
+ Status : metav1 .ConditionFalse ,
424
+ Reason : "RiskThatApplies" ,
425
+ Message : "This is a risk! https://match.es" ,
426
+ }, {
427
+ Type : "recommended/RiskThatFailsToEvaluate" ,
428
+ Status : metav1 .ConditionUnknown ,
429
+ Reason : recommendedReasonEvaluationFailed ,
430
+ Message : "Could not evaluate exposure to update risk RiskThatFailsToEvaluate (ERROR)\n " +
431
+ " RiskThatFailsToEvaluate description: This is a risk too!\n " +
432
+ " RiskThatFailsToEvaluate URL: https://whokno.ws" ,
433
+ }, {
393
434
Type : "Recommended" ,
394
435
Status : metav1 .ConditionFalse ,
395
436
Reason : recommendedReasonMultiple ,
396
437
Message : "This is a risk! https://match.es\n \n " +
397
438
"Could not evaluate exposure to update risk RiskThatFailsToEvaluate (ERROR)\n " +
398
439
" RiskThatFailsToEvaluate description: This is a risk too!\n " +
399
440
" RiskThatFailsToEvaluate URL: https://whokno.ws" ,
400
- },
441
+ }} ,
401
442
},
402
443
{
403
444
name : "one risk that fails to evaluate" ,
@@ -413,14 +454,21 @@ func TestEvaluateConditionalUpdate(t *testing.T) {
413
454
ValidQueue : []error {nil },
414
455
MatchQueue : []mock.MatchResult {{Match : false , Error : errors .New ("ERROR" )}},
415
456
},
416
- expected : metav1.Condition {
457
+ expected : []metav1.Condition {{
458
+ Type : "recommended/RiskThatFailsToEvaluate" ,
459
+ Status : metav1 .ConditionUnknown ,
460
+ Reason : recommendedReasonEvaluationFailed ,
461
+ Message : "Could not evaluate exposure to update risk RiskThatFailsToEvaluate (ERROR)\n " +
462
+ " RiskThatFailsToEvaluate description: This is a risk!\n " +
463
+ " RiskThatFailsToEvaluate URL: https://whokno.ws" ,
464
+ }, {
417
465
Type : "Recommended" ,
418
466
Status : metav1 .ConditionUnknown ,
419
467
Reason : recommendedReasonEvaluationFailed ,
420
468
Message : "Could not evaluate exposure to update risk RiskThatFailsToEvaluate (ERROR)\n " +
421
469
" RiskThatFailsToEvaluate description: This is a risk!\n " +
422
470
" RiskThatFailsToEvaluate URL: https://whokno.ws" ,
423
- },
471
+ }} ,
424
472
},
425
473
}
426
474
for _ , tc := range testcases {
0 commit comments