hashicorp / hashicorp/consul-template
Keep getting old values after updating a value in Consul KV
- Dominant language
- Go
- Stars
- 4.8k
- Forks
- 801
- Avg merge
- 4h 5m
- Merged PRs (30d)
- 6
Description
### Consul Template version
consul-template v0.25.2 (c8372a0a)
### Configuration
I'm running a containerized environment using docker-compose. The simplified system consists of **Consul** and a **Angular frontend**.
The image for the frontend has consul-template installed and the consul-template command is executed in a entrypoint shell script at startup.
The purpose is that a config.json file should be populated with the current settings from Consul KV and later on be consumed by the frontend. That part works fine.
**consultemplate.tpl**
{
"backendUrl": "{{ key "/system/web/backend-url" }}",
"backendToken": "{{ key "/system/web/backend-token" }}"
}
**docker-compose.yml**
version: "3.6"
services:
**Consul**
consul:
image: consul:latest
ports:
- "8500:8500"
- "8300:8300"
volumes:
- ${DATA_PATH}/consul-config:/config
- ${DATA_PATH}/consul-data:/data
command: agent -server -data-dir=/data -bind 0.0.0.0 -client 0.0.0.0 -bootstrap-expect=1 -ui=true
**Frontend**
frontend-web:
image: ${REGISTRY}/frontend-web:${FRONTEND_WEB_VERSION}
restart: unless-stopped
environment:
- CONSUL_HTTP_ADDR=${CONSUL_HTTP_ADDR}
ports:
- 4040:80
logging:
driver: json-file
options:
max-size: "10m"
max-file: "5"
### Command
consul-template -template "consultemplate.tpl:config.json" -consul-addr ${CONSUL_HTTP_ADDR} -once
cat config.json
### Expected behavior
The config.json should be populated with the current/latest settings from Consul KV upon each 'docker-compose up'.
### Actual behavior
While trying docker-compose up / down I get different result for my config.json. It's common that the backendUrl or the backendToken suddenly gets a old value.
For example: if I update both the backend-token and the backend-url in Consul KV. Then validate in the Consul KV GUI that the values are correctly saved.
When running docker-compose **down** and then **up** - then sometimes the backendUrl can be correct with the latest value, but the backendToken has the value from 5 updates ago. Or the other way. Sometimes both values are correct.
I go to the Consul KV GUI and check those two keys and see that both has the expected value. So why do I keep getting old values in my config.json?
It can be that I get "Updated 1", "Updated 2", "Updated 3" and when I update to "Updated 4" and restart the service I suddenly get "Update 2" again.
Contributor guide
Research direction
Start by reproducing the reported command from the entrypoint shell script with consultemplate.tpl, docker-compose.yml, and the Consul KV values, then inspect how config.json is generated by consul-template v0.25.2. Done means identifying why stale values are rendered and ensuring both keys consistently produce their latest Consul KV values after the service is restarted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, docker-compose, go
- Domain
- devops, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100