Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/v1alpha1/clienttrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ type ClientTrafficPolicySpec struct {
//
// +optional
HealthCheck *HealthCheckSettings `json:"healthCheck,omitempty"`

// Decompression provides configuration for request/response decompression.
// Decompression is compatible with HTTP compression performed by the backend.
//
// +patchMergeKey=type
// +patchStrategy=merge
//
// +optional
Decompression []*Decompression `json:"decompression,omitempty" patchMergeKey:"type" patchStrategy:"merge"`
}

// HeaderSettings provides configuration options for headers on the listener.
Expand Down
67 changes: 67 additions & 0 deletions api/v1alpha1/decompressor_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package v1alpha1

// DecompressorType defines the types of decompressor library supported by Envoy Gateway.
//
// +kubebuilder:validation:Enum=Gzip;Brotli;Zstd
type DecompressorType string

const (
GzipDecompressorType DecompressorType = "Gzip"

BrotliDecompressorType DecompressorType = "Brotli"

ZstdDecompressorType DecompressorType = "Zstd"
)

// GzipDecompressor defines the config for the Gzip decompressor.
// The default values can be found here:
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/compression/gzip/decompressor/v3/gzip.proto#extension-envoy-compression-gzip-decompressor
type GzipDecompressor struct {
// WindowBits is the window size for decompression. The valid range is 9 to 15.
// The default value is 15.
//
// +optional
// +kubebuilder:validation:Minimum=9
// +kubebuilder:validation:Maximum=15
// +kubebuilder:default=15
WindowBits *uint32 `json:"windowBits,omitempty"`
}

// BrotliDecompressor defines the config for the Brotli decompressor.
// The default values can be found here:
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/compression/brotli/decompressor/v3/brotli.proto#extension-envoy-compression-brotli-decompressor
type BrotliDecompressor struct{}

// ZstdDecompressor defines the config for the Zstd decompressor.
// The default values can be found here:
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/compression/zstd/decompressor/v3/zstd.proto#extension-envoy-compression-zstd-decompressor
type ZstdDecompressor struct{}

// Decompression defines the config of enabling decompression.
// This can help decompress compressed request/response bodies.
type Decompression struct {
// DecompressorType defines the decompressor type to use for decompression.
//
// +required
Type DecompressorType `json:"type"`

// The configuration for Brotli decompressor.
//
// +optional
Brotli *BrotliDecompressor `json:"brotli,omitempty"`

// The configuration for GZIP decompressor.
//
// +optional
Gzip *GzipDecompressor `json:"gzip,omitempty"`

// The configuration for Zstd decompressor.
//
// +optional
Zstd *ZstdDecompressor `json:"zstd,omitempty"`
}
5 changes: 4 additions & 1 deletion api/v1alpha1/envoyproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ type FilterPosition struct {
}

// EnvoyFilter defines the type of Envoy HTTP filter.
// +kubebuilder:validation:Enum=envoy.filters.http.health_check;envoy.filters.http.fault;envoy.filters.http.cors;envoy.filters.http.ext_authz;envoy.filters.http.api_key_auth;envoy.filters.http.basic_auth;envoy.filters.http.oauth2;envoy.filters.http.jwt_authn;envoy.filters.http.stateful_session;envoy.filters.http.lua;envoy.filters.http.ext_proc;envoy.filters.http.wasm;envoy.filters.http.rbac;envoy.filters.http.local_ratelimit;envoy.filters.http.ratelimit;envoy.filters.http.custom_response;envoy.filters.http.compressor
// +kubebuilder:validation:Enum=envoy.filters.http.health_check;envoy.filters.http.fault;envoy.filters.http.cors;envoy.filters.http.ext_authz;envoy.filters.http.api_key_auth;envoy.filters.http.basic_auth;envoy.filters.http.oauth2;envoy.filters.http.jwt_authn;envoy.filters.http.stateful_session;envoy.filters.http.lua;envoy.filters.http.ext_proc;envoy.filters.http.wasm;envoy.filters.http.rbac;envoy.filters.http.local_ratelimit;envoy.filters.http.ratelimit;envoy.filters.http.custom_response;envoy.filters.http.compressor;envoy.filters.http.decompressor
type EnvoyFilter string

const (
Expand Down Expand Up @@ -287,6 +287,9 @@ const (
// EnvoyFilterCompressor defines the Envoy HTTP compressor filter.
EnvoyFilterCompressor EnvoyFilter = "envoy.filters.http.compressor"

// EnvoyFilterDecompressor defines the Envoy HTTP decompressor filter.
EnvoyFilterDecompressor EnvoyFilter = "envoy.filters.http.decompressor"

// EnvoyFilterRouter defines the Envoy HTTP router filter.
EnvoyFilterRouter EnvoyFilter = "envoy.filters.http.router"

Expand Down
91 changes: 91 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions examples/kubernetes/decompressor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: eg-gateway
namespace: default
spec:
gatewayClassName: eg
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
name: decompressor-config
namespace: default
spec:
# Attach this policy to the Gateway
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: eg-gateway
# Configure decompression for gzip, brotli, and zstd compressed requests/responses
decompression:
- type: Gzip
gzip:
windowBits: 15 # Default window size for gzip
- type: Brotli
brotli: {} # Use default settings for brotli
- type: Zstd
zstd: {} # Use default settings for zstd
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: example-httproute
namespace: default
spec:
parentRefs:
- name: eg-gateway
hostnames:
- "www.example.com"
rules:
- backendRefs:
- name: example-service
port: 80
---
apiVersion: v1
kind: Service
metadata:
name: example-service
namespace: default
spec:
selector:
app: example-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app
namespace: default
spec:
selector:
matchLabels:
app: example-app
replicas: 1
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-app
image: kennethreitz/httpbin
ports:
- containerPort: 8080
21 changes: 21 additions & 0 deletions internal/gatewayapi/clienttrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ func (t *Translator) translateClientTrafficPolicyForListener(policy *egv1a1.Clie
// Translate Health Check Settings
translateHealthCheckSettings(policy.Spec.HealthCheck, httpIR)

// Translate Decompression Settings
translateDecompressionSettings(policy.Spec.Decompression, httpIR)

// Translate TLS parameters
tlsConfig, err = t.buildListenerTLSParameters(policy, httpIR.TLS, resources)
if err != nil {
Expand Down Expand Up @@ -800,6 +803,24 @@ func translateHealthCheckSettings(healthCheckSettings *egv1a1.HealthCheckSetting
httpIR.HealthCheck = (*ir.HealthCheckSettings)(healthCheckSettings)
}

func translateDecompressionSettings(decompressionSettings []*egv1a1.Decompression, httpIR *ir.HTTPListener) {
// Return early if not set
if len(decompressionSettings) == 0 {
return
}

httpIR.Decompression = make([]*ir.Decompression, 0, len(decompressionSettings))
for _, decomp := range decompressionSettings {
irDecomp := &ir.Decompression{
Type: decomp.Type,
Gzip: decomp.Gzip,
Brotli: decomp.Brotli,
Zstd: decomp.Zstd,
}
httpIR.Decompression = append(httpIR.Decompression, irDecomp)
}
}

func (t *Translator) buildListenerTLSParameters(policy *egv1a1.ClientTrafficPolicy,
irTLSConfig *ir.TLSConfig, resources *resource.Resources,
) (*ir.TLSConfig, error) {
Expand Down
15 changes: 15 additions & 0 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ type HTTPListener struct {
Connection *ClientConnection `json:"connection,omitempty" yaml:"connection,omitempty"`
// PreserveRouteOrder determines if routes should be sorted according to GW-API specs
PreserveRouteOrder bool `json:"preserveRouteOrder,omitempty" yaml:"preserveRouteOrder,omitempty"`
// Decompression holds the decompression configuration for the listener
Decompression []*Decompression `json:"decompression,omitempty" yaml:"decompression,omitempty"`
}

// Validate the fields within the HTTPListener structure
Expand Down Expand Up @@ -873,6 +875,19 @@ type Compression struct {
Type egv1a1.CompressorType `json:"type" yaml:"type"`
}

// Decompression holds the configuration for HTTP decompression.
// +k8s:deepcopy-gen=true
type Decompression struct {
// Type of decompression to be used.
Type egv1a1.DecompressorType `json:"type" yaml:"type"`
// Gzip decompressor configuration.
Gzip *egv1a1.GzipDecompressor `json:"gzip,omitempty" yaml:"gzip,omitempty"`
// Brotli decompressor configuration.
Brotli *egv1a1.BrotliDecompressor `json:"brotli,omitempty" yaml:"brotli,omitempty"`
// Zstd decompressor configuration.
Zstd *egv1a1.ZstdDecompressor `json:"zstd,omitempty" yaml:"zstd,omitempty"`
}

// TrafficFeatures holds the information associated with the Backend Traffic Policy.
// +k8s:deepcopy-gen=true
type TrafficFeatures struct {
Expand Down
Loading