-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus-k8s.sh
More file actions
executable file
·225 lines (202 loc) · 6.63 KB
/
status-k8s.sh
File metadata and controls
executable file
·225 lines (202 loc) · 6.63 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
# 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 " -d, --detailed Show detailed resource information"
echo " -p, --pods Show only pod status"
echo " -s, --services Show only service status"
echo " -i, --ingress Show only ingress status"
echo " -f, --fast Fast mode (skip minikube checks)"
echo " -c, --config Show configuration"
echo ""
echo "Examples:"
echo " $0 # Show basic status"
echo " $0 --detailed # Show detailed information"
echo " $0 --pods # Show only pod status"
echo " $0 --fast # Fast mode (port forwarding only)"
echo " $0 --config # Show configuration"
echo " $0 --help # Show this help message"
}
# Parse command line arguments
DETAILED=false
SHOW_PODS=false
SHOW_SERVICES=false
SHOW_INGRESS=false
FAST_MODE=false
SHOW_CONFIG=false
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_usage
exit 0
;;
-d|--detailed)
DETAILED=true
shift
;;
-p|--pods)
SHOW_PODS=true
shift
;;
-s|--services)
SHOW_SERVICES=true
shift
;;
-i|--ingress)
SHOW_INGRESS=true
shift
;;
-f|--fast)
FAST_MODE=true
shift
;;
-c|--config)
SHOW_CONFIG=true
shift
;;
-*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
*)
print_error "Unknown argument: $1"
show_usage
exit 1
;;
esac
done
# Show configuration if requested
if [ "$SHOW_CONFIG" = true ]; then
print_config
exit 0
fi
show_script_header "Kubernetes Status" "Checking Apollo Supergraph resources in minikube"
# Check if minikube is running (skip in fast mode)
if [ "$FAST_MODE" = false ]; then
print_status "Checking minikube status..."
if minikube_is_running; then
print_success "Minikube is running"
MINIKUBE_IP=$(get_minikube_ip)
print_status "Minikube IP: $MINIKUBE_IP"
else
print_error "Minikube is not running. Please start minikube first:"
echo " minikube start"
echo " or run: ./setup-minikube.sh"
echo ""
echo "🌐 Access URLs (if services are running locally):"
echo " Router GraphQL: $(get_router_graphql_url)"
echo " Router Health: $(get_router_health_url)"
echo " Subgraphs: $(get_subgraphs_url)"
echo ""
show_script_footer "Kubernetes Status"
exit 0
fi
# Check if namespace exists
NAMESPACE=$(get_k8s_namespace)
print_status "Checking namespace..."
if namespace_exists "$NAMESPACE"; then
print_success "Namespace '$NAMESPACE' exists"
else
print_warning "Namespace '$NAMESPACE' does not exist"
echo " Run: ./run-k8s.sh to deploy the supergraph"
echo ""
echo "🌐 Access URLs (if services are running locally):"
echo " Router GraphQL: $(get_router_graphql_url)"
echo " Router Health: $(get_router_health_url)"
echo " Subgraphs: $(get_subgraphs_url)"
echo ""
show_script_footer "Kubernetes Status"
exit 0
fi
echo ""
fi
# Show pod status
if [ "$SHOW_PODS" = true ] || [ "$FAST_MODE" = false ]; then
print_status "Pod Status:"
echo ""
run_with_timeout 10 kubectl get pods -n "$NAMESPACE" || echo "No pods found or timeout"
echo ""
fi
# Show service status
if [ "$SHOW_SERVICES" = true ] || [ "$FAST_MODE" = false ]; then
print_status "Service Status:"
echo ""
run_with_timeout 10 kubectl get services -n "$NAMESPACE" || echo "No services found or timeout"
echo ""
fi
# Show deployment status
if [ "$FAST_MODE" = false ]; then
print_status "Deployment Status:"
echo ""
run_with_timeout 10 kubectl get deployments -n "$NAMESPACE" || echo "No deployments found or timeout"
echo ""
fi
# Show ingress status
if [ "$SHOW_INGRESS" = true ] || [ "$FAST_MODE" = false ]; then
print_status "Ingress Status:"
echo ""
run_with_timeout 10 kubectl get ingress -n "$NAMESPACE" || echo "No ingress found or timeout"
echo ""
fi
# Show port forwarding status (always show this)
print_status "Port Forwarding Status:"
echo ""
if is_port_forwarded "$ROUTER_GRAPHQL_PORT"; then
print_success "Port $ROUTER_GRAPHQL_PORT is being forwarded (router)"
else
print_warning "Port $ROUTER_GRAPHQL_PORT is not being forwarded"
fi
if is_port_forwarded "$SUBGRAPHS_PORT"; then
print_success "Port $SUBGRAPHS_PORT is being forwarded (subgraphs)"
else
print_warning "Port $SUBGRAPHS_PORT is not being forwarded"
fi
echo ""
# Show access URLs
print_status "Access URLs:"
echo ""
echo " Router GraphQL: $(get_router_graphql_url)"
echo " Router Health: $(get_router_health_url)"
echo " Subgraphs: $(get_subgraphs_url)"
echo " Minikube Dashboard: minikube dashboard"
echo ""
# Show detailed information if requested
if [ "$DETAILED" = true ] && [ "$FAST_MODE" = false ]; then
print_status "Detailed Information:"
echo ""
# Show recent events
print_status "Recent Events:"
run_with_timeout 5 kubectl get events -n "$NAMESPACE" --sort-by='.lastTimestamp' | tail -5 || echo "Events not available"
echo ""
# Show resource usage (if metrics server available)
print_status "Resource Usage:"
run_with_timeout 5 kubectl top pods -n "$NAMESPACE" || echo "Metrics server not available"
echo ""
fi
# Show manual commands
if [ "$FAST_MODE" = false ]; then
print_status "Manual Status Commands:"
echo " - Check minikube: minikube status"
echo " - View pods: kubectl get pods -n $NAMESPACE"
echo " - View services: kubectl get svc -n $NAMESPACE"
echo " - View deployments: kubectl get deployments -n $NAMESPACE"
echo " - Test router: ./test-router.sh"
echo ""
fi
show_script_footer "Kubernetes Status"