Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: proxyProtocol in BackendTrafficPolicy #2192

Merged
merged 2 commits into from
Nov 23, 2023
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
29 changes: 28 additions & 1 deletion internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
var (
rl *ir.RateLimit
lb *ir.LoadBalancer
pp *ir.ProxyProtocol
)

// Build IR
Expand All @@ -250,7 +251,9 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
if policy.Spec.LoadBalancer != nil {
lb = t.buildLoadBalancer(policy)
}

if policy.Spec.ProxyProtocol != nil {
pp = t.buildProxyProtocol(policy)
}
// Apply IR to all relevant routes
prefix := irRoutePrefix(route)
for _, ir := range xdsIR {
Expand All @@ -260,6 +263,7 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
if strings.HasPrefix(r.Name, prefix) {
r.RateLimit = rl
r.LoadBalancer = lb
r.ProxyProtocol = pp
}
}
}
Expand All @@ -271,6 +275,7 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back
var (
rl *ir.RateLimit
lb *ir.LoadBalancer
pp *ir.ProxyProtocol
)

// Build IR
Expand All @@ -280,6 +285,9 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back
if policy.Spec.LoadBalancer != nil {
lb = t.buildLoadBalancer(policy)
}
if policy.Spec.ProxyProtocol != nil {
pp = t.buildProxyProtocol(policy)
}
// Apply IR to all the routes within the specific Gateway
// If the feature is already set, then skip it, since it must be have
// set by a policy attaching to the route
Expand All @@ -296,6 +304,9 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back
if r.LoadBalancer == nil {
r.LoadBalancer = lb
}
if r.ProxyProtocol == nil {
r.ProxyProtocol = pp
}
}
}

Expand Down Expand Up @@ -437,3 +448,19 @@ func (t *Translator) buildLoadBalancer(policy *egv1a1.BackendTrafficPolicy) *ir.

return lb
}

func (t *Translator) buildProxyProtocol(policy *egv1a1.BackendTrafficPolicy) *ir.ProxyProtocol {
var pp *ir.ProxyProtocol
switch policy.Spec.ProxyProtocol.Version {
case egv1a1.ProxyProtocolVersionV1:
pp = &ir.ProxyProtocol{
Version: ir.ProxyProtocolVersionV1,
}
case egv1a1.ProxyProtocolVersionV2:
pp = &ir.ProxyProtocol{
Version: ir.ProxyProtocolVersionV2,
}
}

return pp
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-2
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
grpcRoutes:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: GRPCRoute
metadata:
namespace: default
name: grpcroute-1
spec:
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: http
rules:
- backendRefs:
- name: service-1
port: 8080
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-2
sectionName: http
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-1
port: 8080
backendTrafficPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
namespace: envoy-gateway
name: policy-for-gateway
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-1
namespace: envoy-gateway
proxyProtocol:
version: V1
- 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
namespace: default
proxyProtocol:
version: V2
Loading