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

Update build to use 1.18+ to add template support for continue and break #1663

Closed
jrwren opened this issue Nov 3, 2022 · 6 comments
Closed
Milestone

Comments

@jrwren
Copy link
Contributor

jrwren commented Nov 3, 2022

Consul Template version

consul-template v0.29.5 (f07ce88)

Configuration

wtf.tmpl:

{{ range services }}
{{- range service .Name -}}
{{ if .Tags | contains "https" | not }}
no https in {{.Name}}
{{continue}}
{{end}}
{{end}}
{{end}}

Command

./consul-template -template "wtf.tmpl:out.txt" -once  && less out.txt 

Debug output

Provide a link to a GitHub Gist containing the complete debug
output by running with -log-level=trace.
It is short, I'm putting it here:

2022-11-03T15:07:44.661Z [INFO] consul-template v0.29.5 (f07ce88)
2022-11-03T15:07:44.661Z [INFO] (runner) creating new runner (dry: false, once: true)
2022-11-03T15:07:44.661Z [DEBUG] (runner) final config: {"Consul":{"Address":"172.16.123.74:8500","Namespace":"","Auth":{"Enabled":false,"Username":""},"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":true},"Token":"","TokenFile":"","Transport":{"CustomDialer":null,"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":9,"TLSHandshakeTimeout":10000000000}},"Dedup":{"Enabled":false,"MaxStale":2000000000,"Prefix":"consul-template/dedup/","TTL":15000000000,"BlockQueryWaitTime":60000000000},"DefaultDelims":{"Left":null,"Right":null},"Exec":{"Command":[],"Enabled":false,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":0},"KillSignal":2,"LogLevel":"trace","FileLog":{"LogFilePath":"","LogRotateBytes":0,"LogRotateDuration":86400000000000,"LogRotateMaxFiles":0},"MaxStale":2000000000,"PidFile":"","ReloadSignal":1,"Syslog":{"Enabled":false,"Facility":"LOCAL0","Name":"consul-template"},"Templates":[{"Backup":false,"Command":[],"CommandTimeout":30000000000,"Contents":"","CreateDestDirs":true,"Destination":"out.txt","ErrMissingKey":false,"ErrFatal":true,"Exec":{"Command":[],"Enabled":false,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":30000000000},"Perms":0,"User":null,"Uid":null,"Group":null,"Gid":null,"Source":"wtf.tmpl","Wait":{"Enabled":false,"Min":0,"Max":0},"LeftDelim":"","RightDelim":"","FunctionDenylist":[],"SandboxPath":""}],"TemplateErrFatal":null,"Vault":{"Address":"","Enabled":false,"Namespace":"","RenewToken":false,"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":true,"Key":"","ServerName":"","Verify":true},"Transport":{"CustomDialer":null,"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":9,"TLSHandshakeTimeout":10000000000},"UnwrapToken":false,"DefaultLeaseDuration":300000000000,"LeaseRenewalThreshold":0.9,"K8SAuthRoleName":"","K8SServiceAccountTokenPath":"/run/secrets/kubernetes.io/serviceaccount/token","K8SServiceAccountToken":"","K8SServiceMountPath":"kubernetes"},"Nomad":{"Address":"http://172.16.123.74:4646","Enabled":true,"Namespace":"","SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":true},"AuthUsername":"","AuthPassword":"","Transport":{"CustomDialer":null,"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":9,"TLSHandshakeTimeout":10000000000},"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true}},"Wait":{"Enabled":false,"Min":null,"Max":null},"Once":true,"ParseOnly":false,"BlockQueryWaitTime":60000000000}
2022-11-03T15:07:44.661Z [INFO] (runner) creating watcher
2022-11-03T15:07:44.661Z [INFO] (runner) starting
2022-11-03T15:07:44.661Z [DEBUG] (runner) running initial templates
2022-11-03T15:07:44.661Z [DEBUG] (runner) initiating run
2022-11-03T15:07:44.661Z [DEBUG] (runner) checking template abb1bc4f1698522dea1e1232c237b07d
2022-11-03T15:07:44.662Z [ERR] (cli) wtf.tmpl: parse: template: :5: function "continue" not defined

Expected behavior

What should have happened?
I should be able to use {{continue}} as defined in https://pkg.go.dev/text/template#hdr-Actions

Actual behavior

What actually happened?
I got an error that continue is not defined.

Steps to reproduce

  1. try to use {{continue}}
@eikenb eikenb added the bug label Nov 3, 2022
@eikenb
Copy link
Contributor

eikenb commented Nov 3, 2022

Thanks for the report @jrwren!

That is a very weird one. Not sure how the builtin continue can't be found but I'll look into it as soon as I can.

@eikenb
Copy link
Contributor

eikenb commented Nov 3, 2022

I tried reproducing this real quick with the script below with some test service definitions I had around and couldn't (continue worked). If you could supply any additional information it might help. Thanks.

#!/bin/sh

cat > foo.tmpl << EOF
{{ range services }}
{{ .Name }}
{{ if .Name | contains "api" | not }}
{{ continue }}
{{ end }}
{{ range service .Name }}
{{ . }}
{{ end }}
{{ end }}
EOF

consul-template \
    -template "foo.tmpl:foo" \
    -log-level trace \
    -exec "cat foo" \
    -once

@jrwren
Copy link
Contributor Author

jrwren commented Nov 3, 2022

This makes no sense!

I'm using consul-tempate 0.29.5 as downloaded from https://releases.hashicorp.com/consul-template/0.29.5/consul-template_0.29.5_linux_amd64.zip earlier today

I just copied and pasted your foo.tmpl shell example and I get this:

2022-11-03T20:37:25.191Z [INFO] consul-template v0.29.5 (f07ce88)
2022-11-03T20:37:25.191Z [INFO] (runner) creating new runner (dry: false, once: true)
2022-11-03T20:37:25.191Z [DEBUG] (runner) final config: {"Consul":{"Address":"","Namespace":"","Auth":{"Enabled":false,"Username":""},"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":true},"Token":"","TokenFile":"","Transport":{"CustomDialer":null,"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":9,"TLSHandshakeTimeout":10000000000}},"Dedup":{"Enabled":false,"MaxStale":2000000000,"Prefix":"consul-template/dedup/","TTL":15000000000,"BlockQueryWaitTime":60000000000},"DefaultDelims":{"Left":null,"Right":null},"Exec":{"Command":["cat foo"],"Enabled":true,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":0},"KillSignal":2,"LogLevel":"trace","FileLog":{"LogFilePath":"","LogRotateBytes":0,"LogRotateDuration":86400000000000,"LogRotateMaxFiles":0},"MaxStale":2000000000,"PidFile":"","ReloadSignal":1,"Syslog":{"Enabled":false,"Facility":"LOCAL0","Name":"consul-template"},"Templates":[{"Backup":false,"Command":[],"CommandTimeout":30000000000,"Contents":"","CreateDestDirs":true,"Destination":"foo","ErrMissingKey":false,"ErrFatal":true,"Exec":{"Command":[],"Enabled":false,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":30000000000},"Perms":0,"User":null,"Uid":null,"Group":null,"Gid":null,"Source":"foo.tmpl","Wait":{"Enabled":false,"Min":0,"Max":0},"LeftDelim":"","RightDelim":"","FunctionDenylist":[],"SandboxPath":""}],"TemplateErrFatal":null,"Vault":{"Address":"","Enabled":false,"Namespace":"","RenewToken":false,"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":true,"Key":"","ServerName":"","Verify":true},"Transport":{"CustomDialer":null,"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":9,"TLSHandshakeTimeout":10000000000},"UnwrapToken":false,"DefaultLeaseDuration":300000000000,"LeaseRenewalThreshold":0.9,"K8SAuthRoleName":"","K8SServiceAccountTokenPath":"/run/secrets/kubernetes.io/serviceaccount/token","K8SServiceAccountToken":"","K8SServiceMountPath":"kubernetes"},"Nomad":{"Address":"http://172.16.123.74:4646","Enabled":true,"Namespace":"","SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":true},"AuthUsername":"","AuthPassword":"","Transport":{"CustomDialer":null,"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":9,"TLSHandshakeTimeout":10000000000},"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true}},"Wait":{"Enabled":false,"Min":null,"Max":null},"Once":true,"ParseOnly":false,"BlockQueryWaitTime":60000000000}
2022-11-03T20:37:25.191Z [INFO] (runner) creating watcher
2022-11-03T20:37:25.191Z [INFO] (runner) starting
2022-11-03T20:37:25.191Z [DEBUG] (runner) running initial templates
2022-11-03T20:37:25.191Z [DEBUG] (runner) initiating run
2022-11-03T20:37:25.192Z [DEBUG] (runner) checking template 4fef1b5aeedade4ccadacba77375a01d
2022-11-03T20:37:25.192Z [ERR] (cli) foo.tmpl: parse: template: :4: function "continue" not defined

I just tried it with another consul server with the same results.

I'm running on Ubuntu 18.04.6 LTS which I ack is old. I'll try in a 20.04 container.

The same thing happens in a 20.04 container. I can't imagine what would cause this.

@jrwren
Copy link
Contributor Author

jrwren commented Nov 3, 2022

JFYI, I did it again on an entirely different consul cluster and with the same results.

@eikenb
Copy link
Contributor

eikenb commented Nov 3, 2022

Got it!

I'm running a local build that is using Go 1.19. The v0.29.5 release was built with Go 1.17. Text templates added support for continue/break in Go 1.18.

So they are not supported in the current released version but will be in the next. You can compile it locally with 1.18+ and get the functionality or wait for our next release (no firm timeline for this ATM).

I'm going to leave this open for now as a general feature request to get a release out with support for these new keywords.

@eikenb eikenb changed the title {{continue}} is not defined Update build to use 1.18+ to add template support for continue and break Nov 3, 2022
@eikenb eikenb added this to the v0.30.0 milestone Nov 3, 2022
@eikenb
Copy link
Contributor

eikenb commented Nov 21, 2022

Note that the Go version has been updated to 1.19 and will be included in the next release.

@eikenb eikenb closed this as completed Nov 21, 2022
@eikenb eikenb modified the milestones: v0.30.0, 0.29.6 Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants