Skip to content

Commit

Permalink
internal/dag: 0s HTTPRoute timeout disables the timeout
Browse files Browse the repository at this point in the history
In Gateway API, a timeout specified as 0s (or any
other explicitly zero-valued duration string) should
disable the timeout rather than use the default
value.

Signed-off-by: Steve Kriss <[email protected]>
  • Loading branch information
skriss committed Apr 23, 2024
1 parent 033e968 commit 2cdad15
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 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
5 changes: 5 additions & 0 deletions internal/dag/gatewayapi_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,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()
}

return &RouteTimeoutPolicy{
ResponseTimeout: requestTimeout,
}, nil
Expand Down

0 comments on commit 2cdad15

Please sign in to comment.