@@ -158,6 +158,8 @@ wait_pod() {
158
158
| grep -v ' Getting tasks for pod' \
159
159
| grep -v ' Getting pods from source' \
160
160
| tail -100
161
+ collect_k8s_logs
162
+
161
163
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
162
164
exit 1
163
165
fi
@@ -183,6 +185,8 @@ wait_cron() {
183
185
| grep -v ' Getting tasks for pod' \
184
186
| grep -v ' Getting pods from source' \
185
187
| tail -100
188
+ collect_k8s_logs
189
+
186
190
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
187
191
exit 1
188
192
fi
@@ -203,6 +207,8 @@ wait_backup_agent() {
203
207
if [ $retry -ge 360 ]; then
204
208
kubectl_bin logs $agent_pod -c backup-agent \
205
209
| tail -100
210
+ collect_k8s_logs
211
+
206
212
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
207
213
exit 1
208
214
fi
@@ -230,6 +236,8 @@ wait_backup() {
230
236
| grep -v ' Getting tasks for pod' \
231
237
| grep -v ' Getting pods from source' \
232
238
| tail -100
239
+ collect_k8s_logs
240
+
233
241
echo " Backup object psmdb-backup/${backup_name} is in ${current_state} state."
234
242
echo something went wrong with operator or kubernetes cluster
235
243
exit 1
@@ -289,6 +297,8 @@ wait_deployment() {
289
297
| grep -v ' Getting tasks for pod' \
290
298
| grep -v ' Getting pods from source' \
291
299
| tail -100
300
+ collect_k8s_logs
301
+
292
302
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
293
303
exit 1
294
304
fi
@@ -334,6 +344,7 @@ wait_restore() {
334
344
| grep -v ' Getting tasks for pod' \
335
345
| grep -v ' Getting pods from source' \
336
346
| tail -100
347
+ collect_k8s_logs
337
348
338
349
echo " Restore object restore-${backup_name} is in ${current_state} state."
339
350
echo something went wrong with operator or kubernetes cluster
@@ -528,6 +539,7 @@ retry() {
528
539
529
540
until " $@ " ; do
530
541
if [[ $n -ge $max ]]; then
542
+ collect_k8s_logs
531
543
echo " The command '$@ ' has failed after $n attempts."
532
544
exit 1
533
545
fi
@@ -567,6 +579,7 @@ wait_for_running() {
567
579
timeout=$(( timeout + 1 ))
568
580
echo -n ' .'
569
581
if [[ ${timeout} -gt 1500 ]]; then
582
+ collect_k8s_logs
570
583
echo
571
584
echo " Waiting timeout has been reached. Exiting..."
572
585
exit 1
@@ -594,6 +607,8 @@ wait_for_delete() {
594
607
| grep -v ' Getting tasks for pod' \
595
608
| grep -v ' Getting pods from source' \
596
609
| tail -100
610
+ collect_k8s_logs
611
+
597
612
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
598
613
exit 1
599
614
fi
@@ -609,6 +624,8 @@ compare_generation() {
609
624
610
625
current_generation=" $( kubectl_bin get ${resource_type} " ${resource_name} " -o jsonpath=' {.metadata.generation}' ) "
611
626
if [[ ${generation} != " ${current_generation} " ]]; then
627
+ collect_k8s_logs
628
+
612
629
echo " Generation for ${resource_type} /${resource_name} is: ${current_generation} , but should be: ${generation} "
613
630
exit 1
614
631
fi
@@ -961,6 +978,7 @@ get_service_endpoint() {
961
978
return
962
979
fi
963
980
981
+ collect_k8s_logs
964
982
exit 1
965
983
}
966
984
@@ -1135,6 +1153,7 @@ wait_cluster_consistency() {
1135
1153
until [[ " $( kubectl_bin get psmdb " ${cluster_name} " -o jsonpath=' {.status.state}' ) " == " ready" ]]; do
1136
1154
let retry+=1
1137
1155
if [ $retry -ge 32 ]; then
1156
+ collect_k8s_logs
1138
1157
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
1139
1158
exit 1
1140
1159
fi
@@ -1161,6 +1180,7 @@ check_backup_deletion() {
1161
1180
retry=0
1162
1181
until [[ $( curl -sw ' %{http_code}' -o /dev/null $path ) -eq 403 ]] || [[ $( curl -sw ' %{http_code}' -o /dev/null $path ) -eq 404 ]]; do
1163
1182
if [ $retry -ge 10 ]; then
1183
+ collect_k8s_logs
1164
1184
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
1165
1185
echo " Backup was not removed from bucket -- $storage_name "
1166
1186
exit 1
@@ -1222,6 +1242,7 @@ function get_mongod_ver_from_image() {
1222
1242
version_info=$( run_simple_cli_inside_image ${image} ' mongod --version' | $sed -r ' s/^.*db version v(([0-9]+\.){2}[0-9]+-[0-9]+).*$/\1/g' )
1223
1243
1224
1244
if [[ ! ${version_info} =~ ^([0-9]+\. ){2}[0-9]+-[0-9]+$ ]]; then
1245
+ collect_k8s_logs
1225
1246
printf " No mongod version obtained from %s. Exiting" ${image}
1226
1247
exit 1
1227
1248
fi
@@ -1234,6 +1255,7 @@ function get_pbm_version() {
1234
1255
local version_info=$( run_simple_cli_inside_image ${image} ' pbm-agent version' | $sed -r ' s/^Version:\ (([0-9]+\.){2}[0-9]+)\ .*/\1/g' )
1235
1256
1236
1257
if [[ ! ${version_info} =~ ^([0-9]+\. ){2}[0-9]+$ ]]; then
1258
+ collect_k8s_logs
1237
1259
printf " No pbm version obtained from %s. Exiting" ${image}
1238
1260
exit 1
1239
1261
fi
@@ -1274,6 +1296,24 @@ function generate_vs_json() {
1274
1296
echo ${version_service_source} | jq ' .' > ${target_path}
1275
1297
}
1276
1298
1299
+ collect_k8s_logs () {
1300
+ local check_namespaces=" $namespace ${OPERATOR_NS: + $OPERATOR_NS } "
1301
+
1302
+ for ns in $check_namespaces ; do
1303
+ local pods=$( kubectl_bin get pods -o name | awk -F " /" ' {print $2}' )
1304
+ for p in $pods ; do
1305
+ local containers=$( kubectl_bin -n " $ns " get pod $p -o jsonpath=' {.spec.containers[*].name}' )
1306
+ for c in $containers ; do
1307
+ kubectl_bin -n " $ns " logs $p -c $c > ${logs_dir} /logs_${test_name} _$p_$c .txt
1308
+ echo logs saved in: ${logs_dir} /logs_${test_name} _$p_$c .txt
1309
+ done
1310
+ done
1311
+ done
1312
+ kubectl_bin get pods --all-namespaces > ${logs_dir} /logs_${test_name} _pods.txt
1313
+ kubectl_bin get services --all-namespaces > ${logs_dir} /logs_${test_name} _services.txt
1314
+ kubectl_bin get events --all-namespaces > ${logs_dir} /logs_${test_name} _k8s_events.txt
1315
+ }
1316
+
1277
1317
check_passwords_leak () {
1278
1318
secrets=$( kubectl_bin get secrets -o json | jq -r ' .items[].data | to_entries | .[] | select(.key | (contains("_PASSWORD"))) | .value' )
1279
1319
echo secrets=$secrets
0 commit comments