-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-k8s.sh
More file actions
executable file
·164 lines (139 loc) · 4.58 KB
/
test-k8s.sh
File metadata and controls
executable file
·164 lines (139 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
set -e
# Source shared utilities
if [ -z "$SCRIPT_DIR" ]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi
# If SCRIPT_DIR is the root directory, we need to source from scripts subdirectory
if [ "$(basename "$SCRIPT_DIR")" = "scripts" ]; then
source "$SCRIPT_DIR/utils.sh"
source "$SCRIPT_DIR/config.sh"
else
source "$SCRIPT_DIR/scripts/utils.sh"
source "$SCRIPT_DIR/scripts/config.sh"
fi
# Function to show usage
show_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Test Apollo Supergraph deployment"
echo " $0 --help # Show this help message"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_usage
exit 0
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
show_script_header "Apollo Supergraph Kubernetes Testing" "Testing Apollo Supergraph deployment in minikube"
# Get namespace
NAMESPACE=$(get_k8s_namespace)
# Check if namespace exists
if ! namespace_exists "$NAMESPACE"; then
print_error "Namespace $NAMESPACE does not exist. Please deploy first:"
echo " ./run-k8s.sh"
exit 1
fi
# Check if pods are running
print_status "Checking pod status in namespace: $NAMESPACE..."
PODS=$(kubectl get pods -n $NAMESPACE -o jsonpath='{.items[*].status.phase}')
RUNNING_PODS=$(echo $PODS | grep -o "Running" | wc -l)
TOTAL_PODS=$(echo $PODS | wc -w)
if [ "$RUNNING_PODS" -eq "$TOTAL_PODS" ]; then
print_success "All $TOTAL_PODS pods are running"
else
print_error "Only $RUNNING_PODS/$TOTAL_PODS pods are running"
kubectl get pods -n $NAMESPACE
exit 1
fi
# Check if services are ready
print_status "Checking service status..."
kubectl get svc -n $NAMESPACE
# Source port forwarding utilities
source "$SCRIPT_DIR/scripts/port-forward-utils.sh"
# Test subgraphs
print_status "Testing subgraphs health..."
# Start subgraphs port forwarding
if start_subgraphs_port_forward; then
if curl -s "$(get_subgraphs_products_url)" > /dev/null; then
print_success "Subgraphs are responding"
else
print_error "Subgraphs are not responding"
stop_port_forward "subgraphs"
exit 1
fi
# Test GraphQL query to subgraphs
print_status "Testing GraphQL query to subgraphs..."
RESPONSE=$(curl -s -X POST "$(get_subgraphs_products_url)" \
-H "Content-Type: application/json" \
-d '{"query":"{ searchProducts { id title price } }"}')
# Stop subgraphs port forwarding
stop_port_forward "subgraphs"
else
print_error "Failed to start subgraphs port forwarding"
exit 1
fi
if echo "$RESPONSE" | grep -q "data"; then
print_success "GraphQL query to subgraphs successful"
echo "Response: $RESPONSE" | head -c 200
echo "..."
else
print_error "GraphQL query to subgraphs failed"
echo "Response: $RESPONSE"
exit 1
fi
# Source test utilities for router testing
source "$SCRIPT_DIR/scripts/test-utils.sh"
# Test router
print_status "Testing router health..."
# Start router port forwarding
if start_router_port_forward; then
if test_router_health > /dev/null 2>&1; then
print_success "Router is responding"
else
print_error "Router is not responding"
stop_port_forward "apollo-router"
exit 1
fi
# Test GraphQL query to router
print_status "Testing GraphQL query to router..."
if test_search_products > /dev/null 2>&1; then
print_success "GraphQL query to router successful"
else
print_error "GraphQL query to router failed"
stop_port_forward "apollo-router"
exit 1
fi
# Stop router port forwarding
stop_port_forward "apollo-router"
else
print_error "Failed to start router port forwarding"
exit 1
fi
print_success "All tests passed! 🎉"
echo ""
echo "📋 Test Summary:"
echo " - Namespace: $NAMESPACE"
echo " ✅ All pods are running"
echo " ✅ Services are configured"
echo " ✅ Subgraphs are responding"
echo " ✅ GraphQL queries to subgraphs work"
echo " ✅ Router is responding"
echo " ✅ GraphQL queries to router work"
echo ""
echo "🌐 Your deployment is ready!"
echo " - Router: kubectl port-forward svc/$(get_router_service_name) $ROUTER_GRAPHQL_PORT:$ROUTER_GRAPHQL_PORT -n $NAMESPACE"
echo " - Subgraphs: kubectl port-forward svc/$(get_subgraphs_service_name) $SUBGRAPHS_PORT:$SUBGRAPHS_PORT -n $NAMESPACE"
show_script_footer "Kubernetes Testing"