k8s: start script do not run PBM until shard is not assembled
Take the sharding into account while waiting for cluster to be ready for PBM start
@@ -6,9 +6,29 @@ set -o xtrace
if [ "${1:0:9}" = "pbm-agent" ]; then
OUT="$(mktemp)"
+ OUT_CFG="$(mktemp)"
timeout=5
-
for i in {1..10}; do
+ if [ "${SHARDED}" ]; then
+ echo "waiting for sharded scluster"
+
+ # check in case if shard has role 'shardsrv'
+ mongo "${PBM_MONGODB_URI}" --eval="db.isMaster().\$configServerState.opTime.ts" --quiet | tee "$OUT"
+ exit_status=$?
+
+ # check in case if shard has role 'configsrv'
+ mongo "${PBM_MONGODB_URI}" --eval="db.isMaster().configsvr" --quiet | tail -n 1 | tee "$OUT_CFG"
+ exit_status_cfg=$?
+
+ ts=$(grep -E '^Timestamp\([0-9]+, [0-9]+\)$' "$OUT")
+ isCfg=$(grep -E '^2$' "$OUT_CFG")
+
+ if [[ "${exit_status}" == 0 && "${ts}" ]] || [[ "${exit_status_cfg}" == 0 && "${isCfg}" ]]; then
+ break
+ else
+ sleep "$((timeout * i))"
+ fi
+ else
mongo "${PBM_MONGODB_URI}" --eval="(db.isMaster().hosts).length" --quiet | tee "$OUT"
exit_status=$?
rs_size=$(grep -E '^([0-9]+)$' "$OUT")
@@ -17,6 +37,7 @@ if [ "${1:0:9}" = "pbm-agent" ]; then
else
sleep "$((timeout * i))"
fi
+ fi
done
rm "$OUT"
