Skip to content

Commit 8216629

Browse files
committed
functions - fix run_mongo and run_mongos for collecting k8s logs
1 parent dc207e0 commit 8216629

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

e2e-tests/functions

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,15 @@ run_mongo() {
705705
local suffix=${4:-.svc.cluster.local}
706706
local client_container=$(kubectl_bin get pods --selector=name=psmdb-client -o 'jsonpath={.items[].metadata.name}')
707707
local mongo_flag="$5"
708-
local replica_set=$(echo "$uri" | sed -r 's/.*\-(rs[0-9]|cfg)(\.|-).*/\1/')
709-
710-
kubectl_bin exec ${client_container} -- \
711-
bash -c "printf '$command\n' | mongo $driver://$uri$suffix/admin?ssl=false\&replicaSet=$replica_set $mongo_flag"
708+
local replica_set=$(echo "$uri" | grep -oE '\-(rs[0-9]|cfg)(\.|-)' | sed 's/^.//;s/.$//')
712709

710+
if [[ ${FUNCNAME[1]} == "collect_k8s_logs" ]]; then
711+
kubectl exec ${client_container} -- \
712+
bash -c "printf '$command\n' | mongo $driver://$uri$suffix/admin?ssl=false\&replicaSet=$replica_set $mongo_flag"
713+
else
714+
kubectl_bin exec ${client_container} -- \
715+
bash -c "printf '$command\n' | mongo $driver://$uri$suffix/admin?ssl=false\&replicaSet=$replica_set $mongo_flag"
716+
fi
713717
}
714718

715719
run_mongo_tls() {
@@ -719,11 +723,15 @@ run_mongo_tls() {
719723
local suffix=${4:-.svc.cluster.local}
720724
local client_container=$(kubectl_bin get pods --selector=name=psmdb-client -o 'jsonpath={.items[].metadata.name}')
721725
local mongo_flag="$5"
722-
local replica_set=$(echo "$uri" | sed -r 's/.*\-(rs[0-9]|cfg)(\.|-).*/\1/')
723-
724-
kubectl_bin exec ${client_container} -- \
725-
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"
726+
local replica_set=$(echo "$uri" | grep -oE '\-(rs[0-9]|cfg)(\.|-)' | sed 's/^.//;s/.$//')
726727

728+
if [[ ${FUNCNAME[1]} == "collect_k8s_logs" ]]; then
729+
kubectl exec ${client_container} -- \
730+
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"
731+
else
732+
kubectl_bin exec ${client_container} -- \
733+
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"
734+
fi
727735
}
728736

729737
run_mongos() {

0 commit comments

Comments
 (0)