Browse Source

Let users know namespaces are ent only in config entry decode

pull/8169/head
freddygv 4 years ago
parent
commit
70810b0602
  1. 7
      agent/structs/config_entry.go
  2. 53
      agent/structs/config_entry_test.go

7
agent/structs/config_entry.go

@ -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))
}

53
agent/structs/config_entry_test.go

@ -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: `

Loading…
Cancel
Save