From 8bb16567cd92c76080f0cc48a6e5405bfd068fad Mon Sep 17 00:00:00 2001 From: Eric Haberkorn Date: Fri, 12 May 2023 16:49:42 -0400 Subject: [PATCH] sidecar-proxy refactor (#17328) --- agent/consul/state/config_entry_exported_services.go | 1 + .../grpc-external/services/peerstream/subscription_manager.go | 2 +- agent/sidecar_service.go | 4 ++-- agent/structs/structs.go | 2 ++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/agent/consul/state/config_entry_exported_services.go b/agent/consul/state/config_entry_exported_services.go index 77b8ce78cf..b758adc09e 100644 --- a/agent/consul/state/config_entry_exported_services.go +++ b/agent/consul/state/config_entry_exported_services.go @@ -33,6 +33,7 @@ func (e *SimplifiedExportedServices) ToPartitionMap() map[string]map[string][]st } } resp[svc.Namespace][svc.Name] = consumers + resp[svc.Namespace][svc.Name+structs.SidecarProxySuffix] = consumers } } return resp diff --git a/agent/grpc-external/services/peerstream/subscription_manager.go b/agent/grpc-external/services/peerstream/subscription_manager.go index 42a4d13925..4fcd27635b 100644 --- a/agent/grpc-external/services/peerstream/subscription_manager.go +++ b/agent/grpc-external/services/peerstream/subscription_manager.go @@ -747,7 +747,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 e0b1fe1d2b..1769e549e3 100644 --- a/agent/sidecar_service.go +++ b/agent/sidecar_service.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/consul/agent/structs" ) -const sidecarIDSuffix = "-sidecar-proxy" +const sidecarIDSuffix = structs.SidecarProxySuffix func sidecarIDFromServiceID(serviceID string) string { return serviceID + sidecarIDSuffix @@ -96,7 +96,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/structs.go b/agent/structs/structs.go index 1771b18be0..f36a5b77c4 100644 --- a/agent/structs/structs.go +++ b/agent/structs/structs.go @@ -1270,6 +1270,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