Skip to content

docs: align TrafficPolicy attachment docs with per-route settings#14378

Merged
davidjumani merged 4 commits into
kgateway-dev:mainfrom
puertomontt:trafficpolicy-attachment-docs
Jul 13, 2026
Merged

docs: align TrafficPolicy attachment docs with per-route settings#14378
davidjumani merged 4 commits into
kgateway-dev:mainfrom
puertomontt:trafficpolicy-attachment-docs

Conversation

@puertomontt

Copy link
Copy Markdown
Contributor

Description

Follow-up to #14374. That PR made TrafficPolicy timeouts (and the other
route-action-level settings) take effect when a policy attaches at a Gateway or
a Gateway listener section, not just at an HTTPRoute. This PR updates the API
documentation to match that behavior and reconciles the CEL validations that
had drifted from it:

  • Timeouts doc now states it is applicable to HTTPRoutes and Gateways
    (including individual Gateway listeners via sectionName), with route-level
    precedence noted. Previously it claimed HTTPRoute-only.
  • Retry doc now states it is applicable to HTTPRoutes, Gateways, Gateway
    listeners, and ListenerSets, with route-level precedence noted.
  • Drop the retry sectionName CEL rules, so a retry policy may target a
    whole Gateway (no sectionName) and be admitted — matching timeouts and the
    behavior delivered by apply TrafficPolicy retry per route instead of per vhost #14360/fix: apply TrafficPolicy timeouts per route at the vhost level #14374. Relaxing validation is non-breaking.
  • Add a urlRewrite HTTPRoute-only CEL rule (mirroring autoHostRewrite),
    so the already-documented "only honored for HTTPRoute targets" contract is
    actually enforced at admission rather than silently applying gateway-wide.
  • Update the apivalidation e2e cases: remove the two now-obsolete retry
    sectionName rejection cases, add a positive case (whole-Gateway retry is
    admitted), and add a urlRewrite-invalid-target rejection case.

Note

Stacked on #14374 — the timeouts doc describes behavior that only exists once
that PR merges. Please merge #14374 first; this branch will then contain only
its own changes.

Change Type

/kind documentation
/kind fix

Changelog

TrafficPolicy retry may now target a whole Gateway (without a sectionName), consistent with timeouts. TrafficPolicy urlRewrite is now validated to only target HTTPRoute resources, matching its documented behavior.

A TrafficPolicy targeting a Gateway HTTP listener section attaches at the
Envoy virtual-host level. Timeouts (and other route-action-level settings)
are only applied per route, so they were silently dropped for such policies
even though the policy reported as Accepted. HTTPS listener and whole-Gateway
targeting were unaffected since they attach at the RouteConfiguration level.

Generalize ApplyVhostPlugin to apply the full per-route settings to every
route in the vhost via a shared applyPerRouteSettings helper, mirroring
applyGatewayLevelPerRouteSettings. The existing 'only set if not already set'
guards preserve merge precedence.

Add gateway translator tests for TrafficPolicy timeout targeting the whole
Gateway, an HTTP listener, and an HTTPS listener.

Signed-off-by: omar <[email protected]>
Following kgateway-dev#14374, TrafficPolicy timeouts (and other route-action-level
settings) now take effect when a policy attaches at a Gateway or Gateway
listener section, not just an HTTPRoute. Update the API docs to match and
reconcile the CEL validations:

- Timeouts doc: applicable to HTTPRoutes and Gateways (including per-listener
  sectionName), with route-level precedence noted.
- Retry doc: applicable to HTTPRoutes, Gateways, Gateway listeners, and
  ListenerSets, with route-level precedence noted.
- Drop the retry sectionName CEL rules so whole-Gateway retry is admittable,
  matching timeouts and the documented behavior.
- Add a urlRewrite HTTPRoute-only CEL rule (mirroring autoHostRewrite) so the
  documented 'HTTPRoute targets only' contract is enforced.
- Update apivalidation e2e cases accordingly.

Signed-off-by: omar <[email protected]>
@puertomontt
puertomontt requested a review from a team as a code owner July 9, 2026 17:59
Copilot AI review requested due to automatic review settings July 9, 2026 17:59
@gateway-bot gateway-bot added kind/documentation kind/fix Categorizes issue or PR as related to a bug. release-note labels Jul 9, 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 updates TrafficPolicy’s API documentation and admission validations to match the actual attachment/precedence behavior (Gateway / listener vs per-route), and adjusts validation test coverage accordingly. It also includes translator/plugin changes and goldens that exercise/enable Gateway and listener-level timeout behavior (stacked on #14374 as noted in the PR description).

Changes:

  • Update TrafficPolicy timeouts and retry docstrings/CRD descriptions to reflect applicability at HTTPRoute and Gateway (including listener sectionName) with route-level precedence.
  • Relax retry admission by removing CEL rules that previously required sectionName when targeting Gateway; add a CEL rule enforcing urlRewrite as HTTPRoute-only.
  • Update e2e API validation cases and add gateway translator golden tests for whole-Gateway and per-listener timeout targeting.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/e2e/tests/apivalidation/apivalidation.go Updates validation cases: adds urlRewrite invalid-target rejection and changes retry sectionName expectations.
api/v1alpha1/kgateway/traffic_policy_types.go Updates TrafficPolicy field docs and adds/removes CEL validations (urlRewrite HTTPRoute-only; drops retry sectionName rules).
install/helm/kgateway-crds/templates/gateway.kgateway.dev_trafficpolicies.yaml Regenerated/updated CRD schema docs and CEL validations matching the API changes.
pkg/kgateway/extensions2/plugins/trafficpolicy/traffic_policy_plugin.go Refactors per-route application into a helper and applies per-route settings for vhost-attached policies.
pkg/kgateway/translator/gateway/gateway_translator_test.go Adds translator test cases covering timeout attachment at whole-Gateway and listener section levels.
pkg/kgateway/translator/gateway/testutils/inputs/traffic-policy/timeout-gateway-whole.yaml New input fixture for whole-Gateway timeout behavior.
pkg/kgateway/translator/gateway/testutils/inputs/traffic-policy/timeout-gateway-http-listener.yaml New input fixture for HTTP listener timeout targeting.
pkg/kgateway/translator/gateway/testutils/inputs/traffic-policy/timeout-gateway-https-listener.yaml New input fixture for HTTPS listener timeout targeting.
pkg/kgateway/translator/gateway/testutils/outputs/traffic-policy/timeout-gateway-whole.yaml New golden output validating whole-Gateway timeouts are emitted on all covered routes.
pkg/kgateway/translator/gateway/testutils/outputs/traffic-policy/timeout-gateway-http-listener.yaml New golden output validating HTTP-listener-only timeout emission.
pkg/kgateway/translator/gateway/testutils/outputs/traffic-policy/timeout-gateway-https-listener.yaml New golden output validating HTTPS-listener-only timeout emission.

Comment on lines +395 to 400
for _, route := range routes {
if route.GetRoute() == nil {
continue
}
p.handlePerRoutePolicies(spec, route)
}
// specific TrafficPolicy or a builtin HTTPRoute policy) fully overrides the
// one applied here, and the "only set if not already set" guards in
// handlePerRoutePolicies keep that precedence explicit.
p.applyPerRouteSettings(policy.spec, out.Routes)
Comment on lines +108 to +109
// covers; a route-level timeout (from a more specific TrafficPolicy or the
// built-in HTTPRoute timeouts) takes precedence.
Comment on lines +117 to +118
// covers; a route-level retry policy (from a more specific TrafficPolicy or the
// built-in HTTPRoute retry) takes precedence.
@puertomontt
puertomontt force-pushed the trafficpolicy-attachment-docs branch from 86c22e0 to 3c5445e Compare July 9, 2026 18:31
@davidjumani
davidjumani enabled auto-merge July 13, 2026 15:56
@davidjumani
davidjumani added this pull request to the merge queue Jul 13, 2026
Merged via the queue into kgateway-dev:main with commit 3761c93 Jul 13, 2026
35 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/documentation kind/fix Categorizes issue or PR as related to a bug. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants