From 71b0f0a7a6ed6dd393ce4a9658c0d48128130bc4 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 22 Feb 2021 12:50:52 -0500 Subject: [PATCH] structs: remove EnterpriseMeta.GetNamespace I added this recently without realizing that the method already existed and was named NamespaceOrEmpty. Replace all calls to GetNamespace with NamespaceOrEmpty or NamespaceOrDefault as appropriate. --- agent/cache-types/streaming_health_services.go | 2 +- .../cache-types/streaming_health_services_test.go | 2 +- agent/consul/state/catalog_events.go | 14 +++++++------- agent/consul/state/catalog_events_test.go | 2 +- agent/rpc/subscribe/subscribe.go | 2 +- agent/structs/structs_oss.go | 5 ----- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/agent/cache-types/streaming_health_services.go b/agent/cache-types/streaming_health_services.go index ad11dc6267..6491383456 100644 --- a/agent/cache-types/streaming_health_services.go +++ b/agent/cache-types/streaming_health_services.go @@ -75,7 +75,7 @@ func (c *StreamingHealthServices) Fetch(opts cache.FetchOptions, req cache.Reque Token: srvReq.Token, Datacenter: srvReq.Datacenter, Index: index, - Namespace: srvReq.EnterpriseMeta.GetNamespace(), + Namespace: srvReq.EnterpriseMeta.NamespaceOrEmpty(), } if srvReq.Connect { req.Topic = pbsubscribe.Topic_ServiceHealthConnect diff --git a/agent/cache-types/streaming_health_services_test.go b/agent/cache-types/streaming_health_services_test.go index e361d06a54..9d7193a424 100644 --- a/agent/cache-types/streaming_health_services_test.go +++ b/agent/cache-types/streaming_health_services_test.go @@ -229,7 +229,7 @@ func requireResultsSame(t *testing.T, want, got *structs.IndexedCheckServiceNode // without duplicating the tests. func getNamespace(ns string) string { meta := structs.NewEnterpriseMeta(ns) - return meta.GetNamespace() + return meta.NamespaceOrEmpty() } func TestOrderingConsistentWithMemDb(t *testing.T) { diff --git a/agent/consul/state/catalog_events.go b/agent/consul/state/catalog_events.go index 9c9b4de988..5d6c1308fb 100644 --- a/agent/consul/state/catalog_events.go +++ b/agent/consul/state/catalog_events.go @@ -44,7 +44,7 @@ func (e EventPayloadCheckServiceNode) MatchesKey(key, namespace string) bool { if e.overrideKey != "" { name = e.overrideKey } - ns := e.Value.Service.EnterpriseMeta.GetNamespace() + ns := e.Value.Service.EnterpriseMeta.NamespaceOrDefault() if e.overrideNamespace != "" { ns = e.overrideNamespace } @@ -315,8 +315,8 @@ func ServiceHealthEventsFromChanges(tx ReadTxn, changes Changes) ([]stream.Event e.Topic = topicServiceHealthConnect payload := e.Payload.(EventPayloadCheckServiceNode) payload.overrideKey = serviceName.Name - if gatewayName.EnterpriseMeta.GetNamespace() != serviceName.EnterpriseMeta.GetNamespace() { - payload.overrideNamespace = serviceName.EnterpriseMeta.GetNamespace() + if gatewayName.EnterpriseMeta.NamespaceOrDefault() != serviceName.EnterpriseMeta.NamespaceOrDefault() { + payload.overrideNamespace = serviceName.EnterpriseMeta.NamespaceOrDefault() } e.Payload = payload @@ -339,8 +339,8 @@ func ServiceHealthEventsFromChanges(tx ReadTxn, changes Changes) ([]stream.Event e.Topic = topicServiceHealthConnect payload := e.Payload.(EventPayloadCheckServiceNode) payload.overrideKey = serviceName.Name - if gatewayName.EnterpriseMeta.GetNamespace() != serviceName.EnterpriseMeta.GetNamespace() { - payload.overrideNamespace = serviceName.EnterpriseMeta.GetNamespace() + if gatewayName.EnterpriseMeta.NamespaceOrDefault() != serviceName.EnterpriseMeta.NamespaceOrDefault() { + payload.overrideNamespace = serviceName.EnterpriseMeta.NamespaceOrDefault() } e.Payload = payload @@ -470,8 +470,8 @@ func copyEventForService(event stream.Event, service structs.ServiceName) stream event.Topic = topicServiceHealthConnect payload := event.Payload.(EventPayloadCheckServiceNode) payload.overrideKey = service.Name - if payload.Value.Service.EnterpriseMeta.GetNamespace() != service.EnterpriseMeta.GetNamespace() { - payload.overrideNamespace = service.EnterpriseMeta.GetNamespace() + if payload.Value.Service.EnterpriseMeta.NamespaceOrDefault() != service.EnterpriseMeta.NamespaceOrDefault() { + payload.overrideNamespace = service.EnterpriseMeta.NamespaceOrDefault() } event.Payload = payload diff --git a/agent/consul/state/catalog_events_test.go b/agent/consul/state/catalog_events_test.go index 9aa82062e8..de7a266f0b 100644 --- a/agent/consul/state/catalog_events_test.go +++ b/agent/consul/state/catalog_events_test.go @@ -1666,7 +1666,7 @@ var cmpPartialOrderEvents = cmp.Options{ if payload.overrideKey != "" { name = payload.overrideKey } - ns := csn.Service.EnterpriseMeta.GetNamespace() + ns := csn.Service.EnterpriseMeta.NamespaceOrDefault() if payload.overrideNamespace != "" { ns = payload.overrideNamespace } diff --git a/agent/rpc/subscribe/subscribe.go b/agent/rpc/subscribe/subscribe.go index bb1ccdb0ec..71bede729d 100644 --- a/agent/rpc/subscribe/subscribe.go +++ b/agent/rpc/subscribe/subscribe.go @@ -95,7 +95,7 @@ func toStreamSubscribeRequest(req *pbsubscribe.SubscribeRequest, entMeta structs Key: req.Key, Token: req.Token, Index: req.Index, - Namespace: entMeta.GetNamespace(), + Namespace: entMeta.NamespaceOrEmpty(), } } diff --git a/agent/structs/structs_oss.go b/agent/structs/structs_oss.go index 5d9562631b..def44b1590 100644 --- a/agent/structs/structs_oss.go +++ b/agent/structs/structs_oss.go @@ -74,11 +74,6 @@ func (_ *EnterpriseMeta) FillAuthzContext(_ *acl.AuthorizerContext) {} func (_ *EnterpriseMeta) Normalize() {} -// GetNamespace always returns the empty string. -func (_ *EnterpriseMeta) GetNamespace() string { - return "" -} - // FillAuthzContext stub func (_ *DirEntry) FillAuthzContext(_ *acl.AuthorizerContext) {}