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: impl cluster buffer limit #3479

Merged
merged 7 commits into from
May 29, 2024
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
60 changes: 48 additions & 12 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
to *ir.Timeout
ka *ir.TCPKeepalive
rt *ir.Retry
bc *ir.BackendConnection
err, errs error
)

Expand Down Expand Up @@ -348,6 +349,13 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
}
}

if policy.Spec.Connection != nil {
if bc, err = t.buildBackendConnection(policy); err != nil {
err = perr.WithMessage(err, "BackendConnection")
errs = errors.Join(errs, err)
}
}

// Early return if got any errors
if errs != nil {
return errs
Expand All @@ -366,17 +374,19 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
r.CircuitBreaker = cb
r.TCPKeepalive = ka
r.Timeout = to
r.BackendConnection = bc
}
}
}

for _, udp := range x.UDP {
if udp.Route != nil {
route := udp.Route
r := udp.Route

if strings.HasPrefix(route.Destination.Name, prefix) {
route.LoadBalancer = lb
route.Timeout = to
if strings.HasPrefix(r.Destination.Name, prefix) {
r.LoadBalancer = lb
r.Timeout = to
r.BackendConnection = bc
}
}
}
Expand All @@ -386,14 +396,15 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
// Apply if there is a match
if strings.HasPrefix(r.Name, prefix) {
r.Traffic = &ir.TrafficFeatures{
RateLimit: rl,
LoadBalancer: lb,
ProxyProtocol: pp,
HealthCheck: hc,
CircuitBreaker: cb,
FaultInjection: fi,
TCPKeepalive: ka,
Retry: rt,
RateLimit: rl,
LoadBalancer: lb,
ProxyProtocol: pp,
HealthCheck: hc,
CircuitBreaker: cb,
FaultInjection: fi,
TCPKeepalive: ka,
Retry: rt,
BackendConnection: bc,
}

// Update the Host field in HealthCheck, now that we have access to the Route Hostname.
Expand Down Expand Up @@ -1139,6 +1150,31 @@ func int64ToUint32(in int64) (uint32, bool) {
return 0, false
}

func (t *Translator) buildBackendConnection(policy *egv1a1.BackendTrafficPolicy) (*ir.BackendConnection, error) {
var (
bcIR = &ir.BackendConnection{}
bc = &egv1a1.BackendTrafficPolicyConnection{}
)

if policy.Spec.Connection != nil {
bc = policy.Spec.Connection

if bc.BufferLimit != nil {
bf, ok := bc.BufferLimit.AsInt64()
if !ok {
return nil, fmt.Errorf("invalid BufferLimit value %s", bc.BufferLimit.String())
}
if bf < 0 || bf > math.MaxUint32 {
return nil, fmt.Errorf("BufferLimit value %s is out of range", bc.BufferLimit.String())
}

bcIR.BufferLimitBytes = ptr.To(uint32(bf))
}
}

return bcIR, nil
}

func (t *Translator) buildFaultInjection(policy *egv1a1.BackendTrafficPolicy) *ir.FaultInjection {
var fi *ir.FaultInjection
if policy.Spec.FaultInjection != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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
timeout:
tcp:
connectTimeout: 15s
http:
connectionIdleTimeout: 16s
maxConnectionDuration: 17s
- 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
connection:
bufferLimit: 1000G
Loading