@@ -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 ()
@@ -132,6 +152,37 @@ var _ = Describe("Reporting Infrastructure", func() {
132
152
Entry ("delegatee route" , delegateeRoute ()),
133
153
)
134
154
155
+ DescribeTable ("should preserve conditions set externally" ,
156
+ func (obj client.Object ) {
157
+ rm := reports .NewReportMap ()
158
+
159
+ reporter := reports .NewReporter (& rm )
160
+ // initialize RouteReporter to mimic translation loop (i.e. report gets initialized for all Routes)
161
+ reporter .Route (obj )
162
+
163
+ status := rm .BuildRouteStatus (context .Background (), obj , "gloo-gateway" )
164
+
165
+ Expect (status ).NotTo (BeNil ())
166
+ Expect (status .Parents ).To (HaveLen (1 ))
167
+ Expect (status .Parents [0 ].Conditions ).To (HaveLen (3 )) // 2 from the report, 1 from the original status
168
+ },
169
+ Entry ("regular httproute" , httpRoute (
170
+ metav1.Condition {
171
+ Type : "gloo.solo.io/SomeCondition" ,
172
+ },
173
+ )),
174
+ Entry ("regular tcproute" , tcpRoute (
175
+ metav1.Condition {
176
+ Type : "gloo.solo.io/SomeCondition" ,
177
+ },
178
+ )),
179
+ Entry ("delegatee route" , delegateeRoute (
180
+ metav1.Condition {
181
+ Type : "gloo.solo.io/SomeCondition" ,
182
+ },
183
+ )),
184
+ )
185
+
135
186
DescribeTable ("should correctly set negative route conditions from report and not add extra conditions" ,
136
187
func (obj client.Object , parentRef * gwv1.ParentReference ) {
137
188
rm := reports .NewReportMap ()
@@ -338,25 +389,38 @@ var _ = Describe("Reporting Infrastructure", func() {
338
389
)
339
390
})
340
391
341
- func httpRoute () client.Object {
392
+ func httpRoute (conditions ... metav1. Condition ) client.Object {
342
393
route := & gwv1.HTTPRoute {
343
394
ObjectMeta : metav1.ObjectMeta {
344
395
Name : "route" ,
345
396
Namespace : "default" ,
346
397
},
347
398
}
348
399
route .Spec .CommonRouteSpec .ParentRefs = append (route .Spec .CommonRouteSpec .ParentRefs , * parentRef ())
400
+ if len (conditions ) > 0 {
401
+ route .Status .Parents = append (route .Status .Parents , gwv1.RouteParentStatus {
402
+ ParentRef : * parentRef (),
403
+ Conditions : conditions ,
404
+ })
405
+ }
406
+
349
407
return route
350
408
}
351
409
352
- func tcpRoute () client.Object {
410
+ func tcpRoute (conditions ... metav1. Condition ) client.Object {
353
411
route := & gwv1a2.TCPRoute {
354
412
ObjectMeta : metav1.ObjectMeta {
355
413
Name : "route" ,
356
414
Namespace : "default" ,
357
415
},
358
416
}
359
417
route .Spec .CommonRouteSpec .ParentRefs = append (route .Spec .CommonRouteSpec .ParentRefs , * parentRef ())
418
+ if len (conditions ) > 0 {
419
+ route .Status .Parents = append (route .Status .Parents , gwv1.RouteParentStatus {
420
+ ParentRef : * parentRef (),
421
+ Conditions : conditions ,
422
+ })
423
+ }
360
424
return route
361
425
}
362
426
@@ -366,14 +430,20 @@ func parentRef() *gwv1.ParentReference {
366
430
}
367
431
}
368
432
369
- func delegateeRoute () client.Object {
433
+ func delegateeRoute (conditions ... metav1. Condition ) client.Object {
370
434
route := & gwv1.HTTPRoute {
371
435
ObjectMeta : metav1.ObjectMeta {
372
436
Name : "child-route" ,
373
437
Namespace : "default" ,
374
438
},
375
439
}
376
440
route .Spec .CommonRouteSpec .ParentRefs = append (route .Spec .CommonRouteSpec .ParentRefs , * parentRouteRef ())
441
+ if len (conditions ) > 0 {
442
+ route .Status .Parents = append (route .Status .Parents , gwv1.RouteParentStatus {
443
+ ParentRef : * parentRouteRef (),
444
+ Conditions : conditions ,
445
+ })
446
+ }
377
447
return route
378
448
}
379
449
0 commit comments