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 29, 2023
1 parent 09b0937 commit 1f2c464
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/router/gateway_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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),
Expand All @@ -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.
Expand Down Expand Up @@ -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{})
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 1f2c464

Please sign in to comment.