Skip to content

Commit

Permalink
gatewayapi: add support for timeouts
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
aryan9600 committed Nov 28, 2023
1 parent 003ba6d commit 98ed49b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/router/gateway_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
},
},
},
}
Expand All @@ -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,
},
})
}

Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -378,6 +396,9 @@ func (gwr *GatewayAPIRouter) SetRoutes(
BackendRef: gwr.makeBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port),
},
},
Timeouts: &v1.HTTPRouteTimeouts{
Request: &timeout,
},
})
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/router/gateway_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ func newTestGatewayAPICanary() *flaggerv1.Canary {
Name: "podinfo",
},
},
Timeout: "10s",
},
Analysis: &flaggerv1.CanaryAnalysis{
Threshold: 10,
Expand Down

0 comments on commit 98ed49b

Please sign in to comment.