-
Notifications
You must be signed in to change notification settings - Fork 1
/
trento-support.sh
executable file
·250 lines (207 loc) · 7.57 KB
/
trento-support.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/bin/bash
set -e
readonly ARGS=("$@")
declare -A VALID_FACILITIES=(
["configuration"]="configuration"
["base"]="base"
["kubernetes"]="kubernetes"
["all"]="all"
)
# These two variables can be set from the env as its the
# supportconfig plugin wrapper doesn't allow for arguments
RELEASE_NAME=${TRENTO_CHART_RELEASE_NAME:-"trento-server"}
NAMESPACE=${TRENTO_K8S_NAMESPACE:-"default"}
OUTPUT=/dev/stdout
indent() { sed 's/^/ /'; }
collect_trento_configuration() {
echo "#==[ Configuration File ]===========================#"
echo "# /etc/trento/installer.conf"
echo "$(</etc/trento/installer.conf)"
} &> "$OUTPUT"
collect_base_system() {
if [ "$COLLECT_K3S" != "false" ]; then
echo "#==[ Command ]======================================#"
echo "# k3s --version"
k3s --version
fi
echo "#==[ Command ]======================================#"
echo "# $(which helm) version"
helm version
echo "#==[ Command ]======================================#"
echo "# $(which helm) get hooks $RELEASE_NAME -n $NAMESPACE"
helm get hooks $RELEASE_NAME -n $NAMESPACE
echo "#==[ Command ]======================================#"
echo "# $(which helm) get manifest $RELEASE_NAME -n $NAMESPACE"
helm get manifest $RELEASE_NAME -n $NAMESPACE | yq -n '[inputs]' | jq 'walk(if type == "object" then del(.data."postgresql-password", .data."postgresql-postgres-password", .secretKeyRef, ."admin-user", ."admin-password", ."SMTP_PASSWORD", ."ADMIN_USER", ."ADMIN_PASSWORD", ."SECRET_KEY_BASE", ."ACCESS_TOKEN_ENC_SECRET", ."REFRESH_TOKEN_ENC_SECRET") else . end)'
echo "#==[ Command ]======================================#"
echo "# $(which helm) get notes $RELEASE_NAME -n $NAMESPACE"
helm get notes $RELEASE_NAME -n $NAMESPACE
echo "#==[ Command ]======================================#"
echo "# $(which helm) get values $RELEASE_NAME -n $NAMESPACE"
helm get values $RELEASE_NAME -n $NAMESPACE | yq 'del(."trento-web".adminUser)'
} &> "$OUTPUT"
collect_kubernetes_state() {
echo "#==[ Command ]======================================#"
echo "# $(which kubectl) get nodes -o wide -n $NAMESPACE"
kubectl get nodes -o wide -n $NAMESPACE
echo "#==[ Command ]======================================#"
echo "# $(which kubectl) get pods -n $NAMESPACE"
kubectl get pods -n $NAMESPACE
echo "#==[ Command ]======================================#"
echo "# $(which kubectl) logs deploy/$RELEASE_NAME-wanda -c init -n $NAMESPACE"
kubectl logs deploy/$RELEASE_NAME-wanda -c init -n $NAMESPACE
echo "#==[ Command ]======================================#"
echo "# $(which kubectl) logs deploy/$RELEASE_NAME-wanda -n $NAMESPACE"
kubectl logs deploy/$RELEASE_NAME-wanda -n $NAMESPACE
echo "#==[ Command ]======================================#"
echo "# $(which kubectl) logs deploy/$RELEASE_NAME-web -c init -n $NAMESPACE"
kubectl logs deploy/$RELEASE_NAME-web -c init -n $NAMESPACE
echo "#==[ Command ]======================================#"
echo "# $(which kubectl) logs deploy/$RELEASE_NAME-web -n $NAMESPACE"
kubectl logs deploy/$RELEASE_NAME-web -n $NAMESPACE
echo "#==[ Command ]======================================#"
echo "# $(which kubectl) describe deployments -n $NAMESPACE"
kubectl describe deployments -n $NAMESPACE
if [ "$COLLECT_CRICTL" != "false" ]; then
echo "#==[ Command ]======================================#"
echo "# $(which crictl) images"
crictl images
fi
} &> "$OUTPUT"
collect_all() {
collect_trento_configuration || echo "Error $? during 'configuration' collection"
collect_base_system || echo "Error $? during 'base' collection"
collect_kubernetes_state || echo "Error $? during 'kubernetes' collection"
}
generate_output() {
if [[ " ${arr[*]} " =~ "all" ]]; then
collect_all
else
if [[ " ${arr[*]} " =~ "configuration" ]]; then
collect_trento_configuration
fi
if [[ " ${arr[*]} " =~ "base" ]]; then
collect_base_system
fi
if [[ " ${arr[*]} " =~ "kubernetes" ]]; then
collect_kubernetes_state
fi
fi
if [[ -n "$COMPRESS" ]]; then
echo "COMPRESSING OUTPUT"
tar -czf "$OUTPUT.tar.gz" "$OUTPUT"
rm -f "$OUTPUT"
fi
}
usage() {
cat <<-EOF
Usage: $0 options
Run Trento Server supportconfig script
Options:
-o, --output Output type. Options: stdout|file|file-tgz
-c, --collect Collection options: configuration|base|kubernetes|all
-r, --release-name Release name to use for the chart installation. Default value: "trento-server".
Can also be set with the TRENTO_CHART_RELEASE_NAME environment variable.
-n, --namespace Kubernetes namespace used when installing the chart. Default value: "default".
Can also be set with the TRENTO_K8S_NAMESPACE environment variable.
-h, --help
Example:
$0 --output stdout --collect all
EOF
}
cmdline() {
# abort if we have less than 2 arguments
if [[ $# -lt 2 ]]; then
usage
exit 1
fi
local arg=
for arg; do
local delim=""
case "$arg" in
--help) args="${args}-h " ;;
--output) args="${args}-o " ;;
--collect) args="${args}-c " ;;
--release-name) args="${args}-r " ;;
--namespace) args="${args}-n " ;;
*)
[[ "${arg:0:1}" == "-" ]] || delim="\""
args="${args}${delim}${arg}${delim} "
;;
esac
done
eval set -- "$args"
while getopts "ho:c:r:n:" OPTION; do
case $OPTION in
h)
usage
exit 0
;;
o)
OUTPUT_OPT="${OPTARG}"
if [[ ${OUTPUT_OPT} != "stdout" && ${OUTPUT_OPT} != "file" && ${OUTPUT_OPT} != "file-tgz" ]]; then
echo "Invalid output type: $OUTPUT_OPT"
usage
exit 1
fi
if [ "${OUTPUT_OPT}" = "stdout" ]; then
OUTPUT="/dev/stdout"
elif [ "${OUTPUT_OPT}" = "file-tgz" ]; then
OUTPUT="$(date +%Y-%m-%d_%H%M)_support.txt"
COMPRESS=true
else
OUTPUT="$(date +%Y-%m-%d_%H%M)_support.txt"
fi
;;
c)
COLLECT=$OPTARG
IFS=, read -a arr <<<"${COLLECT}"
for key in "${!arr[@]}"; do
if [[ -z "${VALID_FACILITIES[${arr[$key]}]}" ]]; then
printf '%s: unsupported facility\n' "${arr[$key]}"
usage
exit 1
fi
done
;;
r)
RELEASE_NAME=$OPTARG
;;
n)
NAMESPACE=$OPTARG
;;
*)
usage
exit 0
;;
esac
done
return 0
}
check_deps() {
if ! which jq >/dev/null 2>&1; then
echo "error: jq is required and not installed"
exit 1
fi
if ! which yq >/dev/null 2>&1; then
echo "error: yq is required and not installed"
exit 1
fi
if ! which helm >/dev/null 2>&1; then
echo "error: helm is required and not installed"
exit 1
fi
if ! which kubectl >/dev/null 2>&1; then
echo "error: kubectl is required and not installed"
exit 1
fi
if ! which crictl >/dev/null 2>&1; then
COLLECT_CRICTL=false
fi
if ! which k3s >/dev/null 2>&1; then
COLLECT_K3S=false
fi
}
check_deps
cmdline "${ARGS[@]}"
generate_output