mirror of https://github.com/status-im/consul.git
agent: ensure that we normalize bootstrapped config entries (#8547)
This commit is contained in:
parent
c2a28ba268
commit
b8cfef599c
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
agent: ensure that we normalize bootstrapped config entries
|
||||
```
|
|
@ -777,6 +777,9 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
|
|||
if err != nil {
|
||||
return RuntimeConfig{}, fmt.Errorf("config_entries.bootstrap[%d]: %s", i, err)
|
||||
}
|
||||
if err := entry.Normalize(); err != nil {
|
||||
return RuntimeConfig{}, fmt.Errorf("config_entries.bootstrap[%d]: %s", i, err)
|
||||
}
|
||||
if err := entry.Validate(); err != nil {
|
||||
return RuntimeConfig{}, fmt.Errorf("config_entries.bootstrap[%d]: %s", i, err)
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
|||
dataDir := testutil.TempDir(t, "consul")
|
||||
defer os.RemoveAll(dataDir)
|
||||
|
||||
defaultEntMeta := structs.DefaultEnterpriseMeta()
|
||||
|
||||
tests := []configTest{
|
||||
// ------------------------------------------------------------
|
||||
// cmd line flags
|
||||
|
@ -3288,17 +3290,15 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
|||
err: "config_entries.bootstrap[0]: invalid config entry kind: foo",
|
||||
},
|
||||
{
|
||||
desc: "ConfigEntry bootstrap invalid",
|
||||
desc: "ConfigEntry bootstrap invalid service-defaults",
|
||||
args: []string{`-data-dir=` + dataDir},
|
||||
json: []string{`{
|
||||
"config_entries": {
|
||||
"bootstrap": [
|
||||
{
|
||||
"kind": "proxy-defaults",
|
||||
"name": "invalid-name",
|
||||
"config": {
|
||||
"foo": "bar"
|
||||
}
|
||||
"kind": "service-defaults",
|
||||
"name": "web",
|
||||
"made_up_key": "blah"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -3306,14 +3306,12 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
|||
hcl: []string{`
|
||||
config_entries {
|
||||
bootstrap {
|
||||
kind = "proxy-defaults"
|
||||
name = "invalid-name"
|
||||
config {
|
||||
foo = "bar"
|
||||
}
|
||||
kind = "service-defaults"
|
||||
name = "web"
|
||||
made_up_key = "blah"
|
||||
}
|
||||
}`},
|
||||
err: "config_entries.bootstrap[0]: invalid name (\"invalid-name\"), only \"global\" is supported",
|
||||
err: "config_entries.bootstrap[0]: 1 error occurred:\n\t* invalid config key \"made_up_key\"\n\n",
|
||||
},
|
||||
{
|
||||
desc: "ConfigEntry bootstrap proxy-defaults (snake-case)",
|
||||
|
@ -3357,8 +3355,9 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
|||
rt.DataDir = dataDir
|
||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||
&structs.ProxyConfigEntry{
|
||||
Kind: structs.ProxyDefaults,
|
||||
Name: structs.ProxyConfigGlobal,
|
||||
Kind: structs.ProxyDefaults,
|
||||
Name: structs.ProxyConfigGlobal,
|
||||
EnterpriseMeta: *defaultEntMeta,
|
||||
Config: map[string]interface{}{
|
||||
"bar": "abc",
|
||||
"moreconfig": map[string]interface{}{
|
||||
|
@ -3414,8 +3413,9 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
|||
rt.DataDir = dataDir
|
||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||
&structs.ProxyConfigEntry{
|
||||
Kind: structs.ProxyDefaults,
|
||||
Name: structs.ProxyConfigGlobal,
|
||||
Kind: structs.ProxyDefaults,
|
||||
Name: structs.ProxyConfigGlobal,
|
||||
EnterpriseMeta: *defaultEntMeta,
|
||||
Config: map[string]interface{}{
|
||||
"bar": "abc",
|
||||
"moreconfig": map[string]interface{}{
|
||||
|
@ -3463,10 +3463,11 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
|||
rt.DataDir = dataDir
|
||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||
&structs.ServiceConfigEntry{
|
||||
Kind: structs.ServiceDefaults,
|
||||
Name: "web",
|
||||
Protocol: "http",
|
||||
ExternalSNI: "abc-123",
|
||||
Kind: structs.ServiceDefaults,
|
||||
Name: "web",
|
||||
EnterpriseMeta: *defaultEntMeta,
|
||||
Protocol: "http",
|
||||
ExternalSNI: "abc-123",
|
||||
MeshGateway: structs.MeshGatewayConfig{
|
||||
Mode: structs.MeshGatewayModeRemote,
|
||||
},
|
||||
|
@ -3508,10 +3509,11 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
|||
rt.DataDir = dataDir
|
||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||
&structs.ServiceConfigEntry{
|
||||
Kind: structs.ServiceDefaults,
|
||||
Name: "web",
|
||||
Protocol: "http",
|
||||
ExternalSNI: "abc-123",
|
||||
Kind: structs.ServiceDefaults,
|
||||
Name: "web",
|
||||
EnterpriseMeta: *defaultEntMeta,
|
||||
Protocol: "http",
|
||||
ExternalSNI: "abc-123",
|
||||
MeshGateway: structs.MeshGatewayConfig{
|
||||
Mode: structs.MeshGatewayModeRemote,
|
||||
},
|
||||
|
@ -3693,8 +3695,9 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
|||
rt.DataDir = dataDir
|
||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||
&structs.ServiceRouterConfigEntry{
|
||||
Kind: structs.ServiceRouter,
|
||||
Name: "main",
|
||||
Kind: structs.ServiceRouter,
|
||||
Name: "main",
|
||||
EnterpriseMeta: *defaultEntMeta,
|
||||
Routes: []structs.ServiceRoute{
|
||||
{
|
||||
Match: &structs.ServiceRouteMatch{
|
||||
|
@ -3774,6 +3777,8 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
|||
}
|
||||
},
|
||||
},
|
||||
// TODO(rb): add in missing tests for ingress-gateway (snake + camel)
|
||||
// TODO(rb): add in missing tests for terminating-gateway (snake + camel)
|
||||
|
||||
///////////////////////////////////
|
||||
// Defaults sanity checks
|
||||
|
@ -4390,6 +4395,8 @@ func TestFullConfig(t *testing.T) {
|
|||
return n
|
||||
}
|
||||
|
||||
defaultEntMeta := structs.DefaultEnterpriseMeta()
|
||||
|
||||
flagSrc := []string{`-dev`}
|
||||
src := map[string]string{
|
||||
"json": `{
|
||||
|
@ -5963,8 +5970,9 @@ func TestFullConfig(t *testing.T) {
|
|||
ClientAddrs: []*net.IPAddr{ipAddr("93.83.18.19")},
|
||||
ConfigEntryBootstrap: []structs.ConfigEntry{
|
||||
&structs.ProxyConfigEntry{
|
||||
Kind: structs.ProxyDefaults,
|
||||
Name: structs.ProxyConfigGlobal,
|
||||
Kind: structs.ProxyDefaults,
|
||||
Name: structs.ProxyConfigGlobal,
|
||||
EnterpriseMeta: *defaultEntMeta,
|
||||
Config: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
// has to be a float due to being a map[string]interface
|
||||
|
|
Loading…
Reference in New Issue