gatewayapi: add support for timeouts

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
This commit is contained in:
Sanskar Jaiswal
2023-11-28 19:01:18 +05:30
parent 09b0937e18
commit 1f2c464b45
3 changed files with 37 additions and 0 deletions

View File

@@ -105,6 +105,12 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error {
},
},
}
if canary.Spec.Service.Timeout != "" {
timeout := v1.Duration(canary.Spec.Service.Timeout)
httpRouteSpec.Rules[0].Timeouts = &v1.HTTPRouteTimeouts{
Request: &timeout,
}
}
// A/B testing
if len(canary.GetAnalysis().Match) > 0 {
@@ -120,6 +126,12 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error {
},
},
})
if canary.Spec.Service.Timeout != "" {
timeout := v1.Duration(canary.Spec.Service.Timeout)
httpRouteSpec.Rules[1].Timeouts = &v1.HTTPRouteTimeouts{
Request: &timeout,
}
}
}
httpRoute, err := gwr.gatewayAPIClient.GatewayapiV1().HTTPRoutes(hrNamespace).Get(
@@ -317,6 +329,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),
@@ -329,6 +346,12 @@ func (gwr *GatewayAPIRouter) SetRoutes(
},
},
}
if canary.Spec.Service.Timeout != "" {
timeout := v1.Duration(canary.Spec.Service.Timeout)
weightedRouteRule.Timeouts = &v1.HTTPRouteTimeouts{
Request: &timeout,
}
}
// If B/G mirroring is enabled, then add a route filter which mirrors the traffic
// to the canary service.
@@ -378,7 +401,17 @@ func (gwr *GatewayAPIRouter) SetRoutes(
BackendRef: gwr.makeBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port),
},
},
Timeouts: &v1.HTTPRouteTimeouts{
Request: &timeout,
},
})
if canary.Spec.Service.Timeout != "" {
timeout := v1.Duration(canary.Spec.Service.Timeout)
hrClone.Spec.Rules[1].Timeouts = &v1.HTTPRouteTimeouts{
Request: &timeout,
}
}
}
_, err = gwr.gatewayAPIClient.GatewayapiV1().HTTPRoutes(hrNamespace).Update(context.TODO(), hrClone, metav1.UpdateOptions{})

View File

@@ -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) {

View File

@@ -554,6 +554,7 @@ func newTestGatewayAPICanary() *flaggerv1.Canary {
Name: "podinfo",
},
},
Timeout: "10s",
},
Analysis: &flaggerv1.CanaryAnalysis{
Threshold: 10,