Overview of Transformation in TrafficPolicy
mainTransformation feature under TrafficPolicy allows for modifying request or response headers and bodies. It supports Inja templating syntax for dynamic content manipulation.repository·main·Indexed 26 days ago
https://github.com/kgateway-dev/kgatewayA Kubernetes-native API Gateway control plane that implements the Kubernetes Gateway API for the Envoy proxy. It manages API connectivity, security policies, and traffic routing for microservices, serverless, and legacy applications. The project includes tools for API development, a mock OAuth2 Identity Provider (dummy-idp), an applier utility for YAML templates, and Envoy dynamic module filters such as http-acl and Rustformation.
Transformation feature under TrafficPolicy allows for modifying request or response headers and bodies. It supports Inja templating syntax for dynamic content manipulation.kgateway is a resilient, performance-oriented control plane for Kubernetes that implements the Kubernetes Gateway API for Envoy. It is designed to scale from lightweight microgateway deployments between services to large-scale centralized gateways.
Key Use Cases:
Note on agentgateway: As of version 2.3.0, the control plane for agentgateway has been migrated to the agentgateway repository. kgateway now focuses exclusively on being a stable API Gateway powered by Envoy.
HTTPRoute resources to delegate routing configuration to other HTTPRoute resources. This feature is designed to improve maintainability by splitting large routing configurations into smaller, manageable objects, allowing different teams to manage their own routing decisions and policies independently without impacting others. It also enables the reuse of routing configurations across multiple locations.TrafficPolicy CRD to enable chaos engineering and resiliency testing. This feature allows users to simulate failure conditions such as latency (delay injection), aborts (HTTP/gRPC errors), and response rate limiting. It is designed to help validate retry policies, timeout configurations, and fallback behaviors at the gateway layer without modifying application code.Rustformation is an Envoy dynamic module filter that performs request and response transformations using MiniJinja templates. It implements the TransformationPolicy CRD spec and is attached to routes as a per-route configuration.
Capabilities:
Buffering Behavior:
parseAs: None is specified.kgateway implements a status clearing mechanism to ensure that when a resource (like an HTTPRoute or TrafficPolicy) loses its valid references (e.g., a parentRef is changed to a non-existent Gateway), its stale status conditions are cleared.
Instead of simply ignoring resources with invalid references during the translation phase, kgateway now uses a status collection pattern during the Intermediate Representation (IR) construction phase. This marks resources as "dirty" with an empty status entry. If the translation phase does not find valid references for that resource, the empty status is merged into the final report, effectively clearing the stale parents list in the Kubernetes CRD status.
kgateway implements status reporting for 'orphaned' resources to prevent stale configuration data from misleading users. An orphaned resource is a Custom Resource (CRD) such as an HTTPRoute or TrafficPolicy that contains invalid or non-existent parentRefs or targetRefs.
Previously, these resources were not picked up during the translation phase, causing their status to remain stuck on the last valid configuration. The current implementation ensures that when a resource becomes orphaned, its stale status is cleared, aligning with Kubernetes best practices and improving troubleshooting visibility.
The existing end-to-end (E2E) testing framework is a custom implementation located in test/e2e/. It is designed specifically for kgateway's lifecycle and uses three core abstractions:
TestInstallation: Bundles the runtime context, cluster context, install context, an Actions provider (wrappers for Helm, kubectl, curl), an Assertions provider (Gomega-based helpers), and a per-test failure dump directory.BaseTestingSuite: A suite that embeds testify/suite.Suite and manages the test lifecycle (Setup, Before/After Test, Teardown) including manifest application, image pre-pulling, and Gateway API version gating.SuiteRunner: Registers and executes testify suites against a single TestInstallation.Tests are organized as features/<area>/suite.go and registered in tests/<entrypoint>_tests.go. Each test method on a suite struct is treated as a Go subtest.
kgateway implements a mechanism to handle 'orphaned' resources—Kubernetes resources that previously had a status reported by kgateway but are no longer present in the current translation phase (e.g., due to a change in parentRef or deletion).
To prevent stale status information from persisting in Kubernetes, the controller identifies resources that have an existing status but are missing from the current ReportMap. For these orphaned resources, the controller adds an empty status entry to the ReportMap, which triggers the status syncer to clear the stale status in Kubernetes.
kgateway translates Kubernetes objects (Gateways, HTTPRoutes, Services, etc.) into Envoy configuration through a multi-phase process:
ir.PolicyWrapper objects. This happens early so errors can be reported on the CRD status immediately.TargetRefs to attach these policy IRs to the AttachedPolicies struct within the Gateway and HTTPRoute IRs.NewGatewayTranslationPass provided by your plugins. The plugin's ProxyTranslationPass is called with the AttachedPolicies to modify Envoy routes or listeners (e.g., adding HTTP filters).kgateway is an Envoy-powered, Kubernetes-native API Gateway. Its security and traffic handling are distributed across several specialized components:
kgateway-proxy that implements the SDS protocol, allowing certificates to be distributed to the proxy dynamically without mounting them directly into the container.kgateway-proxy that enables routing traffic to LLMs.In kgateway, TLS configuration is applied via different plugins that target different Envoy fields. Because plugin application uses Go map iteration, the order is non-deterministic.
TransportSocket on the cluster.TransportSocketMatches on the cluster.TransportSocketMatches. If you also use BackendTLSPolicy or BackendConfigPolicy, they set TransportSocket. These are different fields, so they do not overwrite each other, but they can cause functional conflicts in how traffic is handled.kgateway.dev/disable-istio-auto-mtls: "true" annotation, Istio does not set TransportSocketMatches. This allows BackendConfigPolicy and BackendTLSPolicy to configure TransportSocket without conflict.BackendConfigPolicy and BackendTLSPolicy are used, they both target TransportSocket. Since the order is random, the 'winner' is unpredictable, though BackendConfigPolicy is designed to overwrite existing TransportSocket configurations.