@@ -158,6 +158,8 @@ wait_pod() {
158158 | grep -v ' Getting tasks for pod' \
159159 | grep -v ' Getting pods from source' \
160160 | tail -100
161+ collect_k8s_logs
162+
161163 echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
162164 exit 1
163165 fi
@@ -183,6 +185,8 @@ wait_cron() {
183185 | grep -v ' Getting tasks for pod' \
184186 | grep -v ' Getting pods from source' \
185187 | tail -100
188+ collect_k8s_logs
189+
186190 echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
187191 exit 1
188192 fi
@@ -203,6 +207,8 @@ wait_backup_agent() {
203207 if [ $retry -ge 360 ]; then
204208 kubectl_bin logs $agent_pod -c backup-agent \
205209 | tail -100
210+ collect_k8s_logs
211+
206212 echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
207213 exit 1
208214 fi
@@ -230,6 +236,8 @@ wait_backup() {
230236 | grep -v ' Getting tasks for pod' \
231237 | grep -v ' Getting pods from source' \
232238 | tail -100
239+ collect_k8s_logs
240+
233241 echo " Backup object psmdb-backup/${backup_name} is in ${current_state} state."
234242 echo something went wrong with operator or kubernetes cluster
235243 exit 1
@@ -289,6 +297,8 @@ wait_deployment() {
289297 | grep -v ' Getting tasks for pod' \
290298 | grep -v ' Getting pods from source' \
291299 | tail -100
300+ collect_k8s_logs
301+
292302 echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
293303 exit 1
294304 fi
@@ -334,6 +344,7 @@ wait_restore() {
334344 | grep -v ' Getting tasks for pod' \
335345 | grep -v ' Getting pods from source' \
336346 | tail -100
347+ collect_k8s_logs
337348
338349 echo " Restore object restore-${backup_name} is in ${current_state} state."
339350 echo something went wrong with operator or kubernetes cluster
@@ -528,6 +539,7 @@ retry() {
528539
529540 until " $@ " ; do
530541 if [[ $n -ge $max ]]; then
542+ collect_k8s_logs
531543 echo " The command '$@ ' has failed after $n attempts."
532544 exit 1
533545 fi
@@ -567,6 +579,7 @@ wait_for_running() {
567579 timeout=$(( timeout + 1 ))
568580 echo -n ' .'
569581 if [[ ${timeout} -gt 1500 ]]; then
582+ collect_k8s_logs
570583 echo
571584 echo " Waiting timeout has been reached. Exiting..."
572585 exit 1
@@ -594,6 +607,8 @@ wait_for_delete() {
594607 | grep -v ' Getting tasks for pod' \
595608 | grep -v ' Getting pods from source' \
596609 | tail -100
610+ collect_k8s_logs
611+
597612 echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
598613 exit 1
599614 fi
@@ -609,6 +624,8 @@ compare_generation() {
609624
610625 current_generation=" $( kubectl_bin get ${resource_type} " ${resource_name} " -o jsonpath=' {.metadata.generation}' ) "
611626 if [[ ${generation} != " ${current_generation} " ]]; then
627+ collect_k8s_logs
628+
612629 echo " Generation for ${resource_type} /${resource_name} is: ${current_generation} , but should be: ${generation} "
613630 exit 1
614631 fi
@@ -961,6 +978,7 @@ get_service_endpoint() {
961978 return
962979 fi
963980
981+ collect_k8s_logs
964982 exit 1
965983}
966984
@@ -1135,6 +1153,7 @@ wait_cluster_consistency() {
11351153 until [[ " $( kubectl_bin get psmdb " ${cluster_name} " -o jsonpath=' {.status.state}' ) " == " ready" ]]; do
11361154 let retry+=1
11371155 if [ $retry -ge 32 ]; then
1156+ collect_k8s_logs
11381157 echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
11391158 exit 1
11401159 fi
@@ -1161,6 +1180,7 @@ check_backup_deletion() {
11611180 retry=0
11621181 until [[ $( curl -sw ' %{http_code}' -o /dev/null $path ) -eq 403 ]] || [[ $( curl -sw ' %{http_code}' -o /dev/null $path ) -eq 404 ]]; do
11631182 if [ $retry -ge 10 ]; then
1183+ collect_k8s_logs
11641184 echo max retry count $retry reached. something went wrong with operator or kubernetes cluster
11651185 echo " Backup was not removed from bucket -- $storage_name "
11661186 exit 1
@@ -1222,6 +1242,7 @@ function get_mongod_ver_from_image() {
12221242 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' )
12231243
12241244 if [[ ! ${version_info} =~ ^([0-9]+\. ){2}[0-9]+-[0-9]+$ ]]; then
1245+ collect_k8s_logs
12251246 printf " No mongod version obtained from %s. Exiting" ${image}
12261247 exit 1
12271248 fi
@@ -1234,6 +1255,7 @@ function get_pbm_version() {
12341255 local version_info=$( run_simple_cli_inside_image ${image} ' pbm-agent version' | $sed -r ' s/^Version:\ (([0-9]+\.){2}[0-9]+)\ .*/\1/g' )
12351256
12361257 if [[ ! ${version_info} =~ ^([0-9]+\. ){2}[0-9]+$ ]]; then
1258+ collect_k8s_logs
12371259 printf " No pbm version obtained from %s. Exiting" ${image}
12381260 exit 1
12391261 fi
@@ -1274,6 +1296,28 @@ function generate_vs_json() {
12741296 echo ${version_service_source} | jq ' .' > ${target_path}
12751297}
12761298
1299+ collect_k8s_logs () {
1300+ if [[ ${ENABLE_LOGGING} == " true" ]]; then
1301+ rm -f ${logs_dir} /logs_${test_name} _* .txt || :
1302+
1303+ local check_namespaces=" $namespace ${OPERATOR_NS: + $OPERATOR_NS } "
1304+
1305+ for ns in $check_namespaces ; do
1306+ local pods=$( kubectl_bin get pods -o name | awk -F " /" ' {print $2}' )
1307+ for p in $pods ; do
1308+ local containers=$( kubectl_bin -n " $ns " get pod $p -o jsonpath=' {.spec.containers[*].name}' )
1309+ for c in $containers ; do
1310+ kubectl_bin -n " $ns " logs $p -c $c > ${logs_dir} /logs_${test_name} _$p_$c .txt
1311+ echo logs saved in: ${logs_dir} /logs_${test_name} _$p_$c .txt
1312+ done
1313+ done
1314+ done
1315+ kubectl_bin get pods --all-namespaces > ${logs_dir} /logs_${test_name} _pods.txt
1316+ kubectl_bin get services --all-namespaces > ${logs_dir} /logs_${test_name} _services.txt
1317+ kubectl_bin get events --all-namespaces > ${logs_dir} /logs_${test_name} _k8s_events.txt
1318+ fi
1319+ }
1320+
12771321check_passwords_leak () {
12781322 secrets=$( kubectl_bin get secrets -o json | jq -r ' .items[].data | to_entries | .[] | select(.key | (contains("_PASSWORD"))) | .value' )
12791323 echo secrets=$secrets
0 commit comments