From 70810b060292c7588795520d1e0cd6a17d6853ec Mon Sep 17 00:00:00 2001 From: freddygv Date: Mon, 22 Jun 2020 19:04:15 -0600 Subject: [PATCH] Let users know namespaces are ent only in config entry decode --- agent/structs/config_entry.go | 7 ++-- agent/structs/config_entry_test.go | 53 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/agent/structs/config_entry.go b/agent/structs/config_entry.go index 922076a82d..5a5536094e 100644 --- a/agent/structs/config_entry.go +++ b/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)) } diff --git a/agent/structs/config_entry_test.go b/agent/structs/config_entry_test.go index 9f699aa2c0..1819f64c49 100644 --- a/agent/structs/config_entry_test.go +++ b/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: `