Skip to content
Merged
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
6 changes: 2 additions & 4 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ type BackendTrafficPolicySpec struct {
// If not specified, the default upgrade configuration(websocket) will be used.
//
// +optional
// +notImplementedHide
HTTPUpgrade []*ProtocolUpgradeConfig `json:"httpUpgrade,omitempty"`
}

Expand All @@ -87,9 +86,8 @@ type ProtocolUpgradeConfig struct {
//
// +kubebuilder:validation:Required
Type string `json:"type"`
// Disabled indicates whether the upgrade is disabled.
// +optional
Disabled *bool `json:"disabled"`

// TODO: support more options for CONNECT
}

// BackendTrafficPolicyList contains a list of BackendTrafficPolicy resources.
Expand Down
7 changes: 1 addition & 6 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 @@ -538,9 +538,6 @@ spec:
If not specified, the default upgrade configuration(websocket) will be used.
items:
properties:
disabled:
description: Disabled indicates whether the upgrade is disabled.
type: boolean
type:
description: |-
Type is the case-insensitive type of protocol upgrade.
Expand Down
84 changes: 50 additions & 34 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,22 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(
resources *resource.Resources,
) error {
var (
rl *ir.RateLimit
lb *ir.LoadBalancer
pp *ir.ProxyProtocol
hc *ir.HealthCheck
cb *ir.CircuitBreaker
fi *ir.FaultInjection
to *ir.Timeout
ka *ir.TCPKeepalive
rt *ir.Retry
bc *ir.BackendConnection
ds *ir.DNS
h2 *ir.HTTP2Settings
ro *ir.ResponseOverride
cp []*ir.Compression
err, errs error
rl *ir.RateLimit
lb *ir.LoadBalancer
pp *ir.ProxyProtocol
hc *ir.HealthCheck
cb *ir.CircuitBreaker
fi *ir.FaultInjection
to *ir.Timeout
ka *ir.TCPKeepalive
rt *ir.Retry
bc *ir.BackendConnection
ds *ir.DNS
h2 *ir.HTTP2Settings
ro *ir.ResponseOverride
cp []*ir.Compression
httpUpgrade []string
err, errs error
)

// Build IR
Expand Down Expand Up @@ -359,6 +360,7 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(
errs = errors.Join(errs, err)
}
cp = buildCompression(policy.Spec.Compression)
httpUpgrade = buildHTTPProtocolUpgradeConfig(policy.Spec.HTTPUpgrade)

ds = translateDNS(policy.Spec.ClusterSettings)

Expand Down Expand Up @@ -423,6 +425,7 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(
Timeout: to,
ResponseOverride: ro,
Compression: cp,
HTTPUpgrade: httpUpgrade,
}

// Update the Host field in HealthCheck, now that we have access to the Route Hostname.
Expand All @@ -440,27 +443,25 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(
}

func (t *Translator) translateBackendTrafficPolicyForGateway(
policy *egv1a1.BackendTrafficPolicy,
target gwapiv1a2.LocalPolicyTargetReferenceWithSectionName,
gateway *GatewayContext,
xdsIR resource.XdsIRMap,
resources *resource.Resources,
policy *egv1a1.BackendTrafficPolicy, target gwapiv1a2.LocalPolicyTargetReferenceWithSectionName,
gateway *GatewayContext, xdsIR resource.XdsIRMap, resources *resource.Resources,
) error {
var (
rl *ir.RateLimit
lb *ir.LoadBalancer
pp *ir.ProxyProtocol
hc *ir.HealthCheck
cb *ir.CircuitBreaker
fi *ir.FaultInjection
ct *ir.Timeout
ka *ir.TCPKeepalive
rt *ir.Retry
ds *ir.DNS
h2 *ir.HTTP2Settings
ro *ir.ResponseOverride
cp []*ir.Compression
err, errs error
rl *ir.RateLimit
lb *ir.LoadBalancer
pp *ir.ProxyProtocol
hc *ir.HealthCheck
cb *ir.CircuitBreaker
fi *ir.FaultInjection
ct *ir.Timeout
ka *ir.TCPKeepalive
rt *ir.Retry
ds *ir.DNS
h2 *ir.HTTP2Settings
ro *ir.ResponseOverride
cp []*ir.Compression
httpUpgrade []string
err, errs error
)

// Build IR
Expand Down Expand Up @@ -506,6 +507,7 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(
errs = errors.Join(errs, err)
}
cp = buildCompression(policy.Spec.Compression)
httpUpgrade = buildHTTPProtocolUpgradeConfig(policy.Spec.HTTPUpgrade)

ds = translateDNS(policy.Spec.ClusterSettings)

Expand Down Expand Up @@ -591,6 +593,7 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(
DNS: ds,
ResponseOverride: ro,
Compression: cp,
HTTPUpgrade: httpUpgrade,
}

// Update the Host field in HealthCheck, now that we have access to the Route Hostname.
Expand Down Expand Up @@ -971,3 +974,16 @@ func buildCompression(compression []*egv1a1.Compression) []*ir.Compression {

return irCompression
}

func buildHTTPProtocolUpgradeConfig(cfgs []*egv1a1.ProtocolUpgradeConfig) []string {
if len(cfgs) == 0 {
return nil
}

result := make([]string, 0, len(cfgs))
for _, cfg := range cfgs {
result = append(result, cfg.Type)
}

return result
}
54 changes: 54 additions & 0 deletions internal/gatewayapi/backendtrafficpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,57 @@ func Test_translateRateLimitCost(t *testing.T) {
})
}
}

func TestBuildHTTPProtocolUpgradeConfig(t *testing.T) {
cases := []struct {
name string
cfgs []*egv1a1.ProtocolUpgradeConfig
expected []string
}{
{
name: "empty",
cfgs: nil,
expected: nil,
},
{
name: "spdy",
cfgs: []*egv1a1.ProtocolUpgradeConfig{
{
Type: "spdy/3.1",
},
},
expected: []string{"spdy/3.1"},
},
{
name: "websockets-spdy",
cfgs: []*egv1a1.ProtocolUpgradeConfig{
{
Type: "websockets",
},
{
Type: "spdy/3.1",
},
},
expected: []string{"websockets", "spdy/3.1"},
},
{
name: "spdy-websockets",
cfgs: []*egv1a1.ProtocolUpgradeConfig{
{
Type: "spdy/3.1",
},
{
Type: "websockets",
},
},
expected: []string{"spdy/3.1", "websockets"},
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := buildHTTPProtocolUpgradeConfig(tc.cfgs)
require.Equal(t, tc.expected, got)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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
httpUpgrade:
- type: "spdy/3.1"
Loading
Loading