From dc6b1c6f2e65fbc2ded69c10a8131d78cd98b00f Mon Sep 17 00:00:00 2001 From: Tomislav Plavcic Date: Fri, 20 Oct 2023 09:46:26 +0200 Subject: [PATCH] functions - fix run_mongo and run_mongos for collecting k8s logs --- e2e-tests/functions | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/e2e-tests/functions b/e2e-tests/functions index 5c0b3844fe..cd40746ce9 100755 --- a/e2e-tests/functions +++ b/e2e-tests/functions @@ -705,11 +705,15 @@ run_mongo() { local suffix=${4:-.svc.cluster.local} local client_container=$(kubectl_bin get pods --selector=name=psmdb-client -o 'jsonpath={.items[].metadata.name}') local mongo_flag="$5" - local replica_set=$(echo "$uri" | sed -r 's/.*\-(rs[0-9]|cfg)(\.|-).*/\1/') - - kubectl_bin exec ${client_container} -- \ - bash -c "printf '$command\n' | mongo $driver://$uri$suffix/admin?ssl=false\&replicaSet=$replica_set $mongo_flag" + local replica_set=$(echo "$uri" | grep -oE '\-(rs[0-9]|cfg)(\.|-)' | sed 's/^.//;s/.$//' | head -n1) + if [[ ${FUNCNAME[1]} == "collect_k8s_logs" ]]; then + kubectl exec ${client_container} -- \ + bash -c "printf '$command\n' | mongo $driver://$uri$suffix/admin?ssl=false\&replicaSet=$replica_set $mongo_flag" + else + kubectl_bin exec ${client_container} -- \ + bash -c "printf '$command\n' | mongo $driver://$uri$suffix/admin?ssl=false\&replicaSet=$replica_set $mongo_flag" + fi } run_mongo_tls() { @@ -719,11 +723,15 @@ run_mongo_tls() { local suffix=${4:-.svc.cluster.local} local client_container=$(kubectl_bin get pods --selector=name=psmdb-client -o 'jsonpath={.items[].metadata.name}') local mongo_flag="$5" - local replica_set=$(echo "$uri" | sed -r 's/.*\-(rs[0-9]|cfg)(\.|-).*/\1/') - - kubectl_bin exec ${client_container} -- \ - bash -c "printf '$command\n' | mongo $driver://$uri$suffix/admin?replicaSet=$replica_set --tls --tlsCAFile /etc/mongodb-ssl/ca.crt --tlsCertificateKeyFile /tmp/tls.pem --tlsAllowInvalidHostnames $mongo_flag" + local replica_set=$(echo "$uri" | grep -oE '\-(rs[0-9]|cfg)(\.|-)' | sed 's/^.//;s/.$//' | head -n1) + if [[ ${FUNCNAME[1]} == "collect_k8s_logs" ]]; then + kubectl exec ${client_container} -- \ + bash -c "printf '$command\n' | mongo $driver://$uri$suffix/admin?replicaSet=$replica_set --tls --tlsCAFile /etc/mongodb-ssl/ca.crt --tlsCertificateKeyFile /tmp/tls.pem --tlsAllowInvalidHostnames $mongo_flag" + else + kubectl_bin exec ${client_container} -- \ + bash -c "printf '$command\n' | mongo $driver://$uri$suffix/admin?replicaSet=$replica_set --tls --tlsCAFile /etc/mongodb-ssl/ca.crt --tlsCertificateKeyFile /tmp/tls.pem --tlsAllowInvalidHostnames $mongo_flag" + fi } run_mongos() { @@ -1349,7 +1357,7 @@ collect_k8s_logs() { for com in "${command[@]}"; do echo "##### START: ${com} #####" >>${logs_path}/mongodb_${psmdb_name}_${psmdb_replset}.mongo run_mongo "${com}" "${psmdb_user}:${psmdb_pass}@${psmdb_name}-${psmdb_replset}.${namespace}" >>${logs_path}/mongodb_${psmdb_name}_${psmdb_replset}.mongo - echo -e "##### END: ${com} #####\n" >>${logs_path}/mongodb_${psmdb_name}_${psmdb_replset}.mongo + echo -e "##### END: ${com} #####\n" >>${logs_path}/mongodb_${psmdb_name}_${psmdb_replset}.mongo done done done