Skip to content

Commit 51ab958

Browse files
Andrews2024Rahul Sharma
andauthored
[test] UDP e2e testing (#393)
* use linodego with udp support * add UDP support to CCM * add unittests * update linodego for udp_check_port fix * update documentation for UDP support * use supported linodego version * WIP: Test that algorithm is set * Finished algorithm e2e test * Added test for changing stickiness * Added test for changing udp_check_port and fixed typos * Added test to verify mode is none and fixed newlines * Fix spacing * Fixed typos and added LINODE_URL to Makefile * Addressed comments and fixed mode test * Added sleep after annotate * Added fail on unset vars * Updated tests to actually check values are correct * Fixed typos * Removed unused config_id variable --------- Co-authored-by: Rahul Sharma <[email protected]>
1 parent 3dee7ca commit 51ab958

File tree

13 files changed

+436
-8
lines changed

13 files changed

+436
-8
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ WORKER_NODES ?= 1
2727
LINODE_FIREWALL_ENABLED ?= true
2828
LINODE_REGION ?= us-lax
2929
LINODE_OS ?= linode/ubuntu22.04
30+
LINODE_URL ?= https://api.linode.com
3031
KUBECONFIG_PATH ?= $(CURDIR)/test-cluster-kubeconfig.yaml
3132
SUBNET_KUBECONFIG_PATH ?= $(CURDIR)/subnet-testing-kubeconfig.yaml
3233
MGMT_KUBECONFIG_PATH ?= $(CURDIR)/mgmt-cluster-kubeconfig.yaml
@@ -200,6 +201,7 @@ e2e-test:
200201
KUBECONFIG=$(KUBECONFIG_PATH) \
201202
REGION=$(LINODE_REGION) \
202203
LINODE_TOKEN=$(LINODE_TOKEN) \
204+
LINODE_URL=$(LINODE_URL) \
203205
chainsaw test e2e/test --parallel 2 $(E2E_FLAGS)
204206

205207
.PHONY: e2e-test-bgp
@@ -211,6 +213,7 @@ e2e-test-bgp:
211213
KUBECONFIG=$(KUBECONFIG_PATH) \
212214
REGION=$(LINODE_REGION) \
213215
LINODE_TOKEN=$(LINODE_TOKEN) \
216+
LINODE_URL=$(LINODE_URL) \
214217
chainsaw test e2e/bgp-test/lb-cilium-bgp $(E2E_FLAGS)
215218

216219
.PHONY: e2e-test-subnet
@@ -230,6 +233,7 @@ e2e-test-subnet:
230233
KUBECONFIG_PATH=$(SUBNET_KUBECONFIG_PATH) make patch-linode-ccm
231234
# Run chainsaw test
232235
LINODE_TOKEN=$(LINODE_TOKEN) \
236+
LINODE_URL=$(LINODE_URL) \
233237
FIRST_CONFIG=$(KUBECONFIG_PATH) \
234238
SECOND_CONFIG=$(SUBNET_KUBECONFIG_PATH) \
235239
chainsaw test e2e/subnet-test $(E2E_FLAGS)

cloud/linode/loadbalancers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ func (l *loadbalancers) updateNodeBalancer(
431431
currentNBNodes, err = l.client.ListNodeBalancerNodes(ctx, nb.ID, currentNBCfg.ID, nil)
432432
if err != nil {
433433
// This error can be ignored, because if we fail to get nodes we can anyway rebuild the config from scratch,
434-
// it would just cause the NB to reload config even if the node list did not change, so we prefer to send IDs when it is posible.
434+
// it would just cause the NB to reload config even if the node list did not change, so we prefer to send IDs when it is possible.
435435
klog.Warningf("Unable to list existing nodebalancer nodes for NB %d config %d, error: %s", nb.ID, newNBCfg.ID, err)
436436
}
437437
for _, node := range currentNBNodes {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
name: lb-with-udp-ports-algorithm
6+
labels:
7+
all:
8+
lke:
9+
spec:
10+
namespace: "lb-with-udp-ports-algorithm"
11+
steps:
12+
- name: Create pods and services
13+
try:
14+
- apply:
15+
file: create-pods-services.yaml
16+
catch:
17+
- describe:
18+
apiVersion: v1
19+
kind: Pod
20+
- describe:
21+
apiVersion: v1
22+
kind: Service
23+
- name: Check that loadbalancer ip is assigned
24+
try:
25+
- assert:
26+
resource:
27+
apiVersion: v1
28+
kind: Service
29+
metadata:
30+
name: svc-test
31+
status:
32+
(loadBalancer.ingress[0].ip != null): true
33+
- name: Fetch nodebalancer config for port 7070
34+
try:
35+
- script:
36+
content: |
37+
set -euo pipefail
38+
39+
echo "Starting e2e test"
40+
41+
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
42+
43+
echo "Nodebalancer ID: $nbid"
44+
45+
nbconfig=$(LINODE_TOKEN=$LINODE_TOKEN NBID=$nbid ../scripts/get-nb-config.sh)
46+
47+
echo "Nodebalancer config found, updating config algorithm"
48+
49+
kubectl annotate --overwrite svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-default-algorithm=ring_hash
50+
sleep 5s
51+
52+
echo "Verifying that algorithm is set to ring hash"
53+
nbconfig=$(LINODE_TOKEN=$LINODE_TOKEN NBID=$nbid ../scripts/get-nb-config.sh)
54+
algorithm=$(echo $nbconfig | jq -r '.algorithm')
55+
echo "algorithm is $algorithm"
56+
check:
57+
($error == null): true
58+
(contains($stdout, 'algorithm is ring_hash')): true
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
labels:
6+
app: lb-with-udp-ports-algorithm
7+
name: test
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: lb-with-udp-ports-algorithm
13+
template:
14+
metadata:
15+
labels:
16+
app: lb-with-udp-ports-algorithm
17+
spec:
18+
containers:
19+
- image: rahulait/test-server:0.1
20+
name: test
21+
ports:
22+
- name: udp
23+
containerPort: 7070
24+
protocol: UDP
25+
env:
26+
- name: POD_NAME
27+
valueFrom:
28+
fieldRef:
29+
apiVersion: v1
30+
fieldPath: metadata.name
31+
---
32+
apiVersion: v1
33+
kind: Service
34+
metadata:
35+
name: svc-test
36+
labels:
37+
app: lb-with-udp-ports-algorithm
38+
spec:
39+
type: LoadBalancer
40+
selector:
41+
app: lb-with-udp-ports-algorithm
42+
ports:
43+
- name: udp
44+
protocol: UDP
45+
port: 7070
46+
targetPort: 7070
47+
sessionAffinity: None
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
name: lb-with-udp-ports-change-port
6+
labels:
7+
all:
8+
lke:
9+
spec:
10+
namespace: "lb-with-udp-ports-change-port"
11+
steps:
12+
- name: Create pods and services
13+
try:
14+
- apply:
15+
file: create-pods-services.yaml
16+
catch:
17+
- describe:
18+
apiVersion: v1
19+
kind: Pod
20+
- describe:
21+
apiVersion: v1
22+
kind: Service
23+
- name: Check that loadbalancer ip is assigned
24+
try:
25+
- assert:
26+
resource:
27+
apiVersion: v1
28+
kind: Service
29+
metadata:
30+
name: svc-test
31+
status:
32+
(loadBalancer.ingress[0].ip != null): true
33+
- name: Fetch nodebalancer config for port 7070
34+
try:
35+
- script:
36+
content: |
37+
set -euo pipefail
38+
39+
echo "Starting e2e test"
40+
41+
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
42+
43+
echo "Nodebalancer ID: $nbid"
44+
45+
nbconfig=$(LINODE_TOKEN=$LINODE_TOKEN NBID=$nbid ../scripts/get-nb-config.sh)
46+
47+
echo "Nodebalancer config found, updating config udp_check_port"
48+
49+
kubectl annotate --overwrite svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-udp-check-port=4500
50+
sleep 5s
51+
52+
echo "Verifying that udp_check_port is set to 4500"
53+
nbconfig=$(LINODE_TOKEN=$LINODE_TOKEN NBID=$nbid ../scripts/get-nb-config.sh)
54+
udp_check_port=$(echo $nbconfig | jq -r '.udp_check_port')
55+
echo "udp_check_port is $udp_check_port"
56+
check:
57+
($error == null): true
58+
(contains($stdout, 'udp_check_port is 4500')): true
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
labels:
6+
app: lb-with-udp-ports-change-port
7+
name: test
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: lb-with-udp-ports-change-port
13+
template:
14+
metadata:
15+
labels:
16+
app: lb-with-udp-ports-change-port
17+
spec:
18+
containers:
19+
- image: rahulait/test-server:0.1
20+
name: test
21+
ports:
22+
- name: udp
23+
containerPort: 7070
24+
protocol: UDP
25+
env:
26+
- name: POD_NAME
27+
valueFrom:
28+
fieldRef:
29+
apiVersion: v1
30+
fieldPath: metadata.name
31+
---
32+
apiVersion: v1
33+
kind: Service
34+
metadata:
35+
name: svc-test
36+
labels:
37+
app: lb-with-udp-ports-change-port
38+
spec:
39+
type: LoadBalancer
40+
selector:
41+
app: lb-with-udp-ports-change-port
42+
ports:
43+
- name: udp
44+
protocol: UDP
45+
port: 7070
46+
targetPort: 7070
47+
sessionAffinity: None
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
name: lb-with-udp-ports-mode
6+
labels:
7+
all:
8+
lke:
9+
spec:
10+
namespace: "lb-with-udp-ports-mode"
11+
steps:
12+
- name: Create pods and services
13+
try:
14+
- apply:
15+
file: create-pods-services.yaml
16+
catch:
17+
- describe:
18+
apiVersion: v1
19+
kind: Pod
20+
- describe:
21+
apiVersion: v1
22+
kind: Service
23+
- name: Check that loadbalancer ip is assigned
24+
try:
25+
- assert:
26+
resource:
27+
apiVersion: v1
28+
kind: Service
29+
metadata:
30+
name: svc-test
31+
status:
32+
(loadBalancer.ingress[0].ip != null): true
33+
- name: Fetch nodebalancer config for port 7070
34+
try:
35+
- script:
36+
content: |
37+
set -euo pipefail
38+
39+
echo "Starting e2e test"
40+
41+
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
42+
43+
echo "Nodebalancer ID: $nbid"
44+
45+
nbconfig=$(LINODE_TOKEN=$LINODE_TOKEN NBID=$nbid ../scripts/get-nb-config.sh)
46+
config_id=$(echo $nbconfig | jq -r '.id')
47+
48+
mode=$(curl -s \
49+
--url $LINODE_URL/v4beta/nodebalancers/$nbid/configs/$config_id/nodes \
50+
-H 'accept: application/json' \
51+
-H "Authorization: Bearer $LINODE_TOKEN" | jq -r '.data[0].mode')
52+
echo "mode is $mode"
53+
check:
54+
($error == null): true
55+
(contains($stdout, 'mode is none')): true
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
labels:
6+
app: lb-with-udp-ports-mode
7+
name: test
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: lb-with-udp-ports-mode
13+
template:
14+
metadata:
15+
labels:
16+
app: lb-with-udp-ports-mode
17+
spec:
18+
containers:
19+
- image: rahulait/test-server:0.1
20+
name: test
21+
ports:
22+
- name: udp
23+
containerPort: 7070
24+
protocol: UDP
25+
env:
26+
- name: POD_NAME
27+
valueFrom:
28+
fieldRef:
29+
apiVersion: v1
30+
fieldPath: metadata.name
31+
---
32+
apiVersion: v1
33+
kind: Service
34+
metadata:
35+
name: svc-test
36+
labels:
37+
app: lb-with-udp-ports-mode
38+
spec:
39+
type: LoadBalancer
40+
selector:
41+
app: lb-with-udp-ports-mode
42+
ports:
43+
- name: udp
44+
protocol: UDP
45+
port: 7070
46+
targetPort: 7070
47+
sessionAffinity: None

0 commit comments

Comments
 (0)