hashicorp / consul-template

Template rendering, notifier, and supervisor for @HashiCorp Consul and Vault data.
https://www.hashicorp.com/
Mozilla Public License 2.0
4.76k stars 782 forks source link

Service filter returns all services instead of the specified subset #1994

Closed rafaelmagu closed 1 month ago

rafaelmagu commented 1 month ago

When using service "web|passing,warning" in a range loop, all catalog services are returned, instead of just the specific ones. This happens despite correct responses from both Consul CLI and the Consul API.

Consul Template version

consul-template v0.39.1 (cc8f954)

Configuration

tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
# Debug: Total services: {{ len (service "zookeeper|passing,warning") }}
{{ range $index, $service := service "zookeeper" }}
server.{{ $index | add 1 }}={{ $service.Address }}:2888:3888
{{ end }}

Command

/usr/local/bin/consul-template -consul-retry -consul-retry-attempts=0 -dedup -template="/etc/zookeeper/conf/zoo.cfg.ctmpl:/etc/zookeeper/conf/zoo.cfg"

Debug output

Debug output

Expected behavior

When rendered, the above template should yield a result similar to:

tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
# Debug: Total services: 3
server.1=10.110.15.36:2888:3888
server.2=10.110.44.177:2888:3888
server.3=10.110.30.116:2888:3888

Actual behavior

Instead, we end up with many server entries, for all types of services (not just Zookeeper):

tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
# Debug: Total services: 53
server.1=10.110.15.36:2888:3888
server.2=10.110.15.36:2888:3888
server.3=10.110.44.177:2888:3888
server.4=10.110.44.177:2888:3888
server.5=10.110.30.116:2888:3888
server.6=10.110.30.116:2888:3888
server.7=10.110.36.63:2888:3888
server.8=10.110.36.63:2888:3888
server.9=10.110.10.241:2888:3888
server.10=10.110.10.241:2888:3888
...

Notes

If I run the Consul Template command with -once, it will correctly render the file as expected. With -once removed, the file keeps being re-rendered with many extra server lines.

Steps to reproduce

  1. Create Consul Template template
  2. Ensure service zookeeper is present in the catalog in a warning or passing state
  3. Run CLI command

References

dpresling commented 1 month ago

Further context (and a recorded fix) -

The consul servers were running on Consul v1.10.1 | consul-template v0.34.0 while the client (zookeeper) had been upgraded to use Consul v1.19.2 | consul-template v0.39.2. After upgrading the consul servers to v1.19.2 the zookeeper consul-template issues have been resolved.

So this was a backwards compatibility issue.