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

internal/dag: 0s HTTPRoute timeout disables the timeout #6375

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/6375-skriss-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gateway API: a timeout value of `0s` disables the timeout.
48 changes: 48 additions & 0 deletions internal/dag/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3393,6 +3393,30 @@ func TestDAGInsertGatewayAPI(t *testing.T) {
},
),
},
"HTTPRoute rule with 0s (disabled) request timeout": {
gatewayclass: validClass,
gateway: gatewayHTTPAllNamespaces,
objs: []any{
kuardService,
makeHTTPRouteWithTimeouts("0s", ""),
},
want: listeners(
&Listener{
Name: "http-80",
VirtualHosts: virtualhosts(
virtualhost("test.projectcontour.io",
&Route{
PathMatchCondition: prefixString("/"),
Clusters: clustersWeight(service(kuardService)),
TimeoutPolicy: RouteTimeoutPolicy{
ResponseTimeout: timeout.DisabledSetting(),
},
},
),
),
},
),
},
"HTTPRoute rule with request and backendRequest timeout": {
gatewayclass: validClass,
gateway: gatewayHTTPAllNamespaces,
Expand Down Expand Up @@ -3442,6 +3466,30 @@ func TestDAGInsertGatewayAPI(t *testing.T) {
},
),
},
"HTTPRoute rule with 0s (disabled) backendRequest timeout": {
gatewayclass: validClass,
gateway: gatewayHTTPAllNamespaces,
objs: []any{
kuardService,
makeHTTPRouteWithTimeouts("", "0s"),
},
want: listeners(
&Listener{
Name: "http-80",
VirtualHosts: virtualhosts(
virtualhost("test.projectcontour.io",
&Route{
PathMatchCondition: prefixString("/"),
Clusters: clustersWeight(service(kuardService)),
TimeoutPolicy: RouteTimeoutPolicy{
ResponseTimeout: timeout.DisabledSetting(),
},
},
),
),
},
),
},
"HTTPRoute rule with invalid request timeout": {
gatewayclass: validClass,
gateway: gatewayHTTPAllNamespaces,
Expand Down
10 changes: 10 additions & 0 deletions internal/dag/gatewayapi_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,11 @@ func parseHTTPRouteTimeouts(httpRouteTimeouts *gatewayapi_v1.HTTPRouteTimeouts)
return nil, fmt.Errorf("invalid HTTPRoute.Spec.Rules.Timeouts.Request: %v", err)
}

// For Gateway API a zero-valued timeout means disable the timeout.
if requestTimeout.Duration() == 0 {
requestTimeout = timeout.DisabledSetting()
}

responseTimeout = requestTimeout
}

Expand All @@ -1144,6 +1149,11 @@ func parseHTTPRouteTimeouts(httpRouteTimeouts *gatewayapi_v1.HTTPRouteTimeouts)
return nil, fmt.Errorf("invalid HTTPRoute.Spec.Rules.Timeouts.BackendRequest: %v", err)
}

// For Gateway API a zero-valued timeout means disable the timeout.
if backendRequestTimeout.Duration() == 0 {
backendRequestTimeout = timeout.DisabledSetting()
}

// If Timeouts.Request was specified, then Timeouts.BackendRequest must be
// less than/equal to it.
if responseTimeout.Duration() > 0 && backendRequestTimeout.Duration() > responseTimeout.Duration() {
Expand Down