|
| 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 |
0 commit comments