Skip to content

Commit

Permalink
Add e2e test for load balancing (#3868)
Browse files Browse the repository at this point in the history
* update api doc and e2e test env for lb

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* add e2e test for round robin lb

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* fix gen-check

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* add e2e test for source ip consistent hash lb

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* add e2e test for header consistent hash lb

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* add e2e test for cookie consistent hash lb

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* add deployment only for lb test case

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* rename deployment for different test setup

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

* wait deployment to have available replicas

Signed-off-by: shawnh2 <shawnhxh@outlook.com>

---------

Signed-off-by: shawnh2 <shawnhxh@outlook.com>
Co-authored-by: zirain <zirain2009@gmail.com>
  • Loading branch information
shawnh2 and zirain authored Jul 18, 2024
1 parent 09fcfb3 commit f2ce0a2
Show file tree
Hide file tree
Showing 9 changed files with 522 additions and 16 deletions.
5 changes: 4 additions & 1 deletion api/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ const (
// +kubebuilder:validation:XValidation:rule="self.type == 'Header' ? has(self.header) : !has(self.header)",message="If consistent hash type is header, the header field must be set."
// +kubebuilder:validation:XValidation:rule="self.type == 'Cookie' ? has(self.cookie) : !has(self.cookie)",message="If consistent hash type is cookie, the cookie field must be set."
type ConsistentHash struct {
// ConsistentHashType defines the type of input to hash on. Valid Type values are "SourceIP" or "Header".
// ConsistentHashType defines the type of input to hash on. Valid Type values are
// "SourceIP",
// "Header",
// "Cookie".
//
// +unionDiscriminator
Type ConsistentHashType `json:"type"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,11 @@ spec:
minimum: 2
type: integer
type:
description: ConsistentHashType defines the type of input
to hash on. Valid Type values are "SourceIP" or "Header".
description: |-
ConsistentHashType defines the type of input to hash on. Valid Type values are
"SourceIP",
"Header",
"Cookie".
enum:
- SourceIP
- Header
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ _Appears in:_

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `type` | _[ConsistentHashType](#consistenthashtype)_ | true | ConsistentHashType defines the type of input to hash on. Valid Type values are "SourceIP" or "Header". |
| `type` | _[ConsistentHashType](#consistenthashtype)_ | true | ConsistentHashType defines the type of input to hash on. Valid Type values are<br />"SourceIP",<br />"Header",<br />"Cookie". |
| `header` | _[Header](#header)_ | false | Header configures the header hash policy when the consistent hash type is set to Header. |
| `cookie` | _[Cookie](#cookie)_ | false | Cookie configures the cookie hash policy when the consistent hash type is set to Cookie. |
| `tableSize` | _integer_ | false | The table size for consistent hashing, must be prime number limited to 5000011. |
Expand Down
2 changes: 1 addition & 1 deletion site/content/zh/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ _Appears in:_

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `type` | _[ConsistentHashType](#consistenthashtype)_ | true | ConsistentHashType defines the type of input to hash on. Valid Type values are "SourceIP" or "Header". |
| `type` | _[ConsistentHashType](#consistenthashtype)_ | true | ConsistentHashType defines the type of input to hash on. Valid Type values are<br />"SourceIP",<br />"Header",<br />"Cookie". |
| `header` | _[Header](#header)_ | false | Header configures the header hash policy when the consistent hash type is set to Header. |
| `cookie` | _[Cookie](#cookie)_ | false | Cookie configures the cookie hash policy when the consistent hash type is set to Cookie. |
| `tableSize` | _integer_ | false | The table size for consistent hashing, must be prime number limited to 5000011. |
Expand Down
82 changes: 82 additions & 0 deletions test/e2e/testdata/load_balancing_consistent_hash_header.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apiVersion: v1
kind: Service
metadata:
name: lb-backend-3
namespace: gateway-conformance-infra
spec:
selector:
app: lb-backend-3
ports:
- protocol: TCP
port: 8080
targetPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: lb-backend-3
namespace: gateway-conformance-infra
labels:
app: lb-backend-3
spec:
replicas: 4
selector:
matchLabels:
app: lb-backend-3
template:
metadata:
labels:
app: lb-backend-3
spec:
containers:
- name: backend
image: gcr.io/k8s-staging-gateway-api/echo-basic:v20231214-v1.0.0-140-gf544a46e
imagePullPolicy: IfNotPresent
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SERVICE_NAME
value: lb-backend-3
resources:
requests:
cpu: 10m
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
name: header-lb-policy
namespace: gateway-conformance-infra
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: header-lb-route
loadBalancer:
type: ConsistentHash
consistentHash:
type: Header
header:
name: "Lb-Test-Header"
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: header-lb-route
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
rules:
- matches:
- path:
type: PathPrefix
value: /header
backendRefs:
- name: lb-backend-3
port: 8080
80 changes: 80 additions & 0 deletions test/e2e/testdata/load_balancing_consistent_hash_source_ip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: v1
kind: Service
metadata:
name: lb-backend-2
namespace: gateway-conformance-infra
spec:
selector:
app: lb-backend-2
ports:
- protocol: TCP
port: 8080
targetPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: lb-backend-2
namespace: gateway-conformance-infra
labels:
app: lb-backend-2
spec:
replicas: 4
selector:
matchLabels:
app: lb-backend-2
template:
metadata:
labels:
app: lb-backend-2
spec:
containers:
- name: backend
image: gcr.io/k8s-staging-gateway-api/echo-basic:v20231214-v1.0.0-140-gf544a46e
imagePullPolicy: IfNotPresent
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SERVICE_NAME
value: lb-backend-2
resources:
requests:
cpu: 10m
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
name: source-ip-lb-policy
namespace: gateway-conformance-infra
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: source-ip-lb-route
loadBalancer:
type: ConsistentHash
consistentHash:
type: SourceIP
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: source-ip-lb-route
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
rules:
- matches:
- path:
type: PathPrefix
value: /source
backendRefs:
- name: lb-backend-2
port: 8080
78 changes: 78 additions & 0 deletions test/e2e/testdata/load_balancing_round_robin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apiVersion: v1
kind: Service
metadata:
name: lb-backend-1
namespace: gateway-conformance-infra
spec:
selector:
app: lb-backend-1
ports:
- protocol: TCP
port: 8080
targetPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: lb-backend-1
namespace: gateway-conformance-infra
labels:
app: lb-backend-1
spec:
replicas: 4
selector:
matchLabels:
app: lb-backend-1
template:
metadata:
labels:
app: lb-backend-1
spec:
containers:
- name: backend
image: gcr.io/k8s-staging-gateway-api/echo-basic:v20231214-v1.0.0-140-gf544a46e
imagePullPolicy: IfNotPresent
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SERVICE_NAME
value: lb-backend-1
resources:
requests:
cpu: 10m
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
metadata:
name: round-robin-lb-policy
namespace: gateway-conformance-infra
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: round-robin-lb-route
loadBalancer:
type: RoundRobin
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: round-robin-lb-route
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
rules:
- matches:
- path:
type: PathPrefix
value: /round
backendRefs:
- name: lb-backend-1
port: 8080
Loading

0 comments on commit f2ce0a2

Please sign in to comment.