Skip to content

Commit

Permalink
Adds Support for TCPRoute Status (#10387)
Browse files Browse the repository at this point in the history
Signed-off-by: Daneyon Hansen <[email protected]>
Co-authored-by: Sam Heilbron <[email protected]>
Co-authored-by: Nathan Fudenberg <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 7dd0bee commit 0f99be1
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 134 deletions.
6 changes: 6 additions & 0 deletions changelog/v1.18.0-rc2/issue_10365.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: FIX
issueLink: https://github.com/k8sgateway/k8sgateway/issues/10365
resolvesIssue: true
description: >-
Adds support for setting TCPRoute status and managing status conditions.
24 changes: 24 additions & 0 deletions projects/gateway2/proxy_syncer/proxy_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ func TestIsRouteStatusEqual(t *testing.T) {
Namespace: ptr.To[gwv1.Namespace](gwv1.Namespace("default")),
},
},
{
ParentRef: gwv1.ParentReference{
Group: ptr.To[gwv1.Group](gwv1.Group(wellknown.GatewayGroup)),
Kind: ptr.To[gwv1.Kind](gwv1.Kind(wellknown.TCPRouteKind)),
Name: "parent",
Namespace: ptr.To[gwv1.Namespace](gwv1.Namespace("default")),
},
},
},
}
// Same as status1
Expand All @@ -82,6 +90,14 @@ func TestIsRouteStatusEqual(t *testing.T) {
Namespace: ptr.To[gwv1.Namespace](gwv1.Namespace("default")),
},
},
{
ParentRef: gwv1.ParentReference{
Group: ptr.To[gwv1.Group](gwv1.Group(wellknown.GatewayGroup)),
Kind: ptr.To[gwv1.Kind](gwv1.Kind(wellknown.TCPRouteKind)),
Name: "parent",
Namespace: ptr.To[gwv1.Namespace](gwv1.Namespace("default")),
},
},
},
}
// Different from status1
Expand All @@ -95,6 +111,14 @@ func TestIsRouteStatusEqual(t *testing.T) {
Namespace: ptr.To[gwv1.Namespace](gwv1.Namespace("my-other-ns")),
},
},
{
ParentRef: gwv1.ParentReference{
Group: ptr.To[gwv1.Group](gwv1.Group(wellknown.GatewayGroup)),
Kind: ptr.To[gwv1.Kind](gwv1.Kind(wellknown.TCPRouteKind)),
Name: "parent",
Namespace: ptr.To[gwv1.Namespace](gwv1.Namespace("my-other-ns")),
},
},
},
}

Expand Down
2 changes: 2 additions & 0 deletions projects/gateway2/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/solo-io/gloo/projects/gateway2/wellknown"
)

//go:generate go run github.com/golang/mock/mockgen -destination mocks/mock_queries.go -package mocks github.com/solo-io/gloo/projects/gateway2/query GatewayQueries

var _ = Describe("Query", func() {
var (
scheme *runtime.Scheme
Expand Down
70 changes: 68 additions & 2 deletions projects/gateway2/translator/gateway_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

"github.com/solo-io/gloo/projects/gateway2/reports"
)
Expand Down Expand Up @@ -115,7 +116,7 @@ var _ = DescribeTable("Basic GatewayTranslator Tests",
Name: "example-gateway",
}}),
Entry(
"route with missing backend reports correctly",
"httproute with missing backend reports correctly",
translatorTestCase{
inputFile: "http-routing-missing-backend",
outputFile: "http-routing-missing-backend.yaml",
Expand All @@ -139,7 +140,7 @@ var _ = DescribeTable("Basic GatewayTranslator Tests",
},
}),
Entry(
"route with invalid backend reports correctly",
"httproute with invalid backend reports correctly",
translatorTestCase{
inputFile: "http-routing-invalid-backend",
outputFile: "http-routing-invalid-backend.yaml",
Expand Down Expand Up @@ -181,6 +182,71 @@ var _ = DescribeTable("Basic GatewayTranslator Tests",
Namespace: "default",
Name: "example-gateway",
},
assertReports: func(gwNN types.NamespacedName, reportsMap reports.ReportMap) {
route := &gwv1a2.TCPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: "example-tcp-route",
Namespace: "default",
},
}
routeStatus := reportsMap.BuildRouteStatus(context.TODO(), route, "")
Expect(routeStatus).NotTo(BeNil())
Expect(routeStatus.Parents).To(HaveLen(1))
resolvedRefs := meta.FindStatusCondition(routeStatus.Parents[0].Conditions, string(gwv1.RouteConditionResolvedRefs))
Expect(resolvedRefs).NotTo(BeNil())
Expect(resolvedRefs.Status).To(Equal(metav1.ConditionTrue))
Expect(resolvedRefs.Reason).To(Equal(string(gwv1.RouteReasonResolvedRefs)))
},
}),
Entry(
"tcproute with missing backend reports correctly",
translatorTestCase{
inputFile: "tcp-routing/missing-backend.yaml",
outputFile: "tcp-routing/missing-backend.yaml",
gwNN: types.NamespacedName{
Namespace: "default",
Name: "example-gateway",
},
assertReports: func(gwNN types.NamespacedName, reportsMap reports.ReportMap) {
route := &gwv1a2.TCPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: "example-tcp-route",
Namespace: "default",
},
}
routeStatus := reportsMap.BuildRouteStatus(context.TODO(), route, "")
Expect(routeStatus).NotTo(BeNil())
Expect(routeStatus.Parents).To(HaveLen(1))
resolvedRefs := meta.FindStatusCondition(routeStatus.Parents[0].Conditions, string(gwv1.RouteConditionResolvedRefs))
Expect(resolvedRefs).NotTo(BeNil())
Expect(resolvedRefs.Status).To(Equal(metav1.ConditionFalse))
Expect(resolvedRefs.Message).To(Equal("services \"example-tcp-svc\" not found"))
},
}),
Entry(
"tcproute with invalid backend reports correctly",
translatorTestCase{
inputFile: "tcp-routing/invalid-backend.yaml",
outputFile: "tcp-routing/invalid-backend.yaml",
gwNN: types.NamespacedName{
Namespace: "default",
Name: "example-gateway",
},
assertReports: func(gwNN types.NamespacedName, reportsMap reports.ReportMap) {
route := &gwv1a2.TCPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: "example-tcp-route",
Namespace: "default",
},
}
routeStatus := reportsMap.BuildRouteStatus(context.TODO(), route, "")
Expect(routeStatus).NotTo(BeNil())
Expect(routeStatus.Parents).To(HaveLen(1))
resolvedRefs := meta.FindStatusCondition(routeStatus.Parents[0].Conditions, string(gwv1.RouteConditionResolvedRefs))
Expect(resolvedRefs).NotTo(BeNil())
Expect(resolvedRefs.Status).To(Equal(metav1.ConditionFalse))
Expect(resolvedRefs.Message).To(Equal("unknown backend kind"))
},
}),
Entry(
"tcp gateway with multiple backend services",
Expand Down
Loading

0 comments on commit 0f99be1

Please sign in to comment.