From 29f7c23a1d04f8fcca0181e71aff9deb6826e81e Mon Sep 17 00:00:00 2001 From: Eric Haberkorn Date: Mon, 15 May 2023 13:31:16 -0400 Subject: [PATCH] sidecar-proxy refactor (#17336) (#17366) --- .../grpc-external/services/peerstream/subscription_manager.go | 2 +- agent/sidecar_service.go | 4 ++-- agent/structs/config_entry_exports.go | 1 + agent/structs/structs.go | 2 ++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/agent/grpc-external/services/peerstream/subscription_manager.go b/agent/grpc-external/services/peerstream/subscription_manager.go index a209b2b39f5e..007b51bb4512 100644 --- a/agent/grpc-external/services/peerstream/subscription_manager.go +++ b/agent/grpc-external/services/peerstream/subscription_manager.go @@ -744,7 +744,7 @@ func (m *subscriptionManager) NotifyStandardService( // // This name was chosen to match existing "sidecar service" generation logic // and similar logic in the Service Identity synthetic ACL policies. -const syntheticProxyNameSuffix = "-sidecar-proxy" +const syntheticProxyNameSuffix = structs.SidecarProxySuffix func generateProxyNameForDiscoveryChain(sn structs.ServiceName) structs.ServiceName { return structs.NewServiceName(sn.Name+syntheticProxyNameSuffix, &sn.EnterpriseMeta) diff --git a/agent/sidecar_service.go b/agent/sidecar_service.go index 3b536223ffb1..6cd6d294e532 100644 --- a/agent/sidecar_service.go +++ b/agent/sidecar_service.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/consul/agent/structs" ) -const sidecarIDSuffix = "-sidecar-proxy" +const sidecarIDSuffix = structs.SidecarProxySuffix func sidecarIDFromServiceID(serviceID string) string { return serviceID + sidecarIDSuffix @@ -93,7 +93,7 @@ func sidecarServiceFromNodeService(ns *structs.NodeService, token string) (*stru sidecar.Kind = structs.ServiceKindConnectProxy } if sidecar.Service == "" { - sidecar.Service = ns.Service + "-sidecar-proxy" + sidecar.Service = ns.Service + structs.SidecarProxySuffix } if sidecar.Address == "" { // Inherit address from the service if it's provided diff --git a/agent/structs/config_entry_exports.go b/agent/structs/config_entry_exports.go index 81c62e1236d1..958e6a241969 100644 --- a/agent/structs/config_entry_exports.go +++ b/agent/structs/config_entry_exports.go @@ -57,6 +57,7 @@ func (e *ExportedServicesConfigEntry) ToMap() map[string]map[string][]string { consumers = append(consumers, c.Partition) } resp[svc.Namespace][svc.Name] = consumers + resp[svc.Namespace][svc.Name+SidecarProxySuffix] = consumers } } return resp diff --git a/agent/structs/structs.go b/agent/structs/structs.go index fea6da365b80..34c041d587c2 100644 --- a/agent/structs/structs.go +++ b/agent/structs/structs.go @@ -1245,6 +1245,8 @@ func (a ServiceAddress) ToAPIServiceAddress() api.ServiceAddress { return api.ServiceAddress{Address: a.Address, Port: a.Port} } +const SidecarProxySuffix = "-sidecar-proxy" + // NodeService is a service provided by a node type NodeService struct { // Kind is the kind of service this is. Different kinds of services may