mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Allow client template config block to be parsed when using json config (#24007)
- Adds tests - Adds sample test data for parsing hcl and json - Adds changelog
This commit is contained in:
@@ -295,7 +295,7 @@ func extraKeys(c *Config) error {
|
||||
helper.RemoveEqualFold(&c.ExtraKeysHCL, "plugin")
|
||||
}
|
||||
|
||||
for _, k := range []string{"options", "meta", "chroot_env", "servers", "server_join"} {
|
||||
for _, k := range []string{"options", "meta", "chroot_env", "servers", "server_join", "template"} {
|
||||
helper.RemoveEqualFold(&c.ExtraKeysHCL, k)
|
||||
helper.RemoveEqualFold(&c.ExtraKeysHCL, "client")
|
||||
}
|
||||
@@ -315,6 +315,12 @@ func extraKeys(c *Config) error {
|
||||
helper.RemoveEqualFold(&c.Client.ExtraKeysHCL, "host_network")
|
||||
}
|
||||
|
||||
// Remove Template extra keys
|
||||
for _, t := range []string{"function_denylist", "disable_file_sandbox", "max_stale", "wait", "wait_bounds", "block_query_wait", "consul_retry", "vault_retry", "nomad_retry"} {
|
||||
helper.RemoveEqualFold(&c.Client.ExtraKeysHCL, t)
|
||||
helper.RemoveEqualFold(&c.Client.ExtraKeysHCL, "template")
|
||||
}
|
||||
|
||||
// Remove AuditConfig extra keys
|
||||
for _, f := range c.Audit.Filters {
|
||||
helper.RemoveEqualFold(&c.Audit.ExtraKeysHCL, f.Name)
|
||||
|
||||
@@ -1146,3 +1146,44 @@ func TestConfig_Telemetry(t *testing.T) {
|
||||
must.Eq(t, mergedTelemetry2.inMemoryCollectionInterval, 1*time.Second)
|
||||
must.Eq(t, mergedTelemetry2.inMemoryRetentionPeriod, 10*time.Second)
|
||||
}
|
||||
|
||||
func TestConfig_Template(t *testing.T) {
|
||||
ci.Parallel(t)
|
||||
|
||||
for _, suffix := range []string{"hcl", "json"} {
|
||||
t.Run(suffix, func(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
fc, err := LoadConfig("testdata/template." + suffix)
|
||||
must.NoError(t, err)
|
||||
cfg = cfg.Merge(fc)
|
||||
|
||||
must.Eq(t, []string{"plugin"}, cfg.Client.TemplateConfig.FunctionDenylist)
|
||||
must.True(t, cfg.Client.TemplateConfig.DisableSandbox)
|
||||
must.Eq(t, pointer.Of(7600*time.Hour), cfg.Client.TemplateConfig.MaxStale)
|
||||
must.Eq(t, pointer.Of(10*time.Minute), cfg.Client.TemplateConfig.BlockQueryWaitTime)
|
||||
|
||||
must.NotNil(t, cfg.Client.TemplateConfig.Wait)
|
||||
must.Eq(t, pointer.Of(10*time.Second), cfg.Client.TemplateConfig.Wait.Min)
|
||||
must.Eq(t, pointer.Of(10*time.Minute), cfg.Client.TemplateConfig.Wait.Max)
|
||||
|
||||
must.NotNil(t, cfg.Client.TemplateConfig.WaitBounds)
|
||||
must.Eq(t, pointer.Of(1*time.Second), cfg.Client.TemplateConfig.WaitBounds.Min)
|
||||
must.Eq(t, pointer.Of(10*time.Hour), cfg.Client.TemplateConfig.WaitBounds.Max)
|
||||
|
||||
must.NotNil(t, cfg.Client.TemplateConfig.ConsulRetry)
|
||||
must.Eq(t, 6, *cfg.Client.TemplateConfig.ConsulRetry.Attempts)
|
||||
must.Eq(t, pointer.Of(550*time.Millisecond), cfg.Client.TemplateConfig.ConsulRetry.Backoff)
|
||||
must.Eq(t, pointer.Of(10*time.Minute), cfg.Client.TemplateConfig.ConsulRetry.MaxBackoff)
|
||||
|
||||
must.NotNil(t, cfg.Client.TemplateConfig.VaultRetry)
|
||||
must.Eq(t, 6, *cfg.Client.TemplateConfig.VaultRetry.Attempts)
|
||||
must.Eq(t, pointer.Of(550*time.Millisecond), cfg.Client.TemplateConfig.VaultRetry.Backoff)
|
||||
must.Eq(t, pointer.Of(10*time.Minute), cfg.Client.TemplateConfig.VaultRetry.MaxBackoff)
|
||||
|
||||
must.NotNil(t, cfg.Client.TemplateConfig.NomadRetry)
|
||||
must.Eq(t, 6, *cfg.Client.TemplateConfig.NomadRetry.Attempts)
|
||||
must.Eq(t, pointer.Of(550*time.Millisecond), cfg.Client.TemplateConfig.NomadRetry.Backoff)
|
||||
must.Eq(t, pointer.Of(10*time.Minute), cfg.Client.TemplateConfig.NomadRetry.MaxBackoff)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
37
command/agent/testdata/template.hcl
vendored
Normal file
37
command/agent/testdata/template.hcl
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
client {
|
||||
template {
|
||||
function_denylist = ["plugin"]
|
||||
disable_file_sandbox = true
|
||||
max_stale = "7600h"
|
||||
|
||||
wait {
|
||||
min = "10s"
|
||||
max = "10m"
|
||||
}
|
||||
|
||||
wait_bounds {
|
||||
min = "1s"
|
||||
max = "10h"
|
||||
}
|
||||
|
||||
block_query_wait = "10m"
|
||||
|
||||
consul_retry {
|
||||
attempts = 6
|
||||
backoff = "550ms"
|
||||
max_backoff = "10m"
|
||||
}
|
||||
|
||||
vault_retry {
|
||||
attempts = 6
|
||||
backoff = "550ms"
|
||||
max_backoff = "10m"
|
||||
}
|
||||
|
||||
nomad_retry {
|
||||
attempts = 6
|
||||
backoff = "550ms"
|
||||
max_backoff = "10m"
|
||||
}
|
||||
}
|
||||
}
|
||||
33
command/agent/testdata/template.json
vendored
Normal file
33
command/agent/testdata/template.json
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"client": {
|
||||
"template": {
|
||||
"function_denylist": ["plugin"],
|
||||
"disable_file_sandbox": true,
|
||||
"max_stale": "7600h",
|
||||
"wait": {
|
||||
"min": "10s",
|
||||
"max": "10m"
|
||||
},
|
||||
"wait_bounds": {
|
||||
"min": "1s",
|
||||
"max": "10h"
|
||||
},
|
||||
"block_query_wait": "10m",
|
||||
"consul_retry": {
|
||||
"attempts": 6,
|
||||
"backoff": "550ms",
|
||||
"max_backoff": "10m"
|
||||
},
|
||||
"vault_retry": {
|
||||
"attempts": 6,
|
||||
"backoff": "550ms",
|
||||
"max_backoff": "10m"
|
||||
},
|
||||
"nomad_retry": {
|
||||
"attempts": 6,
|
||||
"backoff": "550ms",
|
||||
"max_backoff": "10m"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user