Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Wait until leader before applying license
Browse files Browse the repository at this point in the history
Previously, if the leader wasn't elected the consul license command
would fail. On clusters where the servers took a long time to come up,
the job would reach its maximum backoff limit and the license would
never be applied.
  • Loading branch information
lkysow committed Feb 10, 2020
1 parent b1432cc commit 0db9e52
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion templates/enterprise-license-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,35 @@ spec:
{{- end}}
command:
- "/bin/sh"
- "-ec"
- "-c"
- |
log() {
echo "$(date +%d-%m-%Y" "%H:%M:%S) $@"
}
log "Waiting for leader to be elected..."
while true; do
OUTPUT=$(curl --silent --show-error --fail \
--max-time 2 \
{{- if .Values.global.tls.enabled }}
--cacert /consul/tls/ca/tls.crt \
{{- end }}
"$CONSUL_HTTP_ADDR/v1/status/leader" 2>&1)
CODE=$?
log "curl $CONSUL_HTTP_ADDR/v1/status/leader: $OUTPUT"
# Need to check for empty output because if the servers
# are running but no leader is elected the endpoint
# will return HTTP 200 but with empty output.
if [ $CODE -eq 0 ] && [ "$OUTPUT" != '""' ]; then
log "Leader elected"
break
fi
log "Retrying in 2s"
sleep 2s
done
consul license put "${ENTERPRISE_LICENSE}"
{{- if .Values.global.tls.enabled }}
volumeMounts:
Expand Down

0 comments on commit 0db9e52

Please sign in to comment.