agent: ensure that we normalize bootstrapped config entries (#8547)
This commit is contained in:
parent
106e1d50bd
commit
a7a8b8d6d9
|
@ -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 {
|
if err != nil {
|
||||||
return RuntimeConfig{}, fmt.Errorf("config_entries.bootstrap[%d]: %s", i, err)
|
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 {
|
if err := entry.Validate(); err != nil {
|
||||||
return RuntimeConfig{}, fmt.Errorf("config_entries.bootstrap[%d]: %s", i, err)
|
return RuntimeConfig{}, fmt.Errorf("config_entries.bootstrap[%d]: %s", i, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,8 @@ type configTest struct {
|
||||||
func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
dataDir := testutil.TempDir(t, "consul")
|
dataDir := testutil.TempDir(t, "consul")
|
||||||
|
|
||||||
|
defaultEntMeta := structs.DefaultEnterpriseMeta()
|
||||||
|
|
||||||
tests := []configTest{
|
tests := []configTest{
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
// cmd line flags
|
// cmd line flags
|
||||||
|
@ -3286,17 +3288,15 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
err: "config_entries.bootstrap[0]: invalid config entry kind: foo",
|
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},
|
args: []string{`-data-dir=` + dataDir},
|
||||||
json: []string{`{
|
json: []string{`{
|
||||||
"config_entries": {
|
"config_entries": {
|
||||||
"bootstrap": [
|
"bootstrap": [
|
||||||
{
|
{
|
||||||
"kind": "proxy-defaults",
|
"kind": "service-defaults",
|
||||||
"name": "invalid-name",
|
"name": "web",
|
||||||
"config": {
|
"made_up_key": "blah"
|
||||||
"foo": "bar"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -3304,14 +3304,12 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
hcl: []string{`
|
hcl: []string{`
|
||||||
config_entries {
|
config_entries {
|
||||||
bootstrap {
|
bootstrap {
|
||||||
kind = "proxy-defaults"
|
kind = "service-defaults"
|
||||||
name = "invalid-name"
|
name = "web"
|
||||||
config {
|
made_up_key = "blah"
|
||||||
foo = "bar"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}`},
|
}`},
|
||||||
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)",
|
desc: "ConfigEntry bootstrap proxy-defaults (snake-case)",
|
||||||
|
@ -3355,8 +3353,9 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
rt.DataDir = dataDir
|
rt.DataDir = dataDir
|
||||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||||
&structs.ProxyConfigEntry{
|
&structs.ProxyConfigEntry{
|
||||||
Kind: structs.ProxyDefaults,
|
Kind: structs.ProxyDefaults,
|
||||||
Name: structs.ProxyConfigGlobal,
|
Name: structs.ProxyConfigGlobal,
|
||||||
|
EnterpriseMeta: *defaultEntMeta,
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"bar": "abc",
|
"bar": "abc",
|
||||||
"moreconfig": map[string]interface{}{
|
"moreconfig": map[string]interface{}{
|
||||||
|
@ -3412,8 +3411,9 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
rt.DataDir = dataDir
|
rt.DataDir = dataDir
|
||||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||||
&structs.ProxyConfigEntry{
|
&structs.ProxyConfigEntry{
|
||||||
Kind: structs.ProxyDefaults,
|
Kind: structs.ProxyDefaults,
|
||||||
Name: structs.ProxyConfigGlobal,
|
Name: structs.ProxyConfigGlobal,
|
||||||
|
EnterpriseMeta: *defaultEntMeta,
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"bar": "abc",
|
"bar": "abc",
|
||||||
"moreconfig": map[string]interface{}{
|
"moreconfig": map[string]interface{}{
|
||||||
|
@ -3461,10 +3461,11 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
rt.DataDir = dataDir
|
rt.DataDir = dataDir
|
||||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||||
&structs.ServiceConfigEntry{
|
&structs.ServiceConfigEntry{
|
||||||
Kind: structs.ServiceDefaults,
|
Kind: structs.ServiceDefaults,
|
||||||
Name: "web",
|
Name: "web",
|
||||||
Protocol: "http",
|
EnterpriseMeta: *defaultEntMeta,
|
||||||
ExternalSNI: "abc-123",
|
Protocol: "http",
|
||||||
|
ExternalSNI: "abc-123",
|
||||||
MeshGateway: structs.MeshGatewayConfig{
|
MeshGateway: structs.MeshGatewayConfig{
|
||||||
Mode: structs.MeshGatewayModeRemote,
|
Mode: structs.MeshGatewayModeRemote,
|
||||||
},
|
},
|
||||||
|
@ -3506,10 +3507,11 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
rt.DataDir = dataDir
|
rt.DataDir = dataDir
|
||||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||||
&structs.ServiceConfigEntry{
|
&structs.ServiceConfigEntry{
|
||||||
Kind: structs.ServiceDefaults,
|
Kind: structs.ServiceDefaults,
|
||||||
Name: "web",
|
Name: "web",
|
||||||
Protocol: "http",
|
EnterpriseMeta: *defaultEntMeta,
|
||||||
ExternalSNI: "abc-123",
|
Protocol: "http",
|
||||||
|
ExternalSNI: "abc-123",
|
||||||
MeshGateway: structs.MeshGatewayConfig{
|
MeshGateway: structs.MeshGatewayConfig{
|
||||||
Mode: structs.MeshGatewayModeRemote,
|
Mode: structs.MeshGatewayModeRemote,
|
||||||
},
|
},
|
||||||
|
@ -3691,8 +3693,9 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
rt.DataDir = dataDir
|
rt.DataDir = dataDir
|
||||||
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
rt.ConfigEntryBootstrap = []structs.ConfigEntry{
|
||||||
&structs.ServiceRouterConfigEntry{
|
&structs.ServiceRouterConfigEntry{
|
||||||
Kind: structs.ServiceRouter,
|
Kind: structs.ServiceRouter,
|
||||||
Name: "main",
|
Name: "main",
|
||||||
|
EnterpriseMeta: *defaultEntMeta,
|
||||||
Routes: []structs.ServiceRoute{
|
Routes: []structs.ServiceRoute{
|
||||||
{
|
{
|
||||||
Match: &structs.ServiceRouteMatch{
|
Match: &structs.ServiceRouteMatch{
|
||||||
|
@ -3772,6 +3775,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
|
// Defaults sanity checks
|
||||||
|
@ -4380,6 +4385,8 @@ func TestFullConfig(t *testing.T) {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defaultEntMeta := structs.DefaultEnterpriseMeta()
|
||||||
|
|
||||||
flagSrc := []string{`-dev`}
|
flagSrc := []string{`-dev`}
|
||||||
src := map[string]string{
|
src := map[string]string{
|
||||||
"json": `{
|
"json": `{
|
||||||
|
@ -5953,8 +5960,9 @@ func TestFullConfig(t *testing.T) {
|
||||||
ClientAddrs: []*net.IPAddr{ipAddr("93.83.18.19")},
|
ClientAddrs: []*net.IPAddr{ipAddr("93.83.18.19")},
|
||||||
ConfigEntryBootstrap: []structs.ConfigEntry{
|
ConfigEntryBootstrap: []structs.ConfigEntry{
|
||||||
&structs.ProxyConfigEntry{
|
&structs.ProxyConfigEntry{
|
||||||
Kind: structs.ProxyDefaults,
|
Kind: structs.ProxyDefaults,
|
||||||
Name: structs.ProxyConfigGlobal,
|
Name: structs.ProxyConfigGlobal,
|
||||||
|
EnterpriseMeta: *defaultEntMeta,
|
||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
// has to be a float due to being a map[string]interface
|
// has to be a float due to being a map[string]interface
|
||||||
|
|
Loading…
Reference in New Issue