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
13 changes: 13 additions & 0 deletions internal/gatewayapi/clustersettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ func buildLoadBalancer(policy egv1a1.ClusterSettings) (*ir.LoadBalancer, error)
}
}

// Add ZoneAware loadbalancer settings
if policy.LoadBalancer.ZoneAware != nil && policy.LoadBalancer.ZoneAware.PreferLocal != nil {
preferLocal := policy.LoadBalancer.ZoneAware.PreferLocal
lb.PreferLocal = &ir.PreferLocalZone{
MinEndpointsThreshold: preferLocal.MinEndpointsThreshold,
}
if preferLocal.Force != nil {
lb.PreferLocal.Force = &ir.ForceLocalZone{
MinEndpointsInZoneThreshold: preferLocal.Force.MinEndpointsInZoneThreshold,
}
}
}

// Add EndpointOverride if specified
if policy.LoadBalancer.EndpointOverride != nil {
lb.EndpointOverride = buildEndpointOverride(*policy.LoadBalancer.EndpointOverride)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ backendTrafficPolicies:
type: RoundRobin
slowStart:
window: 300s
zoneAware:
preferLocal:
force:
minEndpointsInZoneThreshold: 1
minEndpointsThreshold: 1
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ backendTrafficPolicies:
slowStart:
window: 5m0s
type: RoundRobin
zoneAware:
preferLocal:
force:
minEndpointsInZoneThreshold: 1
minEndpointsThreshold: 1
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
Expand Down
33 changes: 33 additions & 0 deletions test/e2e/testdata/zone-aware-routing-backendref-enabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: Service
metadata:
name: topology-aware-routing
namespace: gateway-conformance-infra
annotations:
service.kubernetes.io/topology-mode: Auto
spec:
selector:
app: zone-aware-backend
ports:
- protocol: TCP
port: 8080
name: http11
targetPort: 3000
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: topology-aware-routing
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
rules:
- matches:
- path:
type: PathPrefix
value: /topology-aware-routing
backendRefs:
- name: topology-aware-routing
port: 8080
weight: 1
49 changes: 49 additions & 0 deletions test/e2e/testdata/zone-aware-routing-btp-enabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: v1
kind: Service
metadata:
name: btp-zone-aware
namespace: gateway-conformance-infra
spec:
selector:
app: zone-aware-backend
ports:
- protocol: TCP
port: 8080
name: http11
targetPort: 3000
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: btp-zone-aware
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
rules:
- matches:
- path:
type: PathPrefix
value: /btp-zone-aware
backendRefs:
- name: btp-zone-aware
port: 8080
weight: 1
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
name: btp-zone-aware
namespace: gateway-conformance-infra
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: btp-zone-aware
loadBalancer:
type: RoundRobin
zoneAware:
preferLocal:
minEndpointsThreshold: 1
force:
minEndpointsInZoneThreshold: 1
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,3 @@ spec:
- proxy
topologyKey: topology.kubernetes.io/zone
namespaceSelector: {}
---
apiVersion: v1
kind: Service
metadata:
name: zone-aware-backend
namespace: gateway-conformance-infra
annotations:
service.kubernetes.io/topology-mode: Auto
spec:
selector:
app: zone-aware-backend
ports:
- protocol: TCP
port: 8080
name: http11
targetPort: 3000
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: zone-aware-http-route
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: zone-aware-backend
port: 8080
weight: 1
39 changes: 35 additions & 4 deletions test/e2e/tests/zone_aware_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ package tests
import (
"testing"

"k8s.io/apimachinery/pkg/types"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
"sigs.k8s.io/gateway-api/conformance/utils/suite"

"github.com/envoyproxy/gateway/internal/gatewayapi"
"github.com/envoyproxy/gateway/internal/gatewayapi/resource"
)

func init() {
Expand All @@ -19,17 +25,42 @@ func init() {

var ZoneAwareRoutingTest = suite.ConformanceTest{
ShortName: "ZoneAwareRouting",
Description: "Resource with Zone Aware Routing enabled",
Manifests: []string{"testdata/zone-aware-routing.yaml"},
Description: "Test Zone Aware Routing is working",
Manifests: []string{
"testdata/zone-aware-routing-backendref-enabled.yaml",
"testdata/zone-aware-routing-btp-enabled.yaml",
"testdata/zone-aware-routing-deployments.yaml",
},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
t.Run("only local zone should get requests", func(t *testing.T) {
t.Run("topology aware routing - only local zone should get requests", func(t *testing.T) {
// Pods from the backend-local deployment have affinity
// for the Envoy Proxy pods so should receive all requests.
expected := map[string]int{
"zone-aware-backend-local": sendRequests,
"zone-aware-backend-nonlocal": 0,
}
runWeightedBackendTest(t, suite, "topology-aware-routing", "/topology-aware-routing", "zone-aware-backend", expected)
})
t.Run("BackendTrafficPolicy - only local zone should get requests", func(t *testing.T) {
BackendTrafficPolicyMustBeAccepted(t,
suite.Client,
types.NamespacedName{Name: "btp-zone-aware", Namespace: "gateway-conformance-infra"},
suite.ControllerName,
gwapiv1a2.ParentReference{
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
Kind: gatewayapi.KindPtr(resource.KindGateway),
Namespace: gatewayapi.NamespacePtr("gateway-conformance-infra"),
Name: gwapiv1.ObjectName("same-namespace"),
},
)

// Pods from the backend-local deployment have affinity
// for the Envoy Proxy pods so should receive all requests.
expected := map[string]int{
"zone-aware-backend-local": sendRequests,
"zone-aware-backend-nonlocal": 0,
}
runWeightedBackendTest(t, suite, "zone-aware-http-route", "/", "zone-aware-backend", expected)
runWeightedBackendTest(t, suite, "btp-zone-aware", "/btp-zone-aware", "zone-aware-backend", expected)
})
},
}