-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
debug.sh
executable file
·72 lines (53 loc) · 3.27 KB
/
debug.sh
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
#!/bin/bash
source setup-env.sh "$@"
namespace="5stack"
debug_file="debug_output_$(date +%Y%m%d_%H%M%S).txt"
echo "Checking pod status and restarts in namespace $namespace..." | tee -a "$debug_file"
echo "---------------------------------------" | tee -a "$debug_file"
# Get all pods in the namespace
kubectl --kubeconfig=$KUBECONFIG get pods -n "$namespace" --no-headers | while read -r pod; do
pod_name=$(echo "$pod" | awk '{print $1}')
restarts=$(echo "$pod" | awk '{print $4}')
echo "Pod: $pod_name" | tee -a "$debug_file"
echo "Total restarts: $restarts" | tee -a "$debug_file"
if [ "$restarts" -gt 0 ]; then
echo "Last restart reason:" | tee -a "$debug_file"
kubectl --kubeconfig=$KUBECONFIG get pod "$pod_name" -n "$namespace" -o jsonpath='{.status.containerStatuses[0].lastState.terminated.reason}' | tee -a "$debug_file"
echo -e "\n" | tee -a "$debug_file"
kubectl --kubeconfig=$KUBECONFIG logs "$pod_name" -n "$namespace" --tail=100 | tee -a "$debug_file"
fi
echo "---------------------------------------" | tee -a "$debug_file"
done
echo "Checking certificates in namespace $namespace..." | tee -a "$debug_file"
echo "---------------------------------------" | tee -a "$debug_file"
# Loop through all certificates in all namespaces
for cert in $(kubectl --kubeconfig=$KUBECONFIG get certificates -A -o custom-columns=NAME:.metadata.name --no-headers | awk '{print $1}'); do
name=$(echo "$cert" | cut -d'/' -f2)
# Get the Ready condition status for the certificate
status=$(kubectl --kubeconfig=$KUBECONFIG get certificate "$name" -n "$namespace" -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}')
# If the certificate is valid, skip to the next
if [[ "$status" == "True" ]]; then
echo "Certificate $name in namespace $namespace is valid." | tee -a "$debug_file"
else
echo "Certificate $name in namespace $namespace is not valid. Fetching details..." | tee -a "$debug_file"
# Get details of the certificate
kubectl --kubeconfig=$KUBECONFIG describe certificate "$name" -n "$namespace" | tee -a "$debug_file"
# Find associated challenges for this certificate
echo "Checking challenges for certificate $name..." | tee -a "$debug_file"
# Get all challenges in the same namespace and filter by the certificate name
kubectl --kubeconfig=$KUBECONFIG get challenges -n "$namespace" --no-headers | grep "$name" | while read -r challenge; do
challenge_name=$(echo "$challenge" | awk '{print $1}')
# Check if the challenge is valid
challenge_status=$(kubectl --kubeconfig=$KUBECONFIG get challenge "$challenge_name" -n "$namespace" -o jsonpath='{.status.state}')
# Only fetch details if the challenge is not valid
if [[ "$challenge_status" != "valid" ]]; then
echo "Challenge $challenge_name for certificate $name is not valid. Fetching details..." | tee -a "$debug_file"
kubectl --kubeconfig=$KUBECONFIG describe challenge "$challenge_name" -n "$namespace" | tee -a "$debug_file"
else
echo "Challenge $challenge_name for certificate $name is valid." | tee -a "$debug_file"
fi
done
fi
echo "---------------------------------------" | tee -a "$debug_file"
done
echo -e "\033[32mDebug log saved to: $debug_file\033[0m"