Skip to content

Commit 28b4265

Browse files
authored
[backport] gateway2/status: preserve external conditions (#10666)
Signed-off-by: Shashank Ram <[email protected]>
1 parent 0e84783 commit 28b4265

File tree

3 files changed

+99
-3
lines changed

3 files changed

+99
-3
lines changed

changelog/v1.18.11/dbg-status.yaml

+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

+73-3
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()
@@ -132,6 +152,37 @@ var _ = Describe("Reporting Infrastructure", func() {
132152
Entry("delegatee route", delegateeRoute()),
133153
)
134154

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+
135186
DescribeTable("should correctly set negative route conditions from report and not add extra conditions",
136187
func(obj client.Object, parentRef *gwv1.ParentReference) {
137188
rm := reports.NewReportMap()
@@ -338,25 +389,38 @@ var _ = Describe("Reporting Infrastructure", func() {
338389
)
339390
})
340391

341-
func httpRoute() client.Object {
392+
func httpRoute(conditions ...metav1.Condition) client.Object {
342393
route := &gwv1.HTTPRoute{
343394
ObjectMeta: metav1.ObjectMeta{
344395
Name: "route",
345396
Namespace: "default",
346397
},
347398
}
348399
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+
349407
return route
350408
}
351409

352-
func tcpRoute() client.Object {
410+
func tcpRoute(conditions ...metav1.Condition) client.Object {
353411
route := &gwv1a2.TCPRoute{
354412
ObjectMeta: metav1.ObjectMeta{
355413
Name: "route",
356414
Namespace: "default",
357415
},
358416
}
359417
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+
}
360424
return route
361425
}
362426

@@ -366,14 +430,20 @@ func parentRef() *gwv1.ParentReference {
366430
}
367431
}
368432

369-
func delegateeRoute() client.Object {
433+
func delegateeRoute(conditions ...metav1.Condition) client.Object {
370434
route := &gwv1.HTTPRoute{
371435
ObjectMeta: metav1.ObjectMeta{
372436
Name: "child-route",
373437
Namespace: "default",
374438
},
375439
}
376440
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+
}
377447
return route
378448
}
379449

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
@@ -132,6 +139,13 @@ func (r *ReportMap) BuildRouteStatus(ctx context.Context, obj client.Object, cNa
132139
}
133140
meta.SetStatusCondition(&finalConditions, pCondition)
134141
}
142+
// If there are conditions on the HTTPRoute that are not owned by our reporter, include
143+
// them in the final list of conditions to preseve conditions we do not own
144+
for _, condition := range currentParentRefConditions {
145+
if meta.FindStatusCondition(finalConditions, condition.Type) == nil {
146+
finalConditions = append(finalConditions, condition)
147+
}
148+
}
135149

136150
routeParentStatus := gwv1.RouteParentStatus{
137151
ParentRef: parentRef,

0 commit comments

Comments
 (0)