Skip to content

Commit e92333b

Browse files
committed
address comments
Signed-off-by: Huabing (Robin) Zhao <huabing@tetrate.io>
1 parent b0bd883 commit e92333b

22 files changed

Lines changed: 650 additions & 362 deletions

api/v1alpha1/backendtrafficpolicy_types.go

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type BackendTrafficPolicy struct {
4545
// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, ref.kind in ['Gateway', 'ListenerSet', 'HTTPRoute', 'GRPCRoute', 'UDPRoute', 'TCPRoute', 'TLSRoute']) : true ", message="this policy can only have a targetRefs[*].kind of Gateway/ListenerSet/HTTPRoute/GRPCRoute/TCPRoute/UDPRoute/TLSRoute"
4646
// +kubebuilder:validation:XValidation:rule="!has(self.mergeType) || ((!has(self.targetRef) || self.targetRef.kind in ['HTTPRoute', 'GRPCRoute', 'UDPRoute', 'TCPRoute', 'TLSRoute']) && (!has(self.targetRefs) || self.targetRefs.all(ref, ref.kind in ['HTTPRoute', 'GRPCRoute', 'UDPRoute', 'TCPRoute', 'TLSRoute'])) && (!has(self.targetSelectors) || self.targetSelectors.all(sel, sel.kind in ['HTTPRoute', 'GRPCRoute', 'UDPRoute', 'TCPRoute', 'TLSRoute'])))", message="mergeType can only be used with xRoute targets"
4747
// +kubebuilder:validation:XValidation:rule="!has(self.compression) || !has(self.compressor)", message="either compression or compressor can be set, not both"
48-
// +kubebuilder:validation:XValidation:rule="!has(self.requestBuffer) || !has(self.httpUpgrade) || self.httpUpgrade.size() == 0", message="requestBuffer cannot be used together with httpUpgrade"
48+
// +kubebuilder:validation:XValidation:rule="!has(self.requestBuffer) || self.requestBuffer.mode == 'LimitOnly' || !has(self.httpUpgrade) || self.httpUpgrade.size() == 0", message="requestBuffer with mode FullBuffer cannot be used together with httpUpgrade"
4949
// +kubebuilder:validation:XValidation:rule="!has(self.admissionControl) || ((!has(self.targetRef) || self.targetRef.kind in ['Gateway', 'ListenerSet', 'HTTPRoute', 'GRPCRoute']) && (!has(self.targetRefs) || self.targetRefs.all(ref, ref.kind in ['Gateway', 'ListenerSet', 'HTTPRoute', 'GRPCRoute'])) && (!has(self.targetSelectors) || self.targetSelectors.all(sel, sel.kind in ['Gateway', 'ListenerSet', 'HTTPRoute', 'GRPCRoute'])))", message="admissionControl can only be used with HTTPRoute, GRPCRoute, Gateway, or ListenerSet targets"
5050
type BackendTrafficPolicySpec struct {
5151
PolicyTargetReferences `json:",inline"`
@@ -117,56 +117,27 @@ type BackendTrafficPolicySpec struct {
117117
ResponseOverride []*ResponseOverride `json:"responseOverride,omitempty"`
118118
// HTTPUpgrade defines the configuration for HTTP protocol upgrades.
119119
// If not specified, the default upgrade configuration (websocket) will be used.
120-
// However, if requestBuffer is configured, the default upgrade configuration
121-
// will be ignored.
120+
// However, if requestBuffer is configured with mode FullBuffer, the default
121+
// upgrade configuration will be ignored.
122122
//
123123
// +patchMergeKey=type
124124
// +patchStrategy=merge
125125
//
126126
// +optional
127127
HTTPUpgrade []*ProtocolUpgradeConfig `json:"httpUpgrade,omitempty" patchMergeKey:"type" patchStrategy:"merge"`
128128

129-
// RequestBuffer allows the gateway to buffer and fully receive each request from a client before continuing to send the request
130-
// upstream to the backends. This can be helpful to shield your backend servers from slow clients, and also to enforce a maximum size per request
131-
// as any requests larger than the buffer size will be rejected.
129+
// RequestBuffer configures how much of a request body Envoy is allowed to buffer for a route,
130+
// and whether the gateway fully buffers each request before forwarding it upstream.
132131
//
133-
// This can have a negative performance impact so should only be enabled when necessary.
132+
// A request whose buffered body exceeds the configured limit is rejected with HTTP 413 Content Too
133+
// Large. How much of a request is buffered, and therefore whether the limit acts as a maximum request
134+
// body size, depends on the mode: see the mode field.
134135
//
135-
// Envoy sets the request buffer limit for the stream to this limit, so there is no need to also raise the connection buffer size or
136-
// requestBodyBufferLimit for it to take effect. Buffering does increase memory usage for Envoy that should be accounted for in your
137-
// deployment settings.
138-
//
139-
// Request buffering is incompatible with streaming APIs and protocol upgrades such as gRPC streaming and WebSocket. Do not enable this option
140-
// on routes that need those protocols, because requests can hang instead of being forwarded upstream.
136+
// Buffering increases memory usage for Envoy that should be accounted for in your deployment settings.
141137
//
142138
// +optional
143139
RequestBuffer *RequestBuffer `json:"requestBuffer,omitempty"`
144140

145-
// RequestBodyBufferLimit specifies the maximum size in bytes that Envoy may buffer for request bodies.
146-
// This configures Envoy's request body buffer limit without enabling full request buffering.
147-
//
148-
// This Request body buffer limit is independent of the connection buffer limits configured by
149-
// ClientTrafficPolicy and BackendTrafficPolicy. The connection buffer limits control downstream
150-
// and upstream connection read/write buffering and back pressure, while this field sets the
151-
// maximum size of an individual request body that Envoy may buffer for HTTP processing.
152-
//
153-
// For HTTP/1, connection buffer limits can still affect how request body data is read and buffered
154-
// before or while the request body limit is enforced. Configure connection buffer limits large
155-
// enough for the request body buffering you expect to allow on those connections.
156-
//
157-
// For HTTP/2, initial stream and connection window sizes control HTTP/2 flow control: how much data
158-
// can be in flight before back pressure applies. They affect upload throughput and buffering
159-
// behavior, but they are not a replacement for this request body size limit.
160-
//
161-
// If exceeded, the request will be rejected with HTTP 413 Content Too Large.
162-
//
163-
// Accepts values in resource.Quantity format (e.g., "10Mi", "500Ki").
164-
//
165-
// +kubebuilder:validation:XIntOrString
166-
// +kubebuilder:validation:Pattern="^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$"
167-
// +optional
168-
RequestBodyBufferLimit *resource.Quantity `json:"requestBodyBufferLimit,omitempty"`
169-
170141
// Telemetry configures the telemetry settings for the policy target (Gateway or xRoute).
171142
// This will override the telemetry settings in the EnvoyProxy resource.
172143
//
@@ -233,16 +204,70 @@ type ConnectConfig struct {
233204
}
234205

235206
type RequestBuffer struct {
236-
// Limit specifies the maximum allowed size in bytes for each incoming request buffer.
237-
// If exceeded, the request will be rejected with HTTP 413 Content Too Large.
207+
// Limit specifies the maximum size in bytes that Envoy may buffer for an incoming request body.
208+
// If a request's buffered body exceeds this limit, the request is rejected with HTTP 413 Content
209+
// Too Large.
210+
//
211+
// In FullBuffer mode the entire body is always buffered, so this acts as a maximum request body size.
212+
// In LimitOnly mode only what a filter later in the chain actually buffers counts against the limit,
213+
// so a streamed request that nothing buffers can exceed it and still be forwarded upstream.
238214
//
239215
// Accepts values in resource.Quantity format (e.g., "10Mi", "500Ki").
240216
//
241217
// +kubebuilder:validation:XIntOrString
242218
// +kubebuilder:validation:Pattern="^[1-9]+[0-9]*([EPTGMK]i|[EPTGMk])?$"
243219
Limit resource.Quantity `json:"limit,omitempty"`
220+
221+
// Mode determines how Limit is enforced. Defaults to FullBuffer.
222+
//
223+
// FullBuffer makes the gateway buffer and fully receive each request from a client before continuing
224+
// to send the request upstream to the backends. This can be helpful to shield your backend servers
225+
// from slow clients. Envoy sets the request buffer limit for the stream to Limit, so there is no need
226+
// to also raise the connection buffer size for it to take effect.
227+
// This can have a negative performance impact so should only be used when necessary. It is also
228+
// incompatible with streaming APIs and protocol upgrades such as gRPC streaming and WebSocket: do not
229+
// use this mode on routes that need those protocols, because requests can hang instead of being
230+
// forwarded upstream.
231+
//
232+
// LimitOnly only raises Envoy's request body buffer limit for the route, without enabling full request
233+
// buffering. Use this mode when a filter later in the chain (ext_proc, Lua, WASM, ...) buffers the
234+
// request body and the default buffer limit is too small. Unlike FullBuffer, this mode is compatible
235+
// with streaming APIs and protocol upgrades, because Envoy does not wait for the whole request body
236+
// before forwarding it upstream.
237+
//
238+
// In both modes, the request body buffer limit is independent of the connection buffer limits
239+
// configured by ClientTrafficPolicy and BackendTrafficPolicy. The connection buffer limits control
240+
// downstream and upstream connection read/write buffering and back pressure, while Limit sets the
241+
// maximum size of an individual request body that Envoy may buffer for HTTP processing.
242+
//
243+
// For HTTP/1, connection buffer limits can still affect how request body data is read and buffered
244+
// before or while the request body limit is enforced. Configure connection buffer limits large
245+
// enough for the request body buffering you expect to allow on those connections.
246+
//
247+
// For HTTP/2, initial stream and connection window sizes control HTTP/2 flow control: how much data
248+
// can be in flight before back pressure applies. They affect upload throughput and buffering
249+
// behavior, but they are not a replacement for this request body size limit.
250+
//
251+
// +kubebuilder:default=FullBuffer
252+
// +optional
253+
Mode *RequestBufferMode `json:"mode,omitempty"`
244254
}
245255

256+
// RequestBufferMode determines how RequestBuffer.Limit is applied.
257+
//
258+
// +kubebuilder:validation:Enum=FullBuffer;LimitOnly
259+
type RequestBufferMode string
260+
261+
const (
262+
// RequestBufferModeFullBuffer buffers the entire request body in the gateway before forwarding the
263+
// request upstream. It is incompatible with streaming APIs and protocol upgrades.
264+
RequestBufferModeFullBuffer RequestBufferMode = "FullBuffer"
265+
266+
// RequestBufferModeLimitOnly only raises the request body buffer limit for the route, without
267+
// enabling full request buffering.
268+
RequestBufferModeLimitOnly RequestBufferMode = "LimitOnly"
269+
)
270+
246271
// BackendTrafficPolicyList contains a list of BackendTrafficPolicy resources.
247272
//
248273
// +kubebuilder:object:root=true

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)