Skip to content

Commit

Permalink
ZDM-295 Fixed bug in container discovery performed by jumphost
Browse files Browse the repository at this point in the history
  • Loading branch information
ossarga committed Sep 29, 2022
1 parent efe6e18 commit 2f14987
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docker-compose/services/client/client-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ do
eval $host_var_name=$(cut -d':' -f2 <<<"$get_host_info_result")
done

echo "Testing cqlsh to proxy_1"
echo "Testing cqlsh to $proxy_1_host"
test_conn $proxy_1_host

echo "Creating schema on $cassandra_origin_host"
Expand Down
40 changes: 28 additions & 12 deletions docker-compose/services/jumphost/jumphost-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,29 @@ function get_host_info() {
cidr_ip_subnet=$(ip addr show | grep "inet" | grep "eth0" | tr -s ' ' | cut -d' ' -f3)
fi
# formats each entry in the array as: <host_name>:<host_ip>
get_host_info_results=($(nmap -sn $cidr_ip_subnet | grep "proxy" | cut -d' ' -f5,6 | sed 's,\.proxy\ (\([0-9\.]*\)),:\1,' | grep "$host_search_name"))
get_host_info_results=( \
$(nmap -sn $cidr_ip_subnet | \
grep "proxy" | \
cut -d' ' -f5,6 | \
sed 's,\.proxy\ (\([0-9\.]*\)),:\1,' | \
rev | \
cut -d'-' -f1 | \
rev | \
grep "$host_search_name"))

while [ ${#get_host_info_results[*]} -eq 0 ]
do
echo "no '$host_search_name' hosts found, trying again in 20s"
sleep 20
get_host_info_results=($(nmap -sn $cidr_ip_subnet | grep "proxy" | cut -d' ' -f5,6 | sed 's,\.proxy\ (\([0-9\.]*\)),:\1,' | grep "$host_search_name"))
get_host_info_results=( \
$(nmap -sn $cidr_ip_subnet | \
grep "proxy" | \
cut -d' ' -f5,6 | \
sed 's,\.proxy\ (\([0-9\.]*\)),:\1,' | \
rev | \
cut -d'-' -f1 | \
rev | \
grep "$host_search_name"))
done
echo "Found '$host_search_name' hosts:"
for host_info in ${get_host_info_results[*]}
Expand Down Expand Up @@ -55,15 +71,6 @@ function get_ip() {
dig +short "$1"
}

echo "Starting SSH server"
/etc/init.d/ssh start

echo "Generating SSH key pair"
gosu ${USER_NAME} ssh-keygen -q -t rsa -N '' -f ${USER_HOME}/.ssh/id_rsa
mkdir -p ${KEY_DROP_DIR} && \
cp -f ${USER_HOME}/.ssh/id_rsa.pub ${KEY_DROP_DIR}/
cat ${USER_HOME}/.ssh/id_rsa.pub >> ${USER_HOME}/.ssh/authorized_keys

echo "Creating hosts file"
echo -n > ${HOSTS_FILE}

Expand All @@ -88,6 +95,15 @@ done
echo "CASSANDRA_ORIGIN:${origin_host_info}" >> ${HOSTS_FILE}
echo "CASSANDRA_TARGET:${target_host_info}" >> ${HOSTS_FILE}

echo "Starting SSH server"
/etc/init.d/ssh start

echo "Generating SSH key pair"
gosu ${USER_NAME} ssh-keygen -q -t rsa -N '' -f ${USER_HOME}/.ssh/id_rsa
mkdir -p ${KEY_DROP_DIR} && \
cp -f ${USER_HOME}/.ssh/id_rsa.pub ${KEY_DROP_DIR}/
cat ${USER_HOME}/.ssh/id_rsa.pub >> ${USER_HOME}/.ssh/authorized_keys

scan_key jumphost
for host_info in ${proxy_host_info[*]}
do
Expand Down Expand Up @@ -120,7 +136,7 @@ echo "[ssh_connection]\nssh_args = -o StrictHostKeyChecking=no\n" > ${ZDM_PROXY_

cd ${ZDM_PROXY_OPT}/ansible

gosu ${USER_NAME} ansible-playbook deploy_zdm_proxy.yml -i zdm_ansible_inventory
gosu ${USER_NAME} ansible-playbook deploy_zdm_proxy.yml -i zdm_ansible_inventory \
-e "origin_cassandra_username=foo" \
-e "origin_cassandra_password=foo" \
-e "target_cassandra_username=foo" \
Expand Down

0 comments on commit 2f14987

Please sign in to comment.