Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetaure request: a way for consul-template to exit upon a failed key lookup #1637

Closed
eikenb opened this issue Sep 7, 2022 · 6 comments · Fixed by #1695
Closed

Fetaure request: a way for consul-template to exit upon a failed key lookup #1637

eikenb opened this issue Sep 7, 2022 · 6 comments · Fixed by #1695
Labels
consul Related to the Consul integration enhancement
Milestone

Comments

@eikenb
Copy link
Contributor

eikenb commented Sep 7, 2022

Requested feature is pretty straightforward and is simply that they want consul-template to exit with an error if a key it is looking up in Consul does not exist.

It should work with the template_error_fatal setting.

Look into making this cover all backends but only if simple. Otherwise keep this consul specific.

@eikenb eikenb added this to the v0.30.0 milestone Sep 7, 2022
@eikenb eikenb added the consul Related to the Consul integration label Sep 7, 2022
@eikenb
Copy link
Contributor Author

eikenb commented Jan 4, 2023

Poked around this today trying to figure out the best solution. My current idea is to add a simple error template function that returns an error in a place that. Having a function that returns an error means you can use it with the keyExists function to dynamically check and trigger an error in the template. Eg.

{{ if not (keyExists "foo") }}
    {{ error "key foo doesn't exist" }}
{{end}}

@eikenb
Copy link
Contributor Author

eikenb commented Jan 4, 2023

Oh.. and using the above with the template_error_fatal setting will achieve the goal of this enhancement request.

@eikenb
Copy link
Contributor Author

eikenb commented Jan 5, 2023

That was naive. Templates always render once through with everything failing to look up. So any sort of exists check will always fail the first time triggering the error.

@eikenb
Copy link
Contributor Author

eikenb commented Jan 6, 2023

Added it as a top level option that triggers the error on any data lookup that fails 2 fetch attempts. The error happens on the second attempt as the first attempt is a special case that does some setup.

Note that setting this disables retries for failed lookup attempt errors.

@akamensky
Copy link

akamensky commented Jan 30, 2023

Does not seem to work.

Template:

$ cat some.tpl 
{{ key "/does/not/exist" }}

Executing as:

$ consul-template -template-error-fatal -once -template "some.tpl:out.txt"

Hangs indefinitely. And I keep seeing in Consul logs:

2023-01-30T17:36:57.248+1100 [DEBUG] agent.http: Request finished: method=GET url="/v1/kv/does/not/exist?index=50&stale=&wait=60000ms" from=127.0.0.1:45502 latency=1m2.449311662s

Unless you mean that I should be checking if key exists from inside template? Then this feature makes very little sense to me.

@jlouros
Copy link

jlouros commented Feb 15, 2023

I can also confirm using consul-template -template-error-fatal -once -template="some.tpl:out.txt" does not work.

Also tried passing a bool consul-template -template-error-fatal=true -once -template="some.tpl:out.txt" (multiple variations like: true, True, TRUE, 1) and nothing happens. Consul-template still waits for the key to be present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consul Related to the Consul integration enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants