Skip to content

Commit b5fc159

Browse files
authored
gateway2/status: preserve external conditions (#10663)
Signed-off-by: Shashank Ram <[email protected]>
1 parent 7f648f0 commit b5fc159

File tree

3 files changed

+111
-4
lines changed

3 files changed

+111
-4
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
changelog:
2+
- type: NON_USER_FACING
3+
resolvesIssue: false
4+
description: |
5+
gateway2/status: preserve external conditions
6+
7+
There is a requirement to allow external controllers to update
8+
the statuses on Gateway objects by writing Conditions that do
9+
not conflict with the Types owned by the Gateway. Currently, only
10+
condition.Types that are a part of the status reporter are set as
11+
the final list of conditions. This change allows external controllers
12+
to write Condition.Types that do not conflict.

projects/gateway2/reports/reporter_test.go

+85-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ var _ = Describe("Reporting Infrastructure", func() {
3737
Expect(status.Listeners[0].Conditions).To(HaveLen(4))
3838
})
3939

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+
4060
It("should correctly set negative gateway conditions from report and not add extra conditions", func() {
4161
gw := gw()
4262
rm := reports.NewReportMap()
@@ -133,6 +153,42 @@ var _ = Describe("Reporting Infrastructure", func() {
133153
Entry("delegatee route", delegateeRoute()),
134154
)
135155

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+
136192
DescribeTable("should correctly set negative route conditions from report and not add extra conditions",
137193
func(obj client.Object, parentRef *gwv1.ParentReference) {
138194
rm := reports.NewReportMap()
@@ -361,36 +417,55 @@ var _ = Describe("Reporting Infrastructure", func() {
361417
)
362418
})
363419

364-
func httpRoute() client.Object {
420+
func httpRoute(conditions ...metav1.Condition) client.Object {
365421
route := &gwv1.HTTPRoute{
366422
ObjectMeta: metav1.ObjectMeta{
367423
Name: "route",
368424
Namespace: "default",
369425
},
370426
}
371427
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+
372435
return route
373436
}
374437

375-
func tcpRoute() client.Object {
438+
func tcpRoute(conditions ...metav1.Condition) client.Object {
376439
route := &gwv1a2.TCPRoute{
377440
ObjectMeta: metav1.ObjectMeta{
378441
Name: "route",
379442
Namespace: "default",
380443
},
381444
}
382445
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+
}
383452
return route
384453
}
385454

386-
func tlsRoute() client.Object {
455+
func tlsRoute(conditions ...metav1.Condition) client.Object {
387456
route := &gwv1a2.TLSRoute{
388457
ObjectMeta: metav1.ObjectMeta{
389458
Name: "route",
390459
Namespace: "default",
391460
},
392461
}
393462
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+
}
394469
return route
395470
}
396471

@@ -400,14 +475,20 @@ func parentRef() *gwv1.ParentReference {
400475
}
401476
}
402477

403-
func delegateeRoute() client.Object {
478+
func delegateeRoute(conditions ...metav1.Condition) client.Object {
404479
route := &gwv1.HTTPRoute{
405480
ObjectMeta: metav1.ObjectMeta{
406481
Name: "child-route",
407482
Namespace: "default",
408483
},
409484
}
410485
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+
}
411492
return route
412493
}
413494

projects/gateway2/reports/status.go

+14
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ func (r *ReportMap) BuildGWStatus(ctx context.Context, gw gwv1.Gateway) *gwv1.Ga
5858
}
5959
meta.SetStatusCondition(&finalConditions, gwCondition)
6060
}
61+
// If there are conditions on the Gateway that are not owned by our reporter, include
62+
// them in the final list of conditions to preseve conditions we do not own
63+
for _, condition := range gw.Status.Conditions {
64+
if meta.FindStatusCondition(finalConditions, condition.Type) == nil {
65+
finalConditions = append(finalConditions, condition)
66+
}
67+
}
6168

6269
finalGwStatus := gwv1.GatewayStatus{}
6370
finalGwStatus.Conditions = finalConditions
@@ -138,6 +145,13 @@ func (r *ReportMap) BuildRouteStatus(ctx context.Context, obj client.Object, cNa
138145
}
139146
meta.SetStatusCondition(&finalConditions, pCondition)
140147
}
148+
// If there are conditions on the HTTPRoute that are not owned by our reporter, include
149+
// them in the final list of conditions to preseve conditions we do not own
150+
for _, condition := range currentParentRefConditions {
151+
if meta.FindStatusCondition(finalConditions, condition.Type) == nil {
152+
finalConditions = append(finalConditions, condition)
153+
}
154+
}
141155

142156
routeParentStatus := gwv1.RouteParentStatus{
143157
ParentRef: parentRef,

0 commit comments

Comments
 (0)