Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
11 changes: 11 additions & 0 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type BackendTrafficPolicy struct {
// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, ref.group == 'gateway.networking.k8s.io') : true ", message="this policy can only have a targetRefs[*].group of gateway.networking.k8s.io"
// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, ref.kind in ['Gateway', 'HTTPRoute', 'GRPCRoute', 'UDPRoute', 'TCPRoute', 'TLSRoute']) : true ", message="this policy can only have a targetRefs[*].kind of Gateway/HTTPRoute/GRPCRoute/TCPRoute/UDPRoute/TLSRoute"
// +kubebuilder:validation:XValidation:rule="has(self.targetRefs) ? self.targetRefs.all(ref, !has(ref.sectionName)) : true",message="this policy does not yet support the sectionName field"
// +kubebuilder:validation:XValidation:rule="!has(self.compression) || !has(self.compressor)", message="either compression or compressor can be set, not both"
type BackendTrafficPolicySpec struct {
PolicyTargetReferences `json:",inline"`
ClusterSettings `json:",inline"`
Expand Down Expand Up @@ -73,13 +74,23 @@ type BackendTrafficPolicySpec struct {
UseClientProtocol *bool `json:"useClientProtocol,omitempty"`

// The compression config for the http streams.
// Deprecated: Use Compressor instead.
//
// +patchMergeKey=type
// +patchStrategy=merge
//
// +optional
Compression []*Compression `json:"compression,omitempty" patchMergeKey:"type" patchStrategy:"merge"`

// The compressor config for the http streams.
// This provides more granular control over compression configuration.
//
// +patchMergeKey=type
// +patchStrategy=merge
//
// +optional
Compressor []*Compression `json:"compressor,omitempty" patchMergeKey:"type" patchStrategy:"merge"`
Copy link
Contributor

Choose a reason for hiding this comment

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

can we rm the patchMergeKey, they are not needed here


// ResponseOverride defines the configuration to override specific responses with a custom one.
// If multiple configurations are specified, the first one to match wins.
//
Expand Down
11 changes: 11 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.

Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,35 @@ spec:
type: object
type: object
compression:
description: The compression config for the http streams.
description: |-
The compression config for the http streams.
Deprecated: Use Compressor instead.
items:
description: |-
Compression defines the config of enabling compression.
This can help reduce the bandwidth at the expense of higher CPU.
properties:
brotli:
description: The configuration for Brotli compressor.
type: object
gzip:
description: The configuration for GZIP compressor.
type: object
type:
description: CompressorType defines the compressor type to use
for compression.
enum:
- Gzip
- Brotli
type: string
required:
- type
type: object
type: array
compressor:
description: |-
The compressor config for the http streams.
This provides more granular control over compression configuration.
items:
description: |-
Compression defines the config of enabling compression.
Expand Down Expand Up @@ -2208,6 +2236,8 @@ spec:
- message: this policy does not yet support the sectionName field
rule: 'has(self.targetRefs) ? self.targetRefs.all(ref, !has(ref.sectionName))
: true'
- message: either compression or compressor can be set, not both
rule: '!has(self.compression) || !has(self.compressor)'
status:
description: status defines the current status of BackendTrafficPolicy.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,35 @@ spec:
type: object
type: object
compression:
description: The compression config for the http streams.
description: |-
The compression config for the http streams.
Deprecated: Use Compressor instead.
items:
description: |-
Compression defines the config of enabling compression.
This can help reduce the bandwidth at the expense of higher CPU.
properties:
brotli:
description: The configuration for Brotli compressor.
type: object
gzip:
description: The configuration for GZIP compressor.
type: object
type:
description: CompressorType defines the compressor type to use
for compression.
enum:
- Gzip
- Brotli
type: string
required:
- type
type: object
type: array
compressor:
description: |-
The compressor config for the http streams.
This provides more granular control over compression configuration.
items:
description: |-
Compression defines the config of enabling compression.
Expand Down Expand Up @@ -2207,6 +2235,8 @@ spec:
- message: this policy does not yet support the sectionName field
rule: 'has(self.targetRefs) ? self.targetRefs.all(ref, !has(ref.sectionName))
: true'
- message: either compression or compressor can be set, not both
rule: '!has(self.compression) || !has(self.compressor)'
status:
description: status defines the current status of BackendTrafficPolicy.
properties:
Expand Down
2 changes: 1 addition & 1 deletion examples/extension-server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/spf13/pflag v1.0.10 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/mod v0.28.0 // indirect
golang.org/x/net v0.46.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/extension-server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
20 changes: 18 additions & 2 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func (t *Translator) buildTrafficFeatures(policy *egv1a1.BackendTrafficPolicy, r
errs = errors.Join(errs, err)
}

cp = buildCompression(policy.Spec.Compression)
cp = buildCompression(policy.Spec.Compression, policy.Spec.Compressor)
httpUpgrade = buildHTTPProtocolUpgradeConfig(policy.Spec.HTTPUpgrade)

ds = translateDNS(&policy.Spec.ClusterSettings)
Expand Down Expand Up @@ -1194,7 +1194,23 @@ func defaultResponseOverrideRuleName(policy *egv1a1.BackendTrafficPolicy, index
strconv.Itoa(index))
}

func buildCompression(compression []*egv1a1.Compression) []*ir.Compression {
func buildCompression(compression, compressor []*egv1a1.Compression) []*ir.Compression {
// Handle the Compressor field first (higher priority)
if len(compressor) > 0 {
irCompression := make([]*ir.Compression, 0, len(compressor))
for _, c := range compressor {
// Only add compression if the corresponding compressor not null
if (c.Type == egv1a1.GzipCompressorType && c.Gzip != nil) ||
(c.Type == egv1a1.BrotliCompressorType && c.Brotli != nil) {
irCompression = append(irCompression, &ir.Compression{
Type: c.Type,
})
}
}
return irCompression
}

// Fallback to the deprecated Compression field
if compression == nil {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-1
spec:
hostnames:
- gateway.envoyproxy.io
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: http
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-1
port: 8080
backendTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
namespace: default
name: policy-for-route
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: httproute-1
compressor:
- type: Brotli
brotli: null
- type: Gzip
gzip: null
Loading
Loading