Let users know namespaces are ent only in config entry decode

This commit is contained in:
freddygv 2020-06-22 19:04:15 -06:00
parent 146afbe9a2
commit e81b6d25ad
2 changed files with 58 additions and 2 deletions

View File

@ -306,8 +306,11 @@ func DecodeConfigEntry(raw map[string]interface{}) (ConfigEntry, error) {
}
for _, k := range md.Unused {
switch k {
case "CreateIndex", "ModifyIndex":
switch {
case k == "CreateIndex" || k == "ModifyIndex":
break
case strings.HasSuffix(strings.ToLower(k), "namespace"):
err = multierror.Append(err, fmt.Errorf("invalid config key %q, namespaces is a consul enterprise feature", k))
default:
err = multierror.Append(err, fmt.Errorf("invalid config key %q", k))
}

View File

@ -86,6 +86,59 @@ func TestDecodeConfigEntry(t *testing.T) {
},
},
},
{
name: "namespaces invalid top level",
snake: `
kind = "terminating-gateway"
name = "terminating-gateway"
namespace = "foo"
`,
camel: `
Kind = "terminating-gateway"
Name = "terminating-gateway"
Namespace = "foo"
`,
expectErr: `invalid config key "namespace", namespaces is a consul enterprise feature`,
},
{
name: "namespaces invalid deep",
snake: `
kind = "ingress-gateway"
name = "ingress-web"
listeners = [
{
port = 8080
protocol = "http"
services = [
{
name = "web"
hosts = ["test.example.com", "test2.example.com"]
namespace = "frontend"
},
]
}
]
`,
camel: `
Kind = "ingress-gateway"
Name = "ingress-web"
Namespace = "blah"
Listeners = [
{
Port = 8080
Protocol = "http"
Services = [
{
Name = "web"
Hosts = ["test.example.com", "test2.example.com"]
Namespace = "frontend"
},
]
},
]
`,
expectErr: `invalid config key "listeners[0].services[0].namespace", namespaces is a consul enterprise feature`,
},
{
name: "service-defaults",
snake: `