Skip to content

Commit

Permalink
functions - fix run_mongo and run_mongos for collecting k8s logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tplavcic committed Oct 20, 2023
1 parent dc207e0 commit dc6b1c6
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions e2e-tests/functions
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dc6b1c6

Please sign in to comment.