Skip to content

Commit 892d895

Browse files
committed
feat: add test for ensuring dashboard to KFAM communication
Signed-off-by: Kimonas Sotirchos <[email protected]>
1 parent 843d968 commit 892d895

File tree

2 files changed

+116
-10
lines changed

2 files changed

+116
-10
lines changed

testing/gh-actions/test_service.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Script to test Kubeflow dashboard services
6+
# Usage: ./test_service.sh OPERATION SERVICE_NAME [NAMESPACE] [PORT] [TARGET_PORT]
7+
8+
OPERATION="$1"
9+
SERVICE_NAME="$2"
10+
NAMESPACE="${3:-kubeflow}"
11+
PORT="${4:-8080}"
12+
TARGET_PORT="${5:-80}"
13+
14+
case "$OPERATION" in
15+
"port-forward")
16+
kubectl port-forward -n "${NAMESPACE}" service/"${SERVICE_NAME}" "${PORT}:${TARGET_PORT}" &
17+
PF_PID=$!
18+
sleep 10
19+
echo "${PF_PID}" > /tmp/portforward_${SERVICE_NAME}_${PORT}.pid
20+
;;
21+
22+
"stop-port-forward")
23+
if [ -f "/tmp/portforward_${SERVICE_NAME}_${PORT}.pid" ]; then
24+
PF_PID=$(cat /tmp/portforward_${SERVICE_NAME}_${PORT}.pid)
25+
kill "${PF_PID}"
26+
rm -f /tmp/portforward_${SERVICE_NAME}_${PORT}.pid
27+
fi
28+
;;
29+
30+
"test-health")
31+
curl -f "http://localhost:${PORT}/healthz" 2>/dev/null || curl -f "http://localhost:${PORT}/" 2>/dev/null
32+
;;
33+
34+
"test-dashboard")
35+
curl -f "http://localhost:${PORT}/" >/dev/null 2>&1
36+
curl -f "http://localhost:${PORT}/assets/dashboard.js" >/dev/null 2>&1
37+
curl -f "http://localhost:${PORT}/api/v1/namespaces" >/dev/null 2>&1
38+
curl -L "http://localhost:${PORT}/jupyter" >/dev/null 2>&1
39+
curl -L "http://localhost:${PORT}/pipeline" >/dev/null 2>&1
40+
curl -L "http://localhost:${PORT}/katib" >/dev/null 2>&1
41+
# test communication between the dashboard and access-management
42+
curl -f \
43+
-H "kubeflow-userid: test-user" \
44+
"http://localhost:${PORT}/api/workgroup/exists" \
45+
>/dev/null 2>&1
46+
;;
47+
48+
"test-kfam")
49+
curl -f "http://localhost:${PORT}/healthz" >/dev/null 2>&1
50+
curl "http://localhost:${PORT}/version" 2>/dev/null
51+
;;
52+
53+
"test-api-with-user")
54+
USER_EMAIL="${6:-test-user@example.com}"
55+
PROFILE_NAMESPACE="${7:-test-profile}"
56+
curl -H "kubeflow-userid: ${USER_EMAIL}" \
57+
"http://localhost:${PORT}/kfam/v1/bindings?namespace=${PROFILE_NAMESPACE}" \
58+
2>/dev/null
59+
;;
60+
61+
"performance-test")
62+
REQUESTS="${6:-10}"
63+
for i in $(seq 1 "${REQUESTS}"); do
64+
curl -s "http://localhost:${PORT}/" >/dev/null &
65+
done
66+
wait
67+
;;
68+
69+
"test-metrics")
70+
curl "http://localhost:${PORT}/metrics" 2>/dev/null
71+
;;
72+
73+
"validate-service")
74+
kubectl get service "${SERVICE_NAME}" -n "${NAMESPACE}"
75+
kubectl describe service "${SERVICE_NAME}" -n "${NAMESPACE}"
76+
;;
77+
78+
"check-logs")
79+
LINES="${6:-50}"
80+
# Handle special case for profiles-deployment which uses kustomize.component=profiles label
81+
if [ "${SERVICE_NAME}" = "profiles-deployment" ]; then
82+
kubectl logs -n "${NAMESPACE}" -l kustomize.component=profiles --tail="${LINES}"
83+
else
84+
kubectl logs -n "${NAMESPACE}" -l app="${SERVICE_NAME}" --tail="${LINES}"
85+
fi
86+
;;
87+
88+
"check-errors")
89+
# Handle special case for profiles-deployment which uses kustomize.component=profiles label
90+
if [ "${SERVICE_NAME}" = "profiles-deployment" ]; then
91+
kubectl logs -n "${NAMESPACE}" -l kustomize.component=profiles --tail=100 | grep -i error || echo "No errors found"
92+
else
93+
kubectl logs -n "${NAMESPACE}" -l app="${SERVICE_NAME}" --tail=100 | grep -i error || echo "No errors found"
94+
fi
95+
;;
96+
97+
*)
98+
echo "Invalid operation: ${OPERATION}"
99+
echo "Valid operations: port-forward, stop-port-forward, test-health, test-dashboard, test-kfam, test-api-with-user, performance-test, test-metrics, validate-service, check-logs, check-errors"
100+
exit 1
101+
;;
102+
esac

testing/shared/test_service.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ case "$OPERATION" in
2222
"stop-port-forward")
2323
if [ -f "/tmp/portforward_${SERVICE_NAME}_${PORT}.pid" ]; then
2424
PF_PID=$(cat /tmp/portforward_${SERVICE_NAME}_${PORT}.pid)
25-
kill "${PF_PID}"
25+
kill "${PF_PID}"
2626
rm -f /tmp/portforward_${SERVICE_NAME}_${PORT}.pid
2727
fi
2828
;;
@@ -33,24 +33,28 @@ case "$OPERATION" in
3333

3434
"test-dashboard")
3535
curl -f "http://localhost:${PORT}/" >/dev/null 2>&1
36-
curl -f "http://localhost:${PORT}/assets/dashboard.js" >/dev/null 2>&1
37-
curl -f "http://localhost:${PORT}/api/v1/namespaces" >/dev/null 2>&1
38-
curl -L "http://localhost:${PORT}/jupyter" >/dev/null 2>&1
39-
curl -L "http://localhost:${PORT}/pipeline" >/dev/null 2>&1
40-
curl -L "http://localhost:${PORT}/katib" >/dev/null 2>&1
36+
curl -f "http://localhost:${PORT}/assets/dashboard.js" >/dev/null 2>&1
37+
curl -f "http://localhost:${PORT}/api/v1/namespaces" >/dev/null 2>&1
38+
curl -L "http://localhost:${PORT}/jupyter" >/dev/null 2>&1
39+
curl -L "http://localhost:${PORT}/pipeline" >/dev/null 2>&1
40+
curl -L "http://localhost:${PORT}/katib" >/dev/null 2>&1
41+
curl -f \
42+
-H "kubeflow-userid: test-user" \
43+
"http://localhost:${PORT}/api/workgroup/exists" \
44+
>/dev/null 2>&1
4145
;;
4246

4347
"test-kfam")
4448
curl -f "http://localhost:${PORT}/healthz" >/dev/null 2>&1
45-
curl "http://localhost:${PORT}/version" 2>/dev/null
49+
curl "http://localhost:${PORT}/version" 2>/dev/null
4650
;;
4751

4852
"test-api-with-user")
4953
USER_EMAIL="${6:-test-user@example.com}"
5054
PROFILE_NAMESPACE="${7:-test-profile}"
5155
curl -H "kubeflow-userid: ${USER_EMAIL}" \
5256
"http://localhost:${PORT}/kfam/v1/bindings?namespace=${PROFILE_NAMESPACE}" \
53-
2>/dev/null
57+
2>/dev/null
5458
;;
5559

5660
"performance-test")
@@ -62,7 +66,7 @@ case "$OPERATION" in
6266
;;
6367

6468
"test-metrics")
65-
curl "http://localhost:${PORT}/metrics" 2>/dev/null
69+
curl "http://localhost:${PORT}/metrics" 2>/dev/null
6670
;;
6771

6872
"validate-service")
@@ -94,4 +98,4 @@ case "$OPERATION" in
9498
echo "Valid operations: port-forward, stop-port-forward, test-health, test-dashboard, test-kfam, test-api-with-user, performance-test, test-metrics, validate-service, check-logs, check-errors"
9599
exit 1
96100
;;
97-
esac
101+
esac

0 commit comments

Comments
 (0)