@@ -149,6 +149,7 @@ wait_pod() {
149
149
echo -n .
150
150
let retry+=1
151
151
if [ $retry -ge 360 ]; then
152
+ collect_k8s_logs
152
153
kubectl_bin describe pod/$pod
153
154
kubectl_bin logs $pod
154
155
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
@@ -157,6 +158,7 @@ wait_pod() {
157
158
| grep -v ' Getting tasks for pod' \
158
159
| grep -v ' Getting pods from source' \
159
160
| tail -100
161
+
160
162
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
161
163
exit 1
162
164
fi
@@ -176,12 +178,14 @@ wait_cron() {
176
178
echo -n .
177
179
let retry+=1
178
180
if [ $retry -ge 360 ]; then
181
+ collect_k8s_logs
179
182
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
180
183
| grep -v ' level=info' \
181
184
| grep -v ' level=debug' \
182
185
| grep -v ' Getting tasks for pod' \
183
186
| grep -v ' Getting pods from source' \
184
187
| tail -100
188
+
185
189
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
186
190
exit 1
187
191
fi
@@ -200,8 +204,10 @@ wait_backup_agent() {
200
204
echo -n .
201
205
let retry+=1
202
206
if [ $retry -ge 360 ]; then
207
+ collect_k8s_logs
203
208
kubectl_bin logs $agent_pod -c backup-agent \
204
209
| tail -100
210
+
205
211
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
206
212
exit 1
207
213
fi
@@ -223,12 +229,14 @@ wait_backup() {
223
229
let retry+=1
224
230
current_status=$( kubectl_bin get psmdb-backup $backup_name -o jsonpath=' {.status.state}' )
225
231
if [[ $retry -ge 360 || ${current_status} == ' error' ]]; then
232
+ collect_k8s_logs
226
233
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
227
234
| grep -v ' level=info' \
228
235
| grep -v ' level=debug' \
229
236
| grep -v ' Getting tasks for pod' \
230
237
| grep -v ' Getting pods from source' \
231
238
| tail -100
239
+
232
240
echo " Backup object psmdb-backup/${backup_name} is in ${current_state} state."
233
241
echo something went wrong with operator or kubernetes cluster
234
242
exit 1
@@ -282,12 +290,14 @@ wait_deployment() {
282
290
echo -n .
283
291
let retry+=1
284
292
if [ $retry -ge 360 ]; then
293
+ collect_k8s_logs
285
294
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
286
295
| grep -v ' level=info' \
287
296
| grep -v ' level=debug' \
288
297
| grep -v ' Getting tasks for pod' \
289
298
| grep -v ' Getting pods from source' \
290
299
| tail -100
300
+
291
301
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
292
302
exit 1
293
303
fi
@@ -328,6 +338,7 @@ wait_restore() {
328
338
let retry+=1
329
339
current_state=$( kubectl_bin get psmdb-restore restore-$backup_name -o jsonpath=' {.status.state}' )
330
340
if [[ $retry -ge $wait_time || ${current_state} == ' error' ]]; then
341
+ collect_k8s_logs
331
342
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
332
343
| grep -v ' level=info' \
333
344
| grep -v ' level=debug' \
@@ -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
@@ -589,12 +602,14 @@ wait_for_delete() {
589
602
echo -n .
590
603
let retry+=1
591
604
if [ $retry -ge $wait_time ]; then
605
+ collect_k8s_logs
592
606
kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
593
607
| grep -v ' level=info' \
594
608
| grep -v ' level=debug' \
595
609
| grep -v ' Getting tasks for pod' \
596
610
| grep -v ' Getting pods from source' \
597
611
| tail -100
612
+
598
613
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
599
614
exit 1
600
615
fi
@@ -610,6 +625,8 @@ compare_generation() {
610
625
611
626
current_generation=" $( kubectl_bin get ${resource_type} " ${resource_name} " -o jsonpath=' {.metadata.generation}' ) "
612
627
if [[ ${generation} != " ${current_generation} " ]]; then
628
+ collect_k8s_logs
629
+
613
630
echo " Generation for ${resource_type} /${resource_name} is: ${current_generation} , but should be: ${generation} "
614
631
exit 1
615
632
fi
@@ -962,6 +979,7 @@ get_service_endpoint() {
962
979
return
963
980
fi
964
981
982
+ collect_k8s_logs
965
983
exit 1
966
984
}
967
985
@@ -1137,6 +1155,7 @@ wait_cluster_consistency() {
1137
1155
until [[ " $( kubectl_bin get psmdb " ${cluster_name} " -o jsonpath=' {.status.state}' ) " == " ready" ]]; do
1138
1156
let retry+=1
1139
1157
if [ $retry -ge $wait_time ]; then
1158
+ collect_k8s_logs
1140
1159
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
1141
1160
exit 1
1142
1161
fi
@@ -1163,6 +1182,7 @@ check_backup_deletion() {
1163
1182
retry=0
1164
1183
until [[ $( curl -sw ' %{http_code}' -o /dev/null $path ) -eq 403 ]] || [[ $( curl -sw ' %{http_code}' -o /dev/null $path ) -eq 404 ]]; do
1165
1184
if [ $retry -ge 10 ]; then
1185
+ collect_k8s_logs
1166
1186
echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
1167
1187
echo " Backup was not removed from bucket -- $storage_name "
1168
1188
exit 1
@@ -1224,6 +1244,7 @@ function get_mongod_ver_from_image() {
1224
1244
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' )
1225
1245
1226
1246
if [[ ! ${version_info} =~ ^([0-9]+\. ){2}[0-9]+-[0-9]+$ ]]; then
1247
+ collect_k8s_logs
1227
1248
printf " No mongod version obtained from %s. Exiting" ${image}
1228
1249
exit 1
1229
1250
fi
@@ -1236,6 +1257,7 @@ function get_pbm_version() {
1236
1257
local version_info=$( run_simple_cli_inside_image ${image} ' pbm-agent version' | $sed -r ' s/^Version:\ (([0-9]+\.){2}[0-9]+)\ .*/\1/g' )
1237
1258
1238
1259
if [[ ! ${version_info} =~ ^([0-9]+\. ){2}[0-9]+$ ]]; then
1260
+ collect_k8s_logs
1239
1261
printf " No pbm version obtained from %s. Exiting" ${image}
1240
1262
exit 1
1241
1263
fi
@@ -1276,6 +1298,31 @@ function generate_vs_json() {
1276
1298
echo ${version_service_source} | jq ' .' > ${target_path}
1277
1299
}
1278
1300
1301
+ collect_k8s_logs () {
1302
+ if [[ ${ENABLE_LOGGING} == " true" ]]; then
1303
+ rm -f ${logs_dir} /logs_${test_name} _* || :
1304
+
1305
+ local check_namespaces=" $namespace ${OPERATOR_NS: + $OPERATOR_NS } "
1306
+
1307
+ for ns in $check_namespaces ; do
1308
+ local pods=$( kubectl_bin get pods -o name | awk -F " /" ' {print $2}' )
1309
+ for p in $pods ; do
1310
+ local containers=$( kubectl_bin -n " $ns " get pod $p -o jsonpath=' {.spec.containers[*].name}' )
1311
+ for c in $containers ; do
1312
+ kubectl_bin -n " $ns " logs $p -c $c > ${logs_dir} /logs_${test_name} _$p_$c .txt
1313
+ echo logs saved in: ${logs_dir} /logs_${test_name} _$p_$c .txt
1314
+ done
1315
+ done
1316
+ done
1317
+ for object in " psmdb psmdb-backup psmdb-restore pods deployments services events sts" ; do
1318
+ echo " ##### START: $object #####" >> ${logs_dir} /logs_${test_name} _simple.txt
1319
+ kubectl_bin get $object --all-namespaces >> ${logs_dir} /logs_${test_name} _simple.txt
1320
+ echo " ##### END: $object ####\n" >> ${logs_dir} /logs_${test_name} _simple.txt
1321
+ kubectl_bin get $object --all-namespaces > ${logs_dir} /logs_${test_name} _$object .yaml
1322
+ done
1323
+ fi
1324
+ }
1325
+
1279
1326
check_passwords_leak () {
1280
1327
local secrets
1281
1328
local passwords
0 commit comments