Update IsEmpty to check for pre-1.2.4 fields (#11930)

This commit is contained in:
Derek Strickland 2022-01-26 11:31:37 -05:00 committed by Tim Gross
parent 7b5ee8a3f3
commit 460416e787
5 changed files with 61 additions and 1 deletions

4
.changelog/11902.txt Normal file
View File

@ -0,0 +1,4 @@
```release-note:bug
template: Fixed a bug where client template configuration that did not include any
of the new 1.2.4 configuration options could result in none of the configuration getting set.
```

View File

@ -450,7 +450,10 @@ func (c *ClientTemplateConfig) IsEmpty() bool {
return true return true
} }
return c.BlockQueryWaitTime == nil && return !c.DisableSandbox &&
len(c.FunctionDenylist) == 0 &&
len(c.FunctionBlacklist) == 0 &&
c.BlockQueryWaitTime == nil &&
c.BlockQueryWaitTimeHCL == "" && c.BlockQueryWaitTimeHCL == "" &&
c.MaxStale == nil && c.MaxStale == nil &&
c.MaxStaleHCL == "" && c.MaxStaleHCL == "" &&

View File

@ -1413,6 +1413,41 @@ func TestConfig_LoadConsulTemplateConfig(t *testing.T) {
require.Equal(t, 20*time.Second, *templateConfig.VaultRetry.MaxBackoff) require.Equal(t, 20*time.Second, *templateConfig.VaultRetry.MaxBackoff)
} }
func TestConfig_LoadConsulTemplateBasic(t *testing.T) {
defaultConfig := DefaultConfig()
// hcl
agentConfig, err := LoadConfig("test-resources/client_with_basic_template.hcl")
require.NoError(t, err)
require.NotNil(t, agentConfig.Client.TemplateConfig)
agentConfig = defaultConfig.Merge(agentConfig)
clientAgent := Agent{config: agentConfig}
clientConfig, err := clientAgent.clientConfig()
require.NoError(t, err)
templateConfig := clientConfig.TemplateConfig
require.NotNil(t, templateConfig)
require.True(t, templateConfig.DisableSandbox)
require.Len(t, templateConfig.FunctionDenylist, 1)
// json
agentConfig, err = LoadConfig("test-resources/client_with_basic_template.json")
require.NoError(t, err)
agentConfig = defaultConfig.Merge(agentConfig)
clientAgent = Agent{config: agentConfig}
clientConfig, err = clientAgent.clientConfig()
require.NoError(t, err)
templateConfig = clientConfig.TemplateConfig
require.NotNil(t, templateConfig)
require.True(t, templateConfig.DisableSandbox)
require.Len(t, templateConfig.FunctionDenylist, 1)
}
func TestParseMultipleIPTemplates(t *testing.T) { func TestParseMultipleIPTemplates(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string

View File

@ -0,0 +1,9 @@
client {
enabled = true
template {
disable_file_sandbox = true
function_denylist = []
}
}

View File

@ -0,0 +1,9 @@
{
"client": {
"enabled": true,
"template": {
"disable_file_sandbox": true,
"function_denylist": []
}
}
}