From 98ed49b147a76532b03f7f7c35d1e756f21bc15f Mon Sep 17 00:00:00 2001 From: Sanskar Jaiswal Date: Tue, 28 Nov 2023 19:01:18 +0530 Subject: [PATCH] gatewayapi: add support for timeouts Signed-off-by: Sanskar Jaiswal --- pkg/router/gateway_api.go | 21 +++++++++++++++++++++ pkg/router/gateway_api_test.go | 3 +++ pkg/router/router_test.go | 1 + 3 files changed, 25 insertions(+) diff --git a/pkg/router/gateway_api.go b/pkg/router/gateway_api.go index 2fff2c3e8..cb85a1f13 100644 --- a/pkg/router/gateway_api.go +++ b/pkg/router/gateway_api.go @@ -84,6 +84,10 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error { }, }) } + var timeout v1.Duration + if canary.Spec.Service.Timeout != "" { + timeout = v1.Duration(canary.Spec.Service.Timeout) + } httpRouteSpec := v1.HTTPRouteSpec{ CommonRouteSpec: v1.CommonRouteSpec{ @@ -102,6 +106,9 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error { BackendRef: gwr.makeBackendRef(canarySvcName, initialCanaryWeight, canary.Spec.Service.Port), }, }, + Timeouts: &v1.HTTPRouteTimeouts{ + Request: &timeout, + }, }, }, } @@ -119,6 +126,9 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error { BackendRef: gwr.makeBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port), }, }, + Timeouts: &v1.HTTPRouteTimeouts{ + Request: &timeout, + }, }) } @@ -317,6 +327,11 @@ func (gwr *GatewayAPIRouter) SetRoutes( }, }) } + var timeout v1.Duration + if canary.Spec.Service.Timeout != "" { + timeout = v1.Duration(canary.Spec.Service.Timeout) + } + weightedRouteRule := &v1.HTTPRouteRule{ Matches: matches, Filters: gwr.makeFilters(canary), @@ -328,6 +343,9 @@ func (gwr *GatewayAPIRouter) SetRoutes( BackendRef: gwr.makeBackendRef(canarySvcName, cWeight, canary.Spec.Service.Port), }, }, + Timeouts: &v1.HTTPRouteTimeouts{ + Request: &timeout, + }, } // If B/G mirroring is enabled, then add a route filter which mirrors the traffic @@ -378,6 +396,9 @@ func (gwr *GatewayAPIRouter) SetRoutes( BackendRef: gwr.makeBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port), }, }, + Timeouts: &v1.HTTPRouteTimeouts{ + Request: &timeout, + }, }) } diff --git a/pkg/router/gateway_api_test.go b/pkg/router/gateway_api_test.go index cdaa18a48..b03b5ab8e 100644 --- a/pkg/router/gateway_api_test.go +++ b/pkg/router/gateway_api_test.go @@ -52,6 +52,9 @@ func TestGatewayAPIRouter_Reconcile(t *testing.T) { require.Equal(t, len(backendRefs), 2) assert.Equal(t, int32(100), *backendRefs[0].Weight) assert.Equal(t, int32(0), *backendRefs[1].Weight) + + timeout := routeRules[0].Timeouts + assert.Equal(t, string(*timeout.Request), canary.Spec.Service.Timeout) } func TestGatewayAPIRouter_Routes(t *testing.T) { diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index 70b6c5129..d9519d76d 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -554,6 +554,7 @@ func newTestGatewayAPICanary() *flaggerv1.Canary { Name: "podinfo", }, }, + Timeout: "10s", }, Analysis: &flaggerv1.CanaryAnalysis{ Threshold: 10,