Skip to content

apply TrafficPolicy retry per route instead of per vhost#14360

Merged
puertomontt merged 4 commits into
kgateway-dev:mainfrom
puertomontt:retries-per-route
Jul 9, 2026
Merged

apply TrafficPolicy retry per route instead of per vhost#14360
puertomontt merged 4 commits into
kgateway-dev:mainfrom
puertomontt:retries-per-route

Conversation

@puertomontt

@puertomontt puertomontt commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

Previously the TrafficPolicy retry policy was applied at the virtual host level via ApplyVhostPlugin. This changes it to apply the retry policy to each route instead.

In Envoy, a route-level retry policy fully overrides the vhost-level one, so a more specific TrafficPolicy (or the builtin HTTPRouteRetry policy) attached at the route level would silently take precedence over a vhost-attached TrafficPolicy retry. Applying the retry policy per route makes that precedence explicit and consistent with how the other per-route settings are handled.

Changes:

  • Add a shared applyRetryPolicy helper that sets the retry policy on a route only when one is not already set (preserving the builtin HTTPRouteRetry / more-specific TrafficPolicy precedence).
  • ApplyVhostPlugin now iterates the vhost's routes and applies the retry policy to each, replacing handlePerVHostPolicies.
  • handlePerRoutePolicies uses the same helper.
  • Add a golden test (traffic-policy/http-retry.yaml) exercising a TrafficPolicy retry attached to an HTTPRoute.

Change Type

/kind feature

Changelog

TrafficPolicy retry configuration is now applied at the route level instead of the virtual host level, making retry policy precedence between TrafficPolicy and the builtin HTTPRouteRetry policy explicit and consistent.

Apply the retry policy to each route rather than to the virtual host. A
route-level retry policy (set by a more specific TrafficPolicy or the
builtin HTTPRouteRetry policy) fully overrides the vhost-level one in
Envoy, so applying it per route keeps that precedence explicit and
consistent with the other per-route settings.

Signed-off-by: omar <[email protected]>
Copilot AI review requested due to automatic review settings July 7, 2026 16:05
@puertomontt puertomontt changed the title feat: apply TrafficPolicy retry per route instead of per vhost apply TrafficPolicy retry per route instead of per vhost Jul 7, 2026
@gateway-bot gateway-bot added do-not-merge/description-invalid kind/feature Categorizes issue or PR as related to a new feature. release-note labels Jul 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes how TrafficPolicy retry settings are applied during Gateway translation: instead of setting retries at the Envoy virtual host level, it applies them at the route level. This makes retry precedence explicit and consistent with Envoy semantics, where route-level retry configuration fully overrides vhost-level configuration.

Changes:

  • Introduces a shared applyRetryPolicy helper that only sets a route retry policy if one is not already present (preserving precedence for builtin HTTPRouteRetry and more-specific TrafficPolicy attachments).
  • Updates ApplyVhostPlugin to apply retry settings to each route in the vhost rather than to the vhost itself.
  • Adds a new golden test case (traffic-policy/http-retry.yaml) and wires it into TestBasic.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/kgateway/extensions2/plugins/trafficpolicy/traffic_policy_plugin.go Moves retry application from vhost scope to per-route scope and centralizes the “only-if-unset” behavior in applyRetryPolicy.
pkg/kgateway/translator/gateway/testutils/outputs/traffic-policy/timeout-retry.yaml Updates golden output to reflect retry policy being present on routes rather than on virtual hosts.
pkg/kgateway/translator/gateway/testutils/inputs/traffic-policy/http-retry.yaml Adds an input fixture covering a TrafficPolicy retry attached directly to an HTTPRoute.
pkg/kgateway/translator/gateway/testutils/outputs/traffic-policy/http-retry.yaml Adds the corresponding golden output validating route-level retry policy emission.
pkg/kgateway/translator/gateway/gateway_translator_test.go Adds a test case to execute the new golden input/output pair.

puertomontt and others added 2 commits July 7, 2026 14:13
Add a golden test where a Gateway-listener-attached retry TrafficPolicy
(via sectionName) shares a vhost with two routes: one rule with its own
route-attached retry and one without. This pins both behaviors of the
per-route retry translation independently of the timeout-retry fixture:

- the listener retry fans out onto the retry-less route (rule1)
- a more specific route-attached retry wins over the listener one (rule0)

Signed-off-by: omar <[email protected]>
}

p.handlePolicies(pCtx.FilterChainName, &pCtx.TypedFilterConfig, policy.spec)
p.applyGatewayLevelPerRouteSettings(policy.spec, out)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@puertomontt

Copy link
Copy Markdown
Contributor Author

context:

just making this more consistent since https doesn't carry vhost policies
even though the function applyGatewayLevelPerRouteSettings was inadvertently handling this.
this way we can backport to 2.3.x and fix the bug (where a retry would be silently not applied to https listener)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants