Skip to content

Commit

Permalink
tidy wait for token replication script
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Glass committed May 2, 2022
1 parent a86d78c commit 4f98aec
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/mesh-task/templates/consul_client_command.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ echo "$CONSUL_CACERT" > /consul/consul-ca-cert.pem

%{ if acls && client_token_auth_method_name != "" ~}

login() {
consul_login() {
echo "Logging into auth method: name=${ client_token_auth_method_name }"
consul login \
-http-addr ${ consul_http_addr } \
Expand All @@ -36,15 +36,15 @@ read_token_stale() {
}

# Retry in order to login successfully.
while ! login; do
while ! consul_login; do
sleep 2
done

# Wait for raft replication to hopefully occur. Without this, an "ACL not found" may be cached for a while.
# Technically, the problem could still occur but this should handle most cases.
# This waits at most 2s (20 attempts with 0.1s sleep)
COUNT=20
while [ "$COUNT" -gt "0" ]; do
while [ "$COUNT" -gt 0 ]; do
echo "Checking that the ACL token exists when reading it in the stale consistency mode ($COUNT attempts remaining)"
if read_token_stale; then
echo "Successfully read ACL token from the server"
Expand All @@ -53,7 +53,7 @@ while [ "$COUNT" -gt "0" ]; do
sleep 0.1
COUNT=$((COUNT - 1))
done
if [ "$COUNT" -eq "0" ]; then
if [ "$COUNT" -eq 0 ]; then
echo "Unable to read ACL token from a Consul server; please check that your server cluster is healthy"
exit 1
fi
Expand Down

0 comments on commit 4f98aec

Please sign in to comment.