@@ -37,6 +37,26 @@ var _ = Describe("Reporting Infrastructure", func() {
37
37
Expect (status .Listeners [0 ].Conditions ).To (HaveLen (4 ))
38
38
})
39
39
40
+ It ("should preserve conditions set externally" , func () {
41
+ gw := gw ()
42
+ gw .Status .Conditions = append (gw .Status .Conditions , metav1.Condition {
43
+ Type : "gloo.solo.io/SomeCondition" ,
44
+ Status : metav1 .ConditionFalse ,
45
+ })
46
+ rm := reports .NewReportMap ()
47
+
48
+ reporter := reports .NewReporter (& rm )
49
+ // initialize GatewayReporter to mimic translation loop (i.e. report gets initialized for all GWs)
50
+ reporter .Gateway (gw )
51
+
52
+ status := rm .BuildGWStatus (context .Background (), * gw )
53
+
54
+ Expect (status ).NotTo (BeNil ())
55
+ Expect (status .Conditions ).To (HaveLen (3 )) // 2 from the report, 1 from the original status
56
+ Expect (status .Listeners ).To (HaveLen (1 ))
57
+ Expect (status .Listeners [0 ].Conditions ).To (HaveLen (4 ))
58
+ })
59
+
40
60
It ("should correctly set negative gateway conditions from report and not add extra conditions" , func () {
41
61
gw := gw ()
42
62
rm := reports .NewReportMap ()
@@ -133,6 +153,42 @@ var _ = Describe("Reporting Infrastructure", func() {
133
153
Entry ("delegatee route" , delegateeRoute ()),
134
154
)
135
155
156
+ DescribeTable ("should preserve conditions set externally" ,
157
+ func (obj client.Object ) {
158
+ rm := reports .NewReportMap ()
159
+
160
+ reporter := reports .NewReporter (& rm )
161
+ // initialize RouteReporter to mimic translation loop (i.e. report gets initialized for all Routes)
162
+ reporter .Route (obj )
163
+
164
+ status := rm .BuildRouteStatus (context .Background (), obj , "gloo-gateway" )
165
+
166
+ Expect (status ).NotTo (BeNil ())
167
+ Expect (status .Parents ).To (HaveLen (1 ))
168
+ Expect (status .Parents [0 ].Conditions ).To (HaveLen (3 )) // 2 from the report, 1 from the original status
169
+ },
170
+ Entry ("regular httproute" , httpRoute (
171
+ metav1.Condition {
172
+ Type : "gloo.solo.io/SomeCondition" ,
173
+ },
174
+ )),
175
+ Entry ("regular tcproute" , tcpRoute (
176
+ metav1.Condition {
177
+ Type : "gloo.solo.io/SomeCondition" ,
178
+ },
179
+ )),
180
+ Entry ("regular tlsroute" , tlsRoute (
181
+ metav1.Condition {
182
+ Type : "gloo.solo.io/SomeCondition" ,
183
+ },
184
+ )),
185
+ Entry ("delegatee route" , delegateeRoute (
186
+ metav1.Condition {
187
+ Type : "gloo.solo.io/SomeCondition" ,
188
+ },
189
+ )),
190
+ )
191
+
136
192
DescribeTable ("should correctly set negative route conditions from report and not add extra conditions" ,
137
193
func (obj client.Object , parentRef * gwv1.ParentReference ) {
138
194
rm := reports .NewReportMap ()
@@ -361,36 +417,55 @@ var _ = Describe("Reporting Infrastructure", func() {
361
417
)
362
418
})
363
419
364
- func httpRoute () client.Object {
420
+ func httpRoute (conditions ... metav1. Condition ) client.Object {
365
421
route := & gwv1.HTTPRoute {
366
422
ObjectMeta : metav1.ObjectMeta {
367
423
Name : "route" ,
368
424
Namespace : "default" ,
369
425
},
370
426
}
371
427
route .Spec .CommonRouteSpec .ParentRefs = append (route .Spec .CommonRouteSpec .ParentRefs , * parentRef ())
428
+ if len (conditions ) > 0 {
429
+ route .Status .Parents = append (route .Status .Parents , gwv1.RouteParentStatus {
430
+ ParentRef : * parentRef (),
431
+ Conditions : conditions ,
432
+ })
433
+ }
434
+
372
435
return route
373
436
}
374
437
375
- func tcpRoute () client.Object {
438
+ func tcpRoute (conditions ... metav1. Condition ) client.Object {
376
439
route := & gwv1a2.TCPRoute {
377
440
ObjectMeta : metav1.ObjectMeta {
378
441
Name : "route" ,
379
442
Namespace : "default" ,
380
443
},
381
444
}
382
445
route .Spec .CommonRouteSpec .ParentRefs = append (route .Spec .CommonRouteSpec .ParentRefs , * parentRef ())
446
+ if len (conditions ) > 0 {
447
+ route .Status .Parents = append (route .Status .Parents , gwv1.RouteParentStatus {
448
+ ParentRef : * parentRef (),
449
+ Conditions : conditions ,
450
+ })
451
+ }
383
452
return route
384
453
}
385
454
386
- func tlsRoute () client.Object {
455
+ func tlsRoute (conditions ... metav1. Condition ) client.Object {
387
456
route := & gwv1a2.TLSRoute {
388
457
ObjectMeta : metav1.ObjectMeta {
389
458
Name : "route" ,
390
459
Namespace : "default" ,
391
460
},
392
461
}
393
462
route .Spec .CommonRouteSpec .ParentRefs = append (route .Spec .CommonRouteSpec .ParentRefs , * parentRef ())
463
+ if len (conditions ) > 0 {
464
+ route .Status .Parents = append (route .Status .Parents , gwv1.RouteParentStatus {
465
+ ParentRef : * parentRef (),
466
+ Conditions : conditions ,
467
+ })
468
+ }
394
469
return route
395
470
}
396
471
@@ -400,14 +475,20 @@ func parentRef() *gwv1.ParentReference {
400
475
}
401
476
}
402
477
403
- func delegateeRoute () client.Object {
478
+ func delegateeRoute (conditions ... metav1. Condition ) client.Object {
404
479
route := & gwv1.HTTPRoute {
405
480
ObjectMeta : metav1.ObjectMeta {
406
481
Name : "child-route" ,
407
482
Namespace : "default" ,
408
483
},
409
484
}
410
485
route .Spec .CommonRouteSpec .ParentRefs = append (route .Spec .CommonRouteSpec .ParentRefs , * parentRouteRef ())
486
+ if len (conditions ) > 0 {
487
+ route .Status .Parents = append (route .Status .Parents , gwv1.RouteParentStatus {
488
+ ParentRef : * parentRouteRef (),
489
+ Conditions : conditions ,
490
+ })
491
+ }
411
492
return route
412
493
}
413
494
0 commit comments