agent/template: fix exec parsing error for templates (#16231)
* agent/template: fix exec parsing error for templates * changelog
This commit is contained in:
parent
c70a2cd198
commit
110f754d97
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
agent/template: Fix parsing error for the exec stanza
|
||||||
|
```
|
|
@ -678,19 +678,24 @@ func parseTemplates(result *Config, list *ast.ObjectList) error {
|
||||||
return errors.New("error converting config")
|
return errors.New("error converting config")
|
||||||
}
|
}
|
||||||
|
|
||||||
// flatten the wait field. The initial "wait" value, if given, is a
|
// flatten the wait or exec fields. The initial "wait" or "exec" value, if given, is a
|
||||||
// []map[string]interface{}, but we need it to be map[string]interface{}.
|
// []map[string]interface{}, but we need it to be map[string]interface{}.
|
||||||
// Consul Template has a method flattenKeys that walks all of parsed and
|
// Consul Template has a method flattenKeys that walks all of parsed and
|
||||||
// flattens every key. For Vault Agent, we only care about the wait input.
|
// flattens every key. For Vault Agent, we only care about the wait input.
|
||||||
// Only one wait stanza is supported, however Consul Template does not error
|
// Only one wait/exec stanza is supported, however Consul Template does not error
|
||||||
// with multiple instead it flattens them down, with last value winning.
|
// with multiple instead it flattens them down, with last value winning.
|
||||||
// Here we take the last element of the parsed["wait"] slice to keep
|
// Here we take the last element of the parsed["wait"] or parsed["exec"] slice to keep
|
||||||
// consistency with Consul Template behavior.
|
// consistency with Consul Template behavior.
|
||||||
wait, ok := parsed["wait"].([]map[string]interface{})
|
wait, ok := parsed["wait"].([]map[string]interface{})
|
||||||
if ok {
|
if ok {
|
||||||
parsed["wait"] = wait[len(wait)-1]
|
parsed["wait"] = wait[len(wait)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exec, ok := parsed["exec"].([]map[string]interface{})
|
||||||
|
if ok {
|
||||||
|
parsed["exec"] = exec[len(exec)-1]
|
||||||
|
}
|
||||||
|
|
||||||
var tc ctconfig.TemplateConfig
|
var tc ctconfig.TemplateConfig
|
||||||
|
|
||||||
// Use mapstructure to populate the basic config fields
|
// Use mapstructure to populate the basic config fields
|
||||||
|
|
|
@ -728,6 +728,10 @@ func TestLoadConfigFile_Template(t *testing.T) {
|
||||||
Perms: pointerutil.FileModePtr(0o655),
|
Perms: pointerutil.FileModePtr(0o655),
|
||||||
RightDelim: pointerutil.StringPtr(">>"),
|
RightDelim: pointerutil.StringPtr(">>"),
|
||||||
SandboxPath: pointerutil.StringPtr("/path/on/disk/where"),
|
SandboxPath: pointerutil.StringPtr("/path/on/disk/where"),
|
||||||
|
Exec: &ctconfig.ExecConfig{
|
||||||
|
Command: []string{"foo"},
|
||||||
|
Timeout: pointerutil.TimeDurationPtr("10s"),
|
||||||
|
},
|
||||||
|
|
||||||
Wait: &ctconfig.WaitConfig{
|
Wait: &ctconfig.WaitConfig{
|
||||||
Min: pointerutil.TimeDurationPtr("10s"),
|
Min: pointerutil.TimeDurationPtr("10s"),
|
||||||
|
|
|
@ -46,4 +46,9 @@ template {
|
||||||
min = "10s"
|
min = "10s"
|
||||||
max = "40s"
|
max = "40s"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exec {
|
||||||
|
command = ["foo"]
|
||||||
|
timeout = "10s"
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue