Skip to content

Commit 0dc5b0c

Browse files
committed
Add kuttl test for routing
1 parent c4b5139 commit 0dc5b0c

13 files changed

Lines changed: 187 additions & 65 deletions

tests/templates/kuttl/smoke/10-assert.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ apiVersion: kuttl.dev/v1beta1
33
kind: TestAssert
44
timeout: 720
55
commands:
6-
- script: kubectl -n $NAMESPACE wait --for=condition=available=true trinoclusters.trino.stackable.tech/trino-default-1 --timeout 719s
6+
- script: kubectl -n $NAMESPACE wait --for=condition=available=true trinoclusters.trino.stackable.tech/trino-s-1 --timeout 719s
7+
- script: kubectl -n $NAMESPACE wait --for=condition=available=true trinoclusters.trino.stackable.tech/trino-m-1 --timeout 719s

tests/templates/kuttl/smoke/10-install-trino.yaml.j2 renamed to tests/templates/kuttl/smoke/10-install-trinos.yaml.j2

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
{% for name in ['trino-s-1', 'trino-m-1'] %}
12
---
23
apiVersion: trino.stackable.tech/v1alpha1
34
kind: TrinoCluster
45
metadata:
5-
name: trino-default-1
6+
name: {{ name }}
67
spec:
78
image:
89
{% if test_scenario['values']['trino'].find(",") > 0 %}
@@ -23,19 +24,32 @@ spec:
2324
{% endif %}
2425
coordinators:
2526
config:
27+
resources:
28+
cpu:
29+
min: 250m
30+
max: "1"
31+
memory:
32+
limit: 2Gi
2633
logging:
2734
enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }}
2835
roleGroups:
2936
default:
3037
replicas: 1
3138
workers:
3239
config:
40+
resources:
41+
cpu:
42+
min: 250m
43+
max: "1"
44+
memory:
45+
limit: 3Gi
3346
gracefulShutdownTimeout: 60s # Let the test run faster
3447
logging:
3548
enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }}
3649
roleGroups:
3750
default:
3851
replicas: 1
52+
{% endfor %}
3953
---
4054
apiVersion: authentication.stackable.tech/v1alpha1
4155
kind: AuthenticationClass

tests/templates/kuttl/smoke/20-install-trino-lb.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ kind: Deployment
99
metadata:
1010
name: trino-lb
1111
spec:
12+
# I'm a bit surprised that 3 replicas work in combination with inMemory persistence :)
13+
# Maybe Kubernetes is sticky for some reason, maybe trino-clients will retry call until they get
14+
# to the correct trino-lb instance...
1215
replicas: 3
1316
selector:
1417
matchLabels:

tests/templates/kuttl/smoke/20_trino-lb-config.yaml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ trinoClusterGroups:
1010
default:
1111
maxRunningQueries: 1
1212
trinoClusters:
13-
- name: trino-default-1
14-
endpoint: https://trino-default-1-coordinator:8443
13+
- name: trino-s-1
14+
endpoint: https://trino-s-1-coordinator:8443
1515
credentials:
1616
username: admin
1717
password: adminadmin

tests/templates/kuttl/smoke/30-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
apiVersion: batch/v1
33
kind: Job
44
metadata:
5-
name: send-queries
5+
name: test-queries
66
status:
77
succeeded: 1

tests/templates/kuttl/smoke/30-send-queries.yaml.j2

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: test-queries
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: test-queries
11+
image: oci.stackable.tech/sdp/trino-cli:{{ test_scenario['values']['trino'] }}-stackable0.0.0-dev
12+
command:
13+
- /bin/bash
14+
- -x
15+
- -euo
16+
- pipefail
17+
- -c
18+
- |
19+
# Query Trinos and trino-lb
20+
COORDINATORS=(
21+
"https://trino-s-1-coordinator:8443"
22+
"https://trino-m-1-coordinator:8443"
23+
"https://trino-lb:8443"
24+
)
25+
26+
export TRINO_USER="alice"
27+
export TRINO_PASSWORD="alicealice"
28+
QUERY="select count(*) from tpch.sf1.customer"
29+
30+
for COORDINATOR in "${COORDINATORS[@]}"; do
31+
echo "$QUERY" | java -jar trino-cli-executable.jar --server $COORDINATOR --insecure --user $TRINO_USER --password
32+
done
33+
34+
# Send multiple queries in parallel to trino-lb
35+
NUM_REQUESTS=10
36+
TRINO_LB_ADDRESS="https://trino-lb:8443"
37+
38+
pids=()
39+
40+
for ((i = 1; i <= NUM_REQUESTS; i++)); do
41+
echo "$QUERY" | java -jar trino-cli-executable.jar --server $TRINO_LB_ADDRESS --insecure --user $TRINO_USER --password &
42+
pids+=("$!")
43+
done
44+
45+
# Wait for all processes to complete and check exit codes
46+
for pid in "${pids[@]}"; do
47+
if ! wait "$pid"; then
48+
echo "One of the requests failed with a non-zero exit code."
49+
exit 1
50+
fi
51+
done
52+
53+
echo "All queries completed successfully."
54+
restartPolicy: OnFailure
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestStep
4+
commands:
5+
- script: kubectl -n $NAMESPACE delete secret trino-lb-config || true
6+
- script: kubectl -n $NAMESPACE create secret generic trino-lb-config --from-file=trino-lb-config.yaml=40_trino-lb-config.yaml
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
trinoLb:
2+
externalAddress: https://trino-lb:8443
3+
tls:
4+
enabled: true
5+
certPemFile: /certificates/cert.pem
6+
keyPemFile: /certificates/key.pem
7+
persistence:
8+
inMemory: {}
9+
trinoClusterGroups:
10+
s:
11+
maxRunningQueries: 1
12+
trinoClusters:
13+
- name: trino-s-1
14+
endpoint: https://trino-s-1-coordinator:8443
15+
credentials:
16+
username: admin
17+
password: adminadmin
18+
m:
19+
maxRunningQueries: 1
20+
trinoClusters:
21+
- name: trino-m-1
22+
endpoint: https://trino-m-1-coordinator:8443
23+
credentials:
24+
username: admin
25+
password: adminadmin
26+
trinoClusterGroupsIgnoreCert: true
27+
28+
routers:
29+
- trinoRoutingGroupHeader:
30+
headerName: X-Trino-Routing-Group
31+
- clientTags:
32+
oneOf: ["s"]
33+
trinoClusterGroup: s
34+
- clientTags:
35+
oneOf: ["m"]
36+
trinoClusterGroup: m
37+
- pythonScript:
38+
script: |
39+
from typing import Optional
40+
41+
def targetClusterGroup(query: str, headers: dict[str, str]) -> Optional[str]:
42+
user = get_user(headers)
43+
if user == "alice":
44+
return "s"
45+
elif user == "bob":
46+
return "m"
47+
else:
48+
return None
49+
50+
def get_user(headers: dict[str, str]) -> Optional[str]:
51+
return headers.get("x-trino-user")
52+
routingFallback: s
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestStep
4+
commands:
5+
- script: kubectl -n $NAMESPACE rollout restart deployment trino-lb
6+
- script: kubectl -n $NAMESPACE rollout status deployment trino-lb --watch
7+
- script: sleep 2

0 commit comments

Comments
 (0)