Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gateway API: fix for failing GatewayWithAttachedRoutes conformance test #5961

Merged
merged 14 commits into from
Dec 12, 2023
Prev Previous commit
Next Next commit
add ut
Signed-off-by: gang.liu <gang.liu@daocloud.io>
izturn committed Nov 20, 2023
commit 9559b2f5a03d98f3fbd2b23f7b8b0f9530b22a89
94 changes: 94 additions & 0 deletions internal/dag/status_test.go
Original file line number Diff line number Diff line change
@@ -9263,6 +9263,100 @@ func TestGatewayAPIHTTPRouteDAGStatus(t *testing.T) {
wantGatewayStatusUpdate: validGatewayStatusUpdate("http", gatewayapi_v1.HTTPProtocolType, 1),
})

run(t, "HTTP listener, route's parent ref route kind is invalid", testcase{
izturn marked this conversation as resolved.
Show resolved Hide resolved
objs: []any{
kuardService,
&gatewayapi_v1beta1.HTTPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: "basic",
Namespace: "default",
},
Spec: gatewayapi_v1beta1.HTTPRouteSpec{
CommonRouteSpec: gatewayapi_v1beta1.CommonRouteSpec{
ParentRefs: []gatewayapi_v1beta1.ParentReference{gatewayapi.GatewayListenerParentRef("projectcontour", "contour", "listener-1", 80)},
},
Hostnames: []gatewayapi_v1beta1.Hostname{"foo.projectcontour.io"},
Rules: []gatewayapi_v1beta1.HTTPRouteRule{{
Matches: gatewayapi.HTTPRouteMatch(gatewayapi_v1.PathMatchPathPrefix, "/"),
BackendRefs: gatewayapi.HTTPBackendRef("kuard", 8080, 1),
}},
},
}},
gateway: &gatewayapi_v1beta1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: "contour",
Namespace: "projectcontour",
},
Spec: gatewayapi_v1beta1.GatewaySpec{
Listeners: []gatewayapi_v1beta1.Listener{
{
Name: "listener-1",
Port: 80,
Protocol: gatewayapi_v1.HTTPProtocolType,
AllowedRoutes: &gatewayapi_v1beta1.AllowedRoutes{
Kinds: []gatewayapi_v1beta1.RouteGroupKind{
{Kind: "FooRoute"},
},
},
Hostname: ref.To(gatewayapi_v1beta1.Hostname("*.projectcontour.io")),
},
},
},
},
wantRouteConditions: []*status.RouteStatusUpdate{{
FullName: types.NamespacedName{Namespace: "default", Name: "basic"},
RouteParentStatuses: []*gatewayapi_v1beta1.RouteParentStatus{
{
ParentRef: gatewayapi.GatewayListenerParentRef("projectcontour", "contour", "listener-1", 80),
Conditions: []metav1.Condition{
{
Type: string(gatewayapi_v1.RouteConditionAccepted),
Status: contour_api_v1.ConditionFalse,
Reason: string(gatewayapi_v1beta1.RouteReasonNotAllowedByListeners),
Message: "No listeners included by this parent ref allowed this attachment.",
},
routeResolvedRefsCondition(),
},
},
},
}},
wantGatewayStatusUpdate: []*status.GatewayStatusUpdate{
{
FullName: types.NamespacedName{Namespace: "projectcontour", Name: "contour"},
Conditions: map[gatewayapi_v1.GatewayConditionType]metav1.Condition{
gatewayapi_v1.GatewayConditionAccepted: gatewayAcceptedCondition(),
gatewayapi_v1.GatewayConditionProgrammed: {
Type: string(gatewayapi_v1.GatewayConditionProgrammed),
Status: contour_api_v1.ConditionFalse,
Reason: string(gatewayapi_v1.GatewayReasonListenersNotValid),
Message: "Listeners are not valid",
},
},
ListenerStatus: map[string]*gatewayapi_v1beta1.ListenerStatus{
"listener-1": {
Name: gatewayapi_v1beta1.SectionName("listener-1"),
AttachedRoutes: int32(0),
Conditions: []metav1.Condition{
{
Type: string(gatewayapi_v1.ListenerConditionResolvedRefs),
Status: metav1.ConditionFalse,
Reason: string(gatewayapi_v1.ListenerReasonInvalidRouteKinds),
Message: "Kind \"FooRoute\" is not supported, kind must be \"HTTPRoute\", \"TLSRoute\", \"GRPCRoute\" or \"TCPRoute\"",
},
{
Type: string(gatewayapi_v1.ListenerConditionProgrammed),
Status: metav1.ConditionFalse,
Reason: string(gatewayapi_v1.ListenerReasonInvalid),
Message: "Invalid listener, see other listener conditions for details",
},
listenerAcceptedCondition(),
},
},
},
},
},
})

}

func TestGatewayAPITLSRouteDAGStatus(t *testing.T) {