@@ -150,6 +150,7 @@ wait_pod() {
150
150
echo -n .
151
151
let retry+=1
152
152
if [ $retry -ge 360 ]; then
153
+ collect_k8s_logs
153
154
kubectl_bin describe pod/$pod
154
155
kubectl_bin logs $pod
155
156
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
@@ -158,6 +159,7 @@ wait_pod() {
158
159
| grep -v ' Getting tasks for pod' \
159
160
| grep -v ' Getting pods from source' \
160
161
| tail -100
162
+
161
163
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
162
164
exit 1
163
165
fi
@@ -177,12 +179,14 @@ wait_cron() {
177
179
echo -n .
178
180
let retry+=1
179
181
if [ $retry -ge 360 ]; then
182
+ collect_k8s_logs
180
183
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
181
184
| grep -v ' level=info' \
182
185
| grep -v ' level=debug' \
183
186
| grep -v ' Getting tasks for pod' \
184
187
| grep -v ' Getting pods from source' \
185
188
| tail -100
189
+
186
190
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
187
191
exit 1
188
192
fi
@@ -201,8 +205,10 @@ wait_backup_agent() {
201
205
echo -n .
202
206
let retry+=1
203
207
if [ $retry -ge 360 ]; then
208
+ collect_k8s_logs
204
209
kubectl_bin logs $agent_pod -c backup-agent \
205
210
| tail -100
211
+
206
212
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
207
213
exit 1
208
214
fi
@@ -224,12 +230,14 @@ wait_backup() {
224
230
let retry+=1
225
231
current_status=$( kubectl_bin get psmdb-backup $backup_name -o jsonpath=' {.status.state}' )
226
232
if [[ $retry -ge 360 || ${current_status} == ' error' ]]; then
233
+ collect_k8s_logs
227
234
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
228
235
| grep -v ' level=info' \
229
236
| grep -v ' level=debug' \
230
237
| grep -v ' Getting tasks for pod' \
231
238
| grep -v ' Getting pods from source' \
232
239
| tail -100
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
@@ -283,12 +291,14 @@ wait_deployment() {
283
291
echo -n .
284
292
let retry+=1
285
293
if [ $retry -ge 360 ]; then
294
+ collect_k8s_logs
286
295
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
287
296
| grep -v ' level=info' \
288
297
| grep -v ' level=debug' \
289
298
| grep -v ' Getting tasks for pod' \
290
299
| grep -v ' Getting pods from source' \
291
300
| tail -100
301
+
292
302
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
293
303
exit 1
294
304
fi
@@ -329,6 +339,7 @@ wait_restore() {
329
339
let retry+=1
330
340
current_state=$( kubectl_bin get psmdb-restore restore-$backup_name -o jsonpath=' {.status.state}' )
331
341
if [[ $retry -ge $wait_time || ${current_state} == ' error' ]]; then
342
+ collect_k8s_logs
332
343
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
333
344
| grep -v ' level=info' \
334
345
| grep -v ' level=debug' \
@@ -542,6 +553,7 @@ retry() {
542
553
543
554
until " $@ " ; do
544
555
if [[ $n -ge $max ]]; then
556
+ collect_k8s_logs
545
557
echo " The command '$@ ' has failed after $n attempts."
546
558
exit 1
547
559
fi
@@ -581,6 +593,7 @@ wait_for_running() {
581
593
timeout=$(( timeout + 1 ))
582
594
echo -n ' .'
583
595
if [[ ${timeout} -gt 1500 ]]; then
596
+ collect_k8s_logs
584
597
echo
585
598
echo " Waiting timeout has been reached. Exiting..."
586
599
exit 1
@@ -603,12 +616,14 @@ wait_for_delete() {
603
616
echo -n .
604
617
let retry+=1
605
618
if [ $retry -ge $wait_time ]; then
619
+ collect_k8s_logs
606
620
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
607
621
| grep -v ' level=info' \
608
622
| grep -v ' level=debug' \
609
623
| grep -v ' Getting tasks for pod' \
610
624
| grep -v ' Getting pods from source' \
611
625
| tail -100
626
+
612
627
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
613
628
exit 1
614
629
fi
@@ -624,6 +639,8 @@ compare_generation() {
624
639
625
640
current_generation=" $( kubectl_bin get ${resource_type} " ${resource_name} " -o jsonpath=' {.metadata.generation}' ) "
626
641
if [[ ${generation} != " ${current_generation} " ]]; then
642
+ collect_k8s_logs
643
+
627
644
echo " Generation for ${resource_type} /${resource_name} is: ${current_generation} , but should be: ${generation} "
628
645
exit 1
629
646
fi
@@ -984,6 +1001,7 @@ get_service_endpoint() {
984
1001
return
985
1002
fi
986
1003
1004
+ collect_k8s_logs
987
1005
exit 1
988
1006
}
989
1007
@@ -1160,6 +1178,7 @@ wait_cluster_consistency() {
1160
1178
until [[ " $( kubectl_bin get psmdb " ${cluster_name} " -o jsonpath=' {.status.state}' ) " == " ready" ]]; do
1161
1179
let retry+=1
1162
1180
if [ $retry -ge $wait_time ]; then
1181
+ collect_k8s_logs
1163
1182
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
1164
1183
exit 1
1165
1184
fi
@@ -1186,6 +1205,7 @@ check_backup_deletion() {
1186
1205
retry=0
1187
1206
until [[ $( curl -sw ' %{http_code}' -o /dev/null $path ) -eq 403 ]] || [[ $( curl -sw ' %{http_code}' -o /dev/null $path ) -eq 404 ]]; do
1188
1207
if [ $retry -ge 10 ]; then
1208
+ collect_k8s_logs
1189
1209
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
1190
1210
echo " Backup was not removed from bucket -- $storage_name "
1191
1211
exit 1
@@ -1247,6 +1267,7 @@ function get_mongod_ver_from_image() {
1247
1267
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' )
1248
1268
1249
1269
if [[ ! ${version_info} =~ ^([0-9]+\. ){2}[0-9]+-[0-9]+$ ]]; then
1270
+ collect_k8s_logs
1250
1271
printf " No mongod version obtained from %s. Exiting" ${image}
1251
1272
exit 1
1252
1273
fi
@@ -1259,6 +1280,7 @@ function get_pbm_version() {
1259
1280
local version_info=$( run_simple_cli_inside_image ${image} ' pbm-agent version' | $sed -r ' s/^Version:\ (([0-9]+\.){2}[0-9]+)\ .*/\1/g' )
1260
1281
1261
1282
if [[ ! ${version_info} =~ ^([0-9]+\. ){2}[0-9]+$ ]]; then
1283
+ collect_k8s_logs
1262
1284
printf " No pbm version obtained from %s. Exiting" ${image}
1263
1285
exit 1
1264
1286
fi
@@ -1299,6 +1321,31 @@ function generate_vs_json() {
1299
1321
echo ${version_service_source} | jq ' .' > ${target_path}
1300
1322
}
1301
1323
1324
+ collect_k8s_logs () {
1325
+ if [[ ${ENABLE_LOGGING} == " true" ]]; then
1326
+ rm -f ${logs_dir} /logs_${test_name} _* || :
1327
+
1328
+ local check_namespaces=" $namespace ${OPERATOR_NS: + $OPERATOR_NS } "
1329
+
1330
+ for ns in $check_namespaces ; do
1331
+ local pods=$( kubectl_bin get pods -o name | awk -F " /" ' {print $2}' )
1332
+ for p in $pods ; do
1333
+ local containers=$( kubectl_bin -n " $ns " get pod $p -o jsonpath=' {.spec.containers[*].name}' )
1334
+ for c in $containers ; do
1335
+ kubectl_bin -n " $ns " logs $p -c $c > ${logs_dir} /logs_${test_name} _$p_$c .txt
1336
+ echo logs saved in: ${logs_dir} /logs_${test_name} _$p_$c .txt
1337
+ done
1338
+ done
1339
+ done
1340
+ for object in " psmdb psmdb-backup psmdb-restore pods deployments services events sts" ; do
1341
+ echo " ##### START: $object #####" >> ${logs_dir} /logs_${test_name} _simple.txt
1342
+ kubectl_bin get $object --all-namespaces >> ${logs_dir} /logs_${test_name} _simple.txt
1343
+ echo " ##### END: $object ####\n" >> ${logs_dir} /logs_${test_name} _simple.txt
1344
+ kubectl_bin get $object --all-namespaces > ${logs_dir} /logs_${test_name} _$object .yaml
1345
+ done
1346
+ fi
1347
+ }
1348
+
1302
1349
check_passwords_leak () {
1303
1350
local secrets
1304
1351
local passwords
0 commit comments