Open analytically opened 9 years ago
# Generated using confd {{datetime}}
Could this be the culprit?
Yep it seems like it.
+1
Well, considering that {{ datetime }}
just outputs time.Now(), I'm wondering if there's a way we can somehow hook into the time when we boot confd and pipe that to datetime
instead. Would that work for you?
More helpful, although probably more complicated to pull off, would be to update the time whenever there are other changes.
Would ignoring lines starting with # and so on help? It would require implementing setting ignoreLines=^#
.
This is working as designed. The template is only triggered when there is an updated key in the configuration store. If you call the datetime function in a loop you are going to get a new timestamp for each call.
This would be a bug if templates are being process when there are no changes in the configuration backend.
I ran into this issue as well. When {{datetime}}
is part of the source template, it causes the reload_cmd
to be triggered (and thus haproxy keeps reloading) without any changes to the keys being monitored.
haproxy.toml
[template]
src = "haproxy.cfg.tmpl"
dest = "/etc/haproxy/haproxy.cfg"
keys = [
"/skydns/tf/csa/services/sample-app"
]
reload_cmd = "echo restarting && /usr/bin/systemctl reload haproxy"
haproxy.cfg.tmpl
...
backend sample_cluster
# Generated by confd {{datetime}}
{{range gets "/skydns/tf/csa/services/sample-app/*"}}
{{$data := json .Value}}
server {{ base .Key}} {{$data.host}}:{{$data.port}} check
{{end}}
/usr/bin/confd[21]: DEBUG "restarting\n"
/usr/bin/confd[21]: INFO Target config /etc/haproxy/haproxy.cfg has been updated
/usr/bin/confd[21]: DEBUG Loading template resources from confdir /etc/confd
/usr/bin/confd[21]: DEBUG Loading template resource from /etc/confd/conf.d/haproxy.toml
/usr/bin/confd[21]: DEBUG Retrieving keys from store
/usr/bin/confd[21]: DEBUG Key prefix set to /
/usr/bin/confd[21]: DEBUG Using source template /etc/confd/templates/haproxy.cfg.tmpl
/usr/bin/confd[21]: DEBUG Compiling source template /etc/confd/templates/haproxy.cfg.tmpl
/usr/bin/confd[21]: DEBUG Comparing candidate config to /etc/haproxy/haproxy.cfg
/usr/bin/confd[21]: INFO /etc/haproxy/haproxy.cfg has md5sum 12edc21a01e8071a55395078bc849c5f should be 7d6b9bb9fc883d04a33d919e022f7254
/usr/bin/confd[21]: INFO Target config /etc/haproxy/haproxy.cfg out of sync
/usr/bin/confd[21]: DEBUG Overwriting target config /etc/haproxy/haproxy.cfg
/usr/bin/confd[21]: DEBUG Running echo restarting && /usr/bin/systemctl reload haproxy
/usr/bin/confd[21]: DEBUG "restarting\n"
/usr/bin/confd[21]: INFO Target config /etc/haproxy/haproxy.cfg has been updated
This would be a bug if templates are being process when there are no changes in the configuration backend.
I think that is what's happening here, judging from @icheko and @analytically's comments. I also tried testing this and verified it's a bug. It's because the md5sum changes any time the template is evaluated because time.Now()
is different every interval, causing the md5sum to always be different compared to its predecessor. I'm not sure there's an easy answer on how we fix this behaviour.
@bacongobbler Setting datetime to write special value and replacing it after computing md5 sum would not work?
We're seeing this. Any idea?