Skip to content

Commit b8878d5

Browse files
jukiezirain
authored andcommitted
fix: Fix BTP ZoneAware translation (envoyproxy#6668)
* Fix BTP ZoneAware translation Signed-off-by: jukie <[email protected]> * Add e2e Signed-off-by: jukie <[email protected]> --------- Signed-off-by: jukie <[email protected]> Signed-off-by: zirain <[email protected]>
1 parent fe92679 commit b8878d5

File tree

7 files changed

+140
-38
lines changed

7 files changed

+140
-38
lines changed

internal/gatewayapi/clustersettings.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,19 @@ func buildLoadBalancer(policy egv1a1.ClusterSettings) (*ir.LoadBalancer, error)
312312
}
313313
}
314314

315+
// Add ZoneAware loadbalancer settings
316+
if policy.LoadBalancer.ZoneAware != nil && policy.LoadBalancer.ZoneAware.PreferLocal != nil {
317+
preferLocal := policy.LoadBalancer.ZoneAware.PreferLocal
318+
lb.PreferLocal = &ir.PreferLocalZone{
319+
MinEndpointsThreshold: preferLocal.MinEndpointsThreshold,
320+
}
321+
if preferLocal.Force != nil {
322+
lb.PreferLocal.Force = &ir.ForceLocalZone{
323+
MinEndpointsInZoneThreshold: preferLocal.Force.MinEndpointsInZoneThreshold,
324+
}
325+
}
326+
}
327+
315328
// Add EndpointOverride if specified
316329
if policy.LoadBalancer.EndpointOverride != nil {
317330
lb.EndpointOverride = buildEndpointOverride(*policy.LoadBalancer.EndpointOverride)

internal/gatewayapi/testdata/backendtrafficpolicy-with-loadbalancer.in.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ backendTrafficPolicies:
142142
type: RoundRobin
143143
slowStart:
144144
window: 300s
145+
zoneAware:
146+
preferLocal:
147+
force:
148+
minEndpointsInZoneThreshold: 1
149+
minEndpointsThreshold: 1
145150
- apiVersion: gateway.envoyproxy.io/v1alpha1
146151
kind: BackendTrafficPolicy
147152
metadata:

internal/gatewayapi/testdata/backendtrafficpolicy-with-loadbalancer.out.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ backendTrafficPolicies:
130130
slowStart:
131131
window: 5m0s
132132
type: RoundRobin
133+
zoneAware:
134+
preferLocal:
135+
force:
136+
minEndpointsInZoneThreshold: 1
137+
minEndpointsThreshold: 1
133138
targetRef:
134139
group: gateway.networking.k8s.io
135140
kind: Gateway
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: topology-aware-routing
5+
namespace: gateway-conformance-infra
6+
annotations:
7+
service.kubernetes.io/topology-mode: Auto
8+
spec:
9+
selector:
10+
app: zone-aware-backend
11+
ports:
12+
- protocol: TCP
13+
port: 8080
14+
name: http11
15+
targetPort: 3000
16+
---
17+
apiVersion: gateway.networking.k8s.io/v1
18+
kind: HTTPRoute
19+
metadata:
20+
name: topology-aware-routing
21+
namespace: gateway-conformance-infra
22+
spec:
23+
parentRefs:
24+
- name: same-namespace
25+
rules:
26+
- matches:
27+
- path:
28+
type: PathPrefix
29+
value: /topology-aware-routing
30+
backendRefs:
31+
- name: topology-aware-routing
32+
port: 8080
33+
weight: 1
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: btp-zone-aware
5+
namespace: gateway-conformance-infra
6+
spec:
7+
selector:
8+
app: zone-aware-backend
9+
ports:
10+
- protocol: TCP
11+
port: 8080
12+
name: http11
13+
targetPort: 3000
14+
---
15+
apiVersion: gateway.networking.k8s.io/v1
16+
kind: HTTPRoute
17+
metadata:
18+
name: btp-zone-aware
19+
namespace: gateway-conformance-infra
20+
spec:
21+
parentRefs:
22+
- name: same-namespace
23+
rules:
24+
- matches:
25+
- path:
26+
type: PathPrefix
27+
value: /btp-zone-aware
28+
backendRefs:
29+
- name: btp-zone-aware
30+
port: 8080
31+
weight: 1
32+
---
33+
apiVersion: gateway.envoyproxy.io/v1alpha1
34+
kind: BackendTrafficPolicy
35+
metadata:
36+
name: btp-zone-aware
37+
namespace: gateway-conformance-infra
38+
spec:
39+
targetRefs:
40+
- group: gateway.networking.k8s.io
41+
kind: HTTPRoute
42+
name: btp-zone-aware
43+
loadBalancer:
44+
type: RoundRobin
45+
zoneAware:
46+
preferLocal:
47+
minEndpointsThreshold: 1
48+
force:
49+
minEndpointsInZoneThreshold: 1

test/e2e/testdata/zone-aware-routing.yaml renamed to test/e2e/testdata/zone-aware-routing-deployments.yaml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -99,37 +99,3 @@ spec:
9999
- proxy
100100
topologyKey: topology.kubernetes.io/zone
101101
namespaceSelector: {}
102-
---
103-
apiVersion: v1
104-
kind: Service
105-
metadata:
106-
name: zone-aware-backend
107-
namespace: gateway-conformance-infra
108-
annotations:
109-
service.kubernetes.io/topology-mode: Auto
110-
spec:
111-
selector:
112-
app: zone-aware-backend
113-
ports:
114-
- protocol: TCP
115-
port: 8080
116-
name: http11
117-
targetPort: 3000
118-
---
119-
apiVersion: gateway.networking.k8s.io/v1
120-
kind: HTTPRoute
121-
metadata:
122-
name: zone-aware-http-route
123-
namespace: gateway-conformance-infra
124-
spec:
125-
parentRefs:
126-
- name: same-namespace
127-
rules:
128-
- matches:
129-
- path:
130-
type: PathPrefix
131-
value: /
132-
backendRefs:
133-
- name: zone-aware-backend
134-
port: 8080
135-
weight: 1

test/e2e/tests/zone_aware_routing.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ package tests
1010
import (
1111
"testing"
1212

13+
"k8s.io/apimachinery/pkg/types"
14+
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
15+
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
1316
"sigs.k8s.io/gateway-api/conformance/utils/suite"
17+
18+
"github.com/envoyproxy/gateway/internal/gatewayapi"
19+
"github.com/envoyproxy/gateway/internal/gatewayapi/resource"
1420
)
1521

1622
func init() {
@@ -19,17 +25,42 @@ func init() {
1925

2026
var ZoneAwareRoutingTest = suite.ConformanceTest{
2127
ShortName: "ZoneAwareRouting",
22-
Description: "Resource with Zone Aware Routing enabled",
23-
Manifests: []string{"testdata/zone-aware-routing.yaml"},
28+
Description: "Test Zone Aware Routing is working",
29+
Manifests: []string{
30+
"testdata/zone-aware-routing-backendref-enabled.yaml",
31+
"testdata/zone-aware-routing-btp-enabled.yaml",
32+
"testdata/zone-aware-routing-deployments.yaml",
33+
},
2434
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
25-
t.Run("only local zone should get requests", func(t *testing.T) {
35+
t.Run("topology aware routing - only local zone should get requests", func(t *testing.T) {
36+
// Pods from the backend-local deployment have affinity
37+
// for the Envoy Proxy pods so should receive all requests.
38+
expected := map[string]int{
39+
"zone-aware-backend-local": sendRequests,
40+
"zone-aware-backend-nonlocal": 0,
41+
}
42+
runWeightedBackendTest(t, suite, "topology-aware-routing", "/topology-aware-routing", "zone-aware-backend", expected)
43+
})
44+
t.Run("BackendTrafficPolicy - only local zone should get requests", func(t *testing.T) {
45+
BackendTrafficPolicyMustBeAccepted(t,
46+
suite.Client,
47+
types.NamespacedName{Name: "btp-zone-aware", Namespace: "gateway-conformance-infra"},
48+
suite.ControllerName,
49+
gwapiv1a2.ParentReference{
50+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
51+
Kind: gatewayapi.KindPtr(resource.KindGateway),
52+
Namespace: gatewayapi.NamespacePtr("gateway-conformance-infra"),
53+
Name: gwapiv1.ObjectName("same-namespace"),
54+
},
55+
)
56+
2657
// Pods from the backend-local deployment have affinity
2758
// for the Envoy Proxy pods so should receive all requests.
2859
expected := map[string]int{
2960
"zone-aware-backend-local": sendRequests,
3061
"zone-aware-backend-nonlocal": 0,
3162
}
32-
runWeightedBackendTest(t, suite, "zone-aware-http-route", "/", "zone-aware-backend", expected)
63+
runWeightedBackendTest(t, suite, "btp-zone-aware", "/btp-zone-aware", "zone-aware-backend", expected)
3364
})
3465
},
3566
}

0 commit comments

Comments
 (0)