Skip to content

Commit

Permalink
[#105] Drainer pod uses un-resolvable hostname for it's cluster conne…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
howardgao committed Jul 11, 2024
1 parent 8009043 commit f9179b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 13 additions & 2 deletions modules/activemq-artemis-launch/added/drain.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/usr/bin/env bash

export BROKER_HOST="$(hostname -f)"
if [ -z "${DRAINER_IP}" ]; then
echo "[drain.sh] DRAINER_IP is not set"
sleep 30
exit 1
fi

echo "[drain.sh] drainer container ip(from hostname) is $BROKER_HOST"
# use pod IP rather than `hostname -f` which will return pod's name
# that is not resolvable across the cluster
export BROKER_HOST=${DRAINER_IP}

echo "[drain.sh] drainer container ip is $BROKER_HOST"

instanceDir="${HOME}/${AMQ_NAME}"

Expand Down Expand Up @@ -110,6 +118,9 @@ echo "[drain.sh] scale down target is: $SCALE_TO_BROKER"
connector="<connector name=\"scaledownconnector\">tcp:\/\/${SCALE_TO_BROKER}:61616<\/connector>"
sed -i "/<\/connectors>/ s/.*/${connector}\n&/" "${instanceDir}/etc/broker.xml"

connector="<connector name=\"artemis\">tcp:\/\/${BROKER_HOST}:61616<\/connector>"
sed -i "s/<connector name=\"artemis\">.*<\/connector>/${connector}/" "${instanceDir}/etc/broker.xml"

# Remove the acceptors
#sed -i -ne "/<acceptors>/ {p; " -e ":a; n; /<\/acceptors>/ {p; b}; ba}; p" ${instanceDir}/etc/broker.xml
acceptor="<acceptor name=\"artemis\">tcp:\/\/${BROKER_HOST}:61616?protocols=CORE<\/acceptor>"
Expand Down
12 changes: 12 additions & 0 deletions modules/activemq-artemis-launch/tests/features/drain.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@artemiscloud
Feature: Scaledown

Scenario: Test if DRAINER_IP works
When container is started with command /opt/amq/bin/drain.sh
| variable | value |
| DRAINER_IP | 10.1.233.13 |
Then available container log should contain 10.1.233.13

Scenario: Test if DRAINER_IP is absent
When container is started with command /opt/amq/bin/drain.sh
Then available container log should contain DRAINER_IP is not set

0 comments on commit f9179b0

Please sign in to comment.