Hey Ivan,
I took a look at the code, and I think that because the hash of the template itself is the same,
all the nodes will treat this as a single template. However, the instance that is doing the actual
rendering (lock winner), will use it’s hostname to watch the “ip/hostname” key, so when the other
templates attempt to render, they will be missing the appropriate value for that key.
In this scenario, I’m not sure deduplication would help, since effectively every node is watching
a distinct key in Consul, so there is no real de-duplication of effort that is possible. That mode is meant
to reduce duplicate watches (e.g. 50 nodes watching the 1 set of keys) instead here it’s 50 nodes
watching 50 distinct keys.
One way you could restructure this is to write a single key to Consul, which is a JSON object of {“hostname”: “ip”}.
Then you could refactor to something like:
{{ $listenMap := key “ip_map” | toJSON }}
{{ $listenIP := $listenMap[$hostname }}
This way all the nodes are watching the same key, so the de-duplicaiton could actually take effect, and then
the client side is able to do the final lookup to determine the appropriate key.
Hope that helps!
Best Regards,
Armon Dadgar