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

Change in writeToFile output do not trigger reload in exec mode #1851

Open
davidatkinsondoyle opened this issue Nov 28, 2023 · 0 comments
Open

Comments

@davidatkinsondoyle
Copy link

When a change in state results in only changes to files creates by writeToFile then a process reload is not triggered. It is unclear if this is a bug or intended behaviour, but the documentation doesn't indicate that writeToFile outputs are not evaluated when determining if there should be a reload.

Consul Template version

0.35.0 OSX
0.35.0 Debian (via Docker)

Configuration

consul {
  address = "host.docker.internal:8500"
  retry {
    enabled = true
    attempts = 0
    backoff = "250ms"
    max_backoff = "1m"
  }
}
max_stale = "10m"
log_level = "trace"

template {
  source = "template.tmpl"
  destination = "out.conf"
}

exec {
  command = "exec ./debug.sh"
  reload_signal = "SIGHUP"
}

Template

{{- with $test := (keyOrDefault "testKeys" "[]") | parseJSON }}
    {{- range $test.testSet}}
        Example include for rendered file output/{{.staticValue}}.conf
        {{.dynamicValue | writeToFile (printf "output/%s.conf" .staticValue) "" "" "0644"}}
    {{- end}}
{{end}}

K/V Sample data at testKeys

{
    "testSet": [
        {
            "staticValue": "test1",
            "dynamicValue": "value1"
        },
        {
            "staticValue": "test2",
            "dynamicValue": "value2"
        }
    ]
}

Managed Process

 #!/usr/bin/env bash 
 trap "echo 'Trapped SIGHUP'" HUP
  
 while true; do 
 	: # Hang 
 done 

Command

consul-template -config ./consul-template.conf

Debug output

Logs Demoing issue: https://gist.github.com/davidatkinsondoyle/b0bca3f3de3a7d0f26b5402459b76545

Expected behavior

When dynamicValue is changed in any set member,
Then output file created by writeToFile is updated,
And the reload signal is sent to the managed process.

Actual behavior

When dynamicValue is changed in any set member,
Then output file created by writeToFile is updated,
And the reload signal is NOT sent to the managed process.

Steps to reproduce

Run consul template with example config, template and mock process. After first load, change one of the dynamic values in the k/v store.

It appears that because none of the template output is changed, then when CT diffs the output it determines reload is not necessary.

References

N/A

Mitigations

It appears that adding {{timestamp}} to the parent template forces a re-render with changes, thus triggering the reload. It isn't clear if this is an appropriate mitigation, as I am unsure if the reload could be triggered before all writeToFile outputs a written to disk.

Logs when run including timestamp in parent template: https://gist.github.com/davidatkinsondoyle/f36c4ac89120caa4a89c467c5d71a97c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant