Move compound service names to use ServiceName type

This commit is contained in:
freddygv 2020-06-12 08:57:41 -06:00
parent e7b52d35d4
commit 19e3954603
25 changed files with 439 additions and 372 deletions

View File

@ -27,8 +27,8 @@ func TestGatewayServices(t *testing.T) {
services := structs.GatewayServices{ services := structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 1234, Port: 1234,
CAFile: "api/ca.crt", CAFile: "api/ca.crt",

View File

@ -1406,8 +1406,8 @@ func TestCatalog_GatewayServices_Terminating(t *testing.T) {
expect := structs.GatewayServices{ expect := structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("terminating", nil), Gateway: structs.NewServiceName("terminating", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "api/ca.crt", CAFile: "api/ca.crt",
CertFile: "api/client.crt", CertFile: "api/client.crt",
@ -1415,8 +1415,8 @@ func TestCatalog_GatewayServices_Terminating(t *testing.T) {
SNI: "my-domain", SNI: "my-domain",
}, },
{ {
Service: structs.NewServiceID("redis", nil), Service: structs.NewServiceName("redis", nil),
Gateway: structs.NewServiceID("terminating", nil), Gateway: structs.NewServiceName("terminating", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "ca.crt", CAFile: "ca.crt",
CertFile: "client.crt", CertFile: "client.crt",
@ -1521,15 +1521,15 @@ func TestCatalog_GatewayServices_Ingress(t *testing.T) {
expect := structs.GatewayServices{ expect := structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("ingress", nil), Gateway: structs.NewServiceName("ingress", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Protocol: "tcp", Protocol: "tcp",
Port: 8888, Port: 8888,
}, },
{ {
Service: structs.NewServiceID("redis", nil), Service: structs.NewServiceName("redis", nil),
Gateway: structs.NewServiceID("ingress", nil), Gateway: structs.NewServiceName("ingress", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Protocol: "tcp", Protocol: "tcp",
Port: 9999, Port: 9999,

View File

@ -1199,12 +1199,12 @@ func (f *aclFilter) allowGateway(gs *structs.GatewayService) bool {
// Need read on service and gateway. Gateway may have different EnterpriseMeta so we fill authzContext twice // Need read on service and gateway. Gateway may have different EnterpriseMeta so we fill authzContext twice
gs.Gateway.FillAuthzContext(&authzContext) gs.Gateway.FillAuthzContext(&authzContext)
if !f.allowService(gs.Gateway.ID, &authzContext) { if !f.allowService(gs.Gateway.Name, &authzContext) {
return false return false
} }
gs.Service.FillAuthzContext(&authzContext) gs.Service.FillAuthzContext(&authzContext)
if !f.allowService(gs.Service.ID, &authzContext) { if !f.allowService(gs.Service.Name, &authzContext) {
return false return false
} }
return true return true
@ -1771,7 +1771,7 @@ func (f *aclFilter) filterGatewayServices(mappings *structs.GatewayServices) {
var authzContext acl.AuthorizerContext var authzContext acl.AuthorizerContext
s.Service.FillAuthzContext(&authzContext) s.Service.FillAuthzContext(&authzContext)
if f.authorizer.ServiceRead(s.Service.ID, &authzContext) != acl.Allow { if f.authorizer.ServiceRead(s.Service.Name, &authzContext) != acl.Allow {
f.logger.Debug("dropping service from result due to ACLs", "service", s.Service.String()) f.logger.Debug("dropping service from result due to ACLs", "service", s.Service.String())
continue continue
} }

View File

@ -629,6 +629,7 @@ func (c *Catalog) GatewayServices(args *structs.ServiceSpecificRequest, reply *s
} }
if entry != nil { if entry != nil {
found = true found = true
break
} }
} }

View File

@ -2848,8 +2848,8 @@ func TestCatalog_GatewayServices_TerminatingGateway(t *testing.T) {
expect := structs.GatewayServices{ expect := structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "api/ca.crt", CAFile: "api/ca.crt",
CertFile: "api/client.crt", CertFile: "api/client.crt",
@ -2857,16 +2857,16 @@ func TestCatalog_GatewayServices_TerminatingGateway(t *testing.T) {
SNI: "my-domain", SNI: "my-domain",
}, },
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "", CAFile: "",
CertFile: "", CertFile: "",
KeyFile: "", KeyFile: "",
}, },
{ {
Service: structs.NewServiceID("redis", nil), Service: structs.NewServiceName("redis", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "ca.crt", CAFile: "ca.crt",
CertFile: "client.crt", CertFile: "client.crt",
@ -3000,8 +3000,8 @@ func TestCatalog_GatewayServices_BothGateways(t *testing.T) {
expect := structs.GatewayServices{ expect := structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
}, },
} }
@ -3018,8 +3018,8 @@ func TestCatalog_GatewayServices_BothGateways(t *testing.T) {
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("ingress", nil), Gateway: structs.NewServiceName("ingress", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Protocol: "tcp", Protocol: "tcp",
Port: 8888, Port: 8888,
@ -3216,13 +3216,13 @@ service "gateway" {
expect := structs.GatewayServices{ expect := structs.GatewayServices{
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
}, },
{ {
Service: structs.NewServiceID("db_replica", nil), Service: structs.NewServiceName("db_replica", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
}, },
} }

View File

@ -169,7 +169,7 @@ func (m *Internal) GatewayServiceDump(args *structs.ServiceSpecificRequest, repl
// Loop over the gateway <-> serviceName mappings and fetch all service instances for each // Loop over the gateway <-> serviceName mappings and fetch all service instances for each
var result structs.ServiceDump var result structs.ServiceDump
for _, gs := range gatewayServices { for _, gs := range gatewayServices {
idx, instances, err := state.CheckServiceNodes(ws, gs.Service.ID, &gs.Service.EnterpriseMeta) idx, instances, err := state.CheckServiceNodes(ws, gs.Service.Name, &gs.Service.EnterpriseMeta)
if err != nil { if err != nil {
return err return err
} }

View File

@ -802,8 +802,8 @@ func TestInternal_GatewayServiceDump_Terminating(t *testing.T) {
}, },
}, },
GatewayService: &structs.GatewayService{ GatewayService: &structs.GatewayService{
Gateway: structs.NewServiceID("terminating-gateway", nil), Gateway: structs.NewServiceName("terminating-gateway", nil),
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
GatewayKind: "terminating-gateway", GatewayKind: "terminating-gateway",
}, },
}, },
@ -834,16 +834,16 @@ func TestInternal_GatewayServiceDump_Terminating(t *testing.T) {
}, },
}, },
GatewayService: &structs.GatewayService{ GatewayService: &structs.GatewayService{
Gateway: structs.NewServiceID("terminating-gateway", nil), Gateway: structs.NewServiceName("terminating-gateway", nil),
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
GatewayKind: "terminating-gateway", GatewayKind: "terminating-gateway",
}, },
}, },
{ {
// Only GatewayService should be returned when linked service isn't registered // Only GatewayService should be returned when linked service isn't registered
GatewayService: &structs.GatewayService{ GatewayService: &structs.GatewayService{
Gateway: structs.NewServiceID("terminating-gateway", nil), Gateway: structs.NewServiceName("terminating-gateway", nil),
Service: structs.NewServiceID("redis", nil), Service: structs.NewServiceName("redis", nil),
GatewayKind: "terminating-gateway", GatewayKind: "terminating-gateway",
CAFile: "/etc/certs/ca.pem", CAFile: "/etc/certs/ca.pem",
CertFile: "/etc/certs/cert.pem", CertFile: "/etc/certs/cert.pem",
@ -1134,8 +1134,8 @@ func TestInternal_GatewayServiceDump_Ingress(t *testing.T) {
}, },
}, },
GatewayService: &structs.GatewayService{ GatewayService: &structs.GatewayService{
Gateway: structs.NewServiceID("ingress-gateway", nil), Gateway: structs.NewServiceName("ingress-gateway", nil),
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
GatewayKind: "ingress-gateway", GatewayKind: "ingress-gateway",
Port: 8888, Port: 8888,
Protocol: "tcp", Protocol: "tcp",
@ -1168,8 +1168,8 @@ func TestInternal_GatewayServiceDump_Ingress(t *testing.T) {
}, },
}, },
GatewayService: &structs.GatewayService{ GatewayService: &structs.GatewayService{
Gateway: structs.NewServiceID("ingress-gateway", nil), Gateway: structs.NewServiceName("ingress-gateway", nil),
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
GatewayKind: "ingress-gateway", GatewayKind: "ingress-gateway",
Port: 8888, Port: 8888,
Protocol: "tcp", Protocol: "tcp",
@ -1178,8 +1178,8 @@ func TestInternal_GatewayServiceDump_Ingress(t *testing.T) {
{ {
// Only GatewayService should be returned when upstream isn't registered // Only GatewayService should be returned when upstream isn't registered
GatewayService: &structs.GatewayService{ GatewayService: &structs.GatewayService{
Gateway: structs.NewServiceID("ingress-gateway", nil), Gateway: structs.NewServiceName("ingress-gateway", nil),
Service: structs.NewServiceID("web", nil), Service: structs.NewServiceName("web", nil),
GatewayKind: "ingress-gateway", GatewayKind: "ingress-gateway",
Port: 8080, Port: 8080,
Protocol: "tcp", Protocol: "tcp",

View File

@ -71,10 +71,10 @@ func gatewayServicesTableNameSchema() *memdb.TableSchema {
Unique: true, Unique: true,
Indexer: &memdb.CompoundIndex{ Indexer: &memdb.CompoundIndex{
Indexes: []memdb.Indexer{ Indexes: []memdb.Indexer{
&ServiceIDIndex{ &ServiceNameIndex{
Field: "Gateway", Field: "Gateway",
}, },
&ServiceIDIndex{ &ServiceNameIndex{
Field: "Service", Field: "Service",
}, },
&memdb.IntFieldIndex{ &memdb.IntFieldIndex{
@ -87,7 +87,7 @@ func gatewayServicesTableNameSchema() *memdb.TableSchema {
Name: "gateway", Name: "gateway",
AllowMissing: false, AllowMissing: false,
Unique: false, Unique: false,
Indexer: &ServiceIDIndex{ Indexer: &ServiceNameIndex{
Field: "Gateway", Field: "Gateway",
}, },
}, },
@ -95,7 +95,7 @@ func gatewayServicesTableNameSchema() *memdb.TableSchema {
Name: "service", Name: "service",
AllowMissing: true, AllowMissing: true,
Unique: false, Unique: false,
Indexer: &ServiceIDIndex{ Indexer: &ServiceNameIndex{
Field: "Service", Field: "Service",
}, },
}, },
@ -103,11 +103,11 @@ func gatewayServicesTableNameSchema() *memdb.TableSchema {
} }
} }
type ServiceIDIndex struct { type ServiceNameIndex struct {
Field string Field string
} }
func (index *ServiceIDIndex) FromObject(obj interface{}) (bool, []byte, error) { func (index *ServiceNameIndex) FromObject(obj interface{}) (bool, []byte, error) {
v := reflect.ValueOf(obj) v := reflect.ValueOf(obj)
v = reflect.Indirect(v) // Dereference the pointer if any v = reflect.Indirect(v) // Dereference the pointer if any
@ -119,33 +119,33 @@ func (index *ServiceIDIndex) FromObject(obj interface{}) (bool, []byte, error) {
fmt.Errorf("field '%s' for %#v is invalid %v ", index.Field, obj, isPtr) fmt.Errorf("field '%s' for %#v is invalid %v ", index.Field, obj, isPtr)
} }
sid, ok := fv.Interface().(structs.ServiceID) name, ok := fv.Interface().(structs.ServiceName)
if !ok { if !ok {
return false, nil, fmt.Errorf("Field 'ServiceID' is not of type structs.ServiceID") return false, nil, fmt.Errorf("Field 'ServiceName' is not of type structs.ServiceName")
} }
// Enforce lowercase and add null character as terminator // Enforce lowercase and add null character as terminator
id := strings.ToLower(sid.String()) + "\x00" id := strings.ToLower(name.String()) + "\x00"
return true, []byte(id), nil return true, []byte(id), nil
} }
func (index *ServiceIDIndex) FromArgs(args ...interface{}) ([]byte, error) { func (index *ServiceNameIndex) FromArgs(args ...interface{}) ([]byte, error) {
if len(args) != 1 { if len(args) != 1 {
return nil, fmt.Errorf("must provide only a single argument") return nil, fmt.Errorf("must provide only a single argument")
} }
sid, ok := args[0].(structs.ServiceID) name, ok := args[0].(structs.ServiceName)
if !ok { if !ok {
return nil, fmt.Errorf("argument must be of type structs.ServiceID: %#v", args[0]) return nil, fmt.Errorf("argument must be of type structs.ServiceName: %#v", args[0])
} }
// Enforce lowercase and add null character as terminator // Enforce lowercase and add null character as terminator
id := strings.ToLower(sid.String()) + "\x00" id := strings.ToLower(name.String()) + "\x00"
return []byte(strings.ToLower(id)), nil return []byte(strings.ToLower(id)), nil
} }
func (index *ServiceIDIndex) PrefixFromArgs(args ...interface{}) ([]byte, error) { func (index *ServiceNameIndex) PrefixFromArgs(args ...interface{}) ([]byte, error) {
val, err := index.FromArgs(args...) val, err := index.FromArgs(args...)
if err != nil { if err != nil {
return nil, err return nil, err
@ -872,7 +872,7 @@ func (s *Store) serviceListTxn(tx *memdb.Txn, ws memdb.WatchSet, entMeta *struct
} }
ws.Add(services.WatchCh()) ws.Add(services.WatchCh())
unique := make(map[structs.ServiceID]struct{}) unique := make(map[structs.ServiceName]struct{})
for service := services.Next(); service != nil; service = services.Next() { for service := services.Next(); service != nil; service = services.Next() {
svc := service.(*structs.ServiceNode) svc := service.(*structs.ServiceNode)
unique[svc.CompoundServiceName()] = struct{}{} unique[svc.CompoundServiceName()] = struct{}{}
@ -880,7 +880,7 @@ func (s *Store) serviceListTxn(tx *memdb.Txn, ws memdb.WatchSet, entMeta *struct
results := make(structs.ServiceList, 0, len(unique)) results := make(structs.ServiceList, 0, len(unique))
for sid, _ := range unique { for sid, _ := range unique {
results = append(results, structs.ServiceName{Name: sid.ID, EnterpriseMeta: sid.EnterpriseMeta}) results = append(results, structs.ServiceName{Name: sid.Name, EnterpriseMeta: sid.EnterpriseMeta})
} }
return idx, results, nil return idx, results, nil
@ -1009,18 +1009,18 @@ func (s *Store) maxIndexAndWatchChsForServiceNodes(tx *memdb.Txn,
var watchChans []<-chan struct{} var watchChans []<-chan struct{}
var maxIdx uint64 var maxIdx uint64
seen := make(map[structs.ServiceID]bool) seen := make(map[structs.ServiceName]bool)
for i := 0; i < len(nodes); i++ { for i := 0; i < len(nodes); i++ {
sid := structs.NewServiceID(nodes[i].ServiceName, &nodes[i].EnterpriseMeta) sn := structs.NewServiceName(nodes[i].ServiceName, &nodes[i].EnterpriseMeta)
if ok := seen[sid]; !ok { if ok := seen[sn]; !ok {
idx, svcCh := s.maxIndexAndWatchChForService(tx, sid.ID, true, watchChecks, &sid.EnterpriseMeta) idx, svcCh := s.maxIndexAndWatchChForService(tx, sn.Name, true, watchChecks, &sn.EnterpriseMeta)
if idx > maxIdx { if idx > maxIdx {
maxIdx = idx maxIdx = idx
} }
if svcCh != nil { if svcCh != nil {
watchChans = append(watchChans, svcCh) watchChans = append(watchChans, svcCh)
} }
seen[sid] = true seen[sn] = true
} }
} }
@ -2014,14 +2014,14 @@ func (s *Store) CheckIngressServiceNodes(ws memdb.WatchSet, serviceName string,
// TODO(ingress): Test namespace functionality here // TODO(ingress): Test namespace functionality here
// De-dup services to lookup // De-dup services to lookup
serviceIDs := make(map[structs.ServiceID]struct{}) names := make(map[structs.ServiceName]struct{})
for _, n := range nodes { for _, n := range nodes {
serviceIDs[n.CompoundServiceName()] = struct{}{} names[n.CompoundServiceName()] = struct{}{}
} }
var results structs.CheckServiceNodes var results structs.CheckServiceNodes
for sid := range serviceIDs { for sid := range names {
idx, n, err := s.checkServiceNodesTxn(tx, ws, sid.ID, false, &sid.EnterpriseMeta) idx, n, err := s.checkServiceNodesTxn(tx, ws, sid.Name, false, &sid.EnterpriseMeta)
if err != nil { if err != nil {
return 0, nil, err return 0, nil, err
} }
@ -2065,13 +2065,13 @@ func (s *Store) checkServiceNodesTxn(tx *memdb.Txn, ws memdb.WatchSet, serviceNa
// service name IFF there is at least one Connect-native instance of that // service name IFF there is at least one Connect-native instance of that
// service. Either way there is usually only one distinct name if proxies are // service. Either way there is usually only one distinct name if proxies are
// named consistently but could be multiple. // named consistently but could be multiple.
serviceNames := make(map[structs.ServiceID]struct{}, 2) serviceNames := make(map[structs.ServiceName]struct{}, 2)
for service := iter.Next(); service != nil; service = iter.Next() { for service := iter.Next(); service != nil; service = iter.Next() {
sn := service.(*structs.ServiceNode) sn := service.(*structs.ServiceNode)
results = append(results, sn) results = append(results, sn)
sid := structs.NewServiceID(sn.ServiceName, &sn.EnterpriseMeta) name := structs.NewServiceName(sn.ServiceName, &sn.EnterpriseMeta)
serviceNames[sid] = struct{}{} serviceNames[name] = struct{}{}
} }
// If we are querying for Connect nodes, the associated proxy might be a terminating-gateway. // If we are querying for Connect nodes, the associated proxy might be a terminating-gateway.
@ -2089,8 +2089,8 @@ func (s *Store) checkServiceNodesTxn(tx *memdb.Txn, ws memdb.WatchSet, serviceNa
for i := 0; i < len(nodes); i++ { for i := 0; i < len(nodes); i++ {
results = append(results, nodes[i]) results = append(results, nodes[i])
sid := structs.NewServiceID(nodes[i].ServiceName, &nodes[i].EnterpriseMeta) name := structs.NewServiceName(nodes[i].ServiceName, &nodes[i].EnterpriseMeta)
serviceNames[sid] = struct{}{} serviceNames[name] = struct{}{}
} }
} }
@ -2109,11 +2109,11 @@ func (s *Store) checkServiceNodesTxn(tx *memdb.Txn, ws memdb.WatchSet, serviceNa
watchOptimized = true watchOptimized = true
// Fetch indexes for all names services in result set. // Fetch indexes for all names services in result set.
for svcName := range serviceNames { for n := range serviceNames {
// We know service values should exist since the serviceNames map is only // We know service values should exist since the serviceNames map is only
// populated if there is at least one result above. so serviceExists arg // populated if there is at least one result above. so serviceExists arg
// below is always true. // below is always true.
svcIdx, svcCh := s.maxIndexAndWatchChForService(tx, svcName.ID, true, true, &svcName.EnterpriseMeta) svcIdx, svcCh := s.maxIndexAndWatchChForService(tx, n.Name, true, true, &n.EnterpriseMeta)
// Take the max index represented // Take the max index represented
idx = lib.MaxUint64(idx, svcIdx) idx = lib.MaxUint64(idx, svcIdx)
if svcCh != nil { if svcCh != nil {
@ -2208,7 +2208,7 @@ func (s *Store) GatewayServices(ws memdb.WatchSet, gateway string, entMeta *stru
for service := iter.Next(); service != nil; service = iter.Next() { for service := iter.Next(); service != nil; service = iter.Next() {
svc := service.(*structs.GatewayService) svc := service.(*structs.GatewayService)
if svc.Service.ID != structs.WildcardSpecifier { if svc.Service.Name != structs.WildcardSpecifier {
idx, matches, err := s.checkProtocolMatch(tx, ws, svc) idx, matches, err := s.checkProtocolMatch(tx, ws, svc)
if err != nil { if err != nil {
return 0, nil, fmt.Errorf("failed checking protocol: %s", err) return 0, nil, fmt.Errorf("failed checking protocol: %s", err)
@ -2476,12 +2476,12 @@ func (s *Store) updateGatewayServices(tx *memdb.Txn, idx uint64, conf structs.Co
err error err error
) )
gatewayID := structs.NewServiceID(conf.GetName(), entMeta) gateway := structs.NewServiceName(conf.GetName(), entMeta)
switch conf.GetKind() { switch conf.GetKind() {
case structs.IngressGateway: case structs.IngressGateway:
noChange, gatewayServices, err = s.ingressConfigGatewayServices(tx, gatewayID, conf, entMeta) noChange, gatewayServices, err = s.ingressConfigGatewayServices(tx, gateway, conf, entMeta)
case structs.TerminatingGateway: case structs.TerminatingGateway:
noChange, gatewayServices, err = s.terminatingConfigGatewayServices(tx, gatewayID, conf, entMeta) noChange, gatewayServices, err = s.terminatingConfigGatewayServices(tx, gateway, conf, entMeta)
default: default:
return fmt.Errorf("config entry kind %q does not need gateway-services", conf.GetKind()) return fmt.Errorf("config entry kind %q does not need gateway-services", conf.GetKind())
} }
@ -2491,15 +2491,15 @@ func (s *Store) updateGatewayServices(tx *memdb.Txn, idx uint64, conf structs.Co
} }
// Delete all associated with gateway first, to avoid keeping mappings that were removed // Delete all associated with gateway first, to avoid keeping mappings that were removed
if _, err := tx.DeleteAll(gatewayServicesTableName, "gateway", structs.NewServiceID(conf.GetName(), entMeta)); err != nil { if _, err := tx.DeleteAll(gatewayServicesTableName, "gateway", structs.NewServiceName(conf.GetName(), entMeta)); err != nil {
return fmt.Errorf("failed to truncate gateway services table: %v", err) return fmt.Errorf("failed to truncate gateway services table: %v", err)
} }
for _, svc := range gatewayServices { for _, svc := range gatewayServices {
// If the service is a wildcard we need to target all services within the namespace // If the service is a wildcard we need to target all services within the namespace
if svc.Service.ID == structs.WildcardSpecifier { if svc.Service.Name == structs.WildcardSpecifier {
if err := s.updateGatewayNamespace(tx, idx, svc, entMeta); err != nil { if err := s.updateGatewayNamespace(tx, idx, svc, entMeta); err != nil {
return fmt.Errorf("failed to associate gateway %q with wildcard: %v", gatewayID.String(), err) return fmt.Errorf("failed to associate gateway %q with wildcard: %v", gateway.String(), err)
} }
// Skip service-specific update below if there was a wildcard update // Skip service-specific update below if there was a wildcard update
continue continue
@ -2527,7 +2527,7 @@ func (s *Store) updateGatewayServices(tx *memdb.Txn, idx uint64, conf structs.Co
// returned indicates that there are no changes necessary to the memdb table. // returned indicates that there are no changes necessary to the memdb table.
func (s *Store) ingressConfigGatewayServices( func (s *Store) ingressConfigGatewayServices(
tx *memdb.Txn, tx *memdb.Txn,
gateway structs.ServiceID, gateway structs.ServiceName,
conf structs.ConfigEntry, conf structs.ConfigEntry,
entMeta *structs.EnterpriseMeta, entMeta *structs.EnterpriseMeta,
) (bool, structs.GatewayServices, error) { ) (bool, structs.GatewayServices, error) {
@ -2553,7 +2553,7 @@ func (s *Store) ingressConfigGatewayServices(
for _, service := range listener.Services { for _, service := range listener.Services {
mapping := &structs.GatewayService{ mapping := &structs.GatewayService{
Gateway: gateway, Gateway: gateway,
Service: service.ToServiceID(), Service: service.ToServiceName(),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Hosts: service.Hosts, Hosts: service.Hosts,
Port: listener.Port, Port: listener.Port,
@ -2572,7 +2572,7 @@ func (s *Store) ingressConfigGatewayServices(
// table. // table.
func (s *Store) terminatingConfigGatewayServices( func (s *Store) terminatingConfigGatewayServices(
tx *memdb.Txn, tx *memdb.Txn,
gateway structs.ServiceID, gateway structs.ServiceName,
conf structs.ConfigEntry, conf structs.ConfigEntry,
entMeta *structs.EnterpriseMeta, entMeta *structs.EnterpriseMeta,
) (bool, structs.GatewayServices, error) { ) (bool, structs.GatewayServices, error) {
@ -2597,7 +2597,7 @@ func (s *Store) terminatingConfigGatewayServices(
for _, svc := range entry.Services { for _, svc := range entry.Services {
mapping := &structs.GatewayService{ mapping := &structs.GatewayService{
Gateway: gateway, Gateway: gateway,
Service: structs.NewServiceID(svc.Name, &svc.EnterpriseMeta), Service: structs.NewServiceName(svc.Name, &svc.EnterpriseMeta),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
KeyFile: svc.KeyFile, KeyFile: svc.KeyFile,
CertFile: svc.CertFile, CertFile: svc.CertFile,
@ -2638,7 +2638,7 @@ func (s *Store) updateGatewayNamespace(tx *memdb.Txn, idx uint64, service *struc
mapping := service.Clone() mapping := service.Clone()
mapping.Service = structs.NewServiceID(sn.ServiceName, &service.Service.EnterpriseMeta) mapping.Service = structs.NewServiceName(sn.ServiceName, &service.Service.EnterpriseMeta)
mapping.FromWildcard = true mapping.FromWildcard = true
err = s.updateGatewayService(tx, idx, mapping) err = s.updateGatewayService(tx, idx, mapping)
@ -2705,7 +2705,7 @@ func (s *Store) checkGatewayWildcardsAndUpdate(tx *memdb.Txn, idx uint64, svc *s
// Copy the wildcard mapping and modify it // Copy the wildcard mapping and modify it
gatewaySvc := wildcardSvc.Clone() gatewaySvc := wildcardSvc.Clone()
gatewaySvc.Service = structs.NewServiceID(svc.Service, &svc.EnterpriseMeta) gatewaySvc.Service = structs.NewServiceName(svc.Service, &svc.EnterpriseMeta)
gatewaySvc.FromWildcard = true gatewaySvc.FromWildcard = true
if err = s.updateGatewayService(tx, idx, gatewaySvc); err != nil { if err = s.updateGatewayService(tx, idx, gatewaySvc); err != nil {
@ -2719,11 +2719,11 @@ func (s *Store) checkGatewayWildcardsAndUpdate(tx *memdb.Txn, idx uint64, svc *s
// serviceGateways returns all GatewayService entries with the given service name. This effectively looks up // serviceGateways returns all GatewayService entries with the given service name. This effectively looks up
// all the gateways mapped to this service. // all the gateways mapped to this service.
func (s *Store) serviceGateways(tx *memdb.Txn, name string, entMeta *structs.EnterpriseMeta) (memdb.ResultIterator, error) { func (s *Store) serviceGateways(tx *memdb.Txn, name string, entMeta *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
return tx.Get(gatewayServicesTableName, "service", structs.NewServiceID(name, entMeta)) return tx.Get(gatewayServicesTableName, "service", structs.NewServiceName(name, entMeta))
} }
func (s *Store) gatewayServices(tx *memdb.Txn, name string, entMeta *structs.EnterpriseMeta) (memdb.ResultIterator, error) { func (s *Store) gatewayServices(tx *memdb.Txn, name string, entMeta *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
return tx.Get(gatewayServicesTableName, "gateway", structs.NewServiceID(name, entMeta)) return tx.Get(gatewayServicesTableName, "gateway", structs.NewServiceName(name, entMeta))
} }
// TODO(ingress): How to handle index rolling back when a config entry is // TODO(ingress): How to handle index rolling back when a config entry is
@ -2752,7 +2752,7 @@ func (s *Store) serviceGatewayNodes(tx *memdb.Txn, ws memdb.WatchSet, service st
maxIdx = lib.MaxUint64(maxIdx, mapping.ModifyIndex) maxIdx = lib.MaxUint64(maxIdx, mapping.ModifyIndex)
// Look up nodes for gateway // Look up nodes for gateway
gwServices, err := s.catalogServiceNodeList(tx, mapping.Gateway.ID, "service", &mapping.Gateway.EnterpriseMeta) gwServices, err := s.catalogServiceNodeList(tx, mapping.Gateway.Name, "service", &mapping.Gateway.EnterpriseMeta)
if err != nil { if err != nil {
return 0, nil, fmt.Errorf("failed service lookup: %s", err) return 0, nil, fmt.Errorf("failed service lookup: %s", err)
} }
@ -2767,7 +2767,7 @@ func (s *Store) serviceGatewayNodes(tx *memdb.Txn, ws memdb.WatchSet, service st
} }
// This prevents the index from sliding back if case all instances of the gateway service are deregistered // This prevents the index from sliding back if case all instances of the gateway service are deregistered
svcIdx := s.maxIndexForService(tx, mapping.Gateway.ID, exists, false, &mapping.Gateway.EnterpriseMeta) svcIdx := s.maxIndexForService(tx, mapping.Gateway.Name, exists, false, &mapping.Gateway.EnterpriseMeta)
maxIdx = lib.MaxUint64(maxIdx, svcIdx) maxIdx = lib.MaxUint64(maxIdx, svcIdx)
// Ensure that blocking queries wake up if the gateway-service mapping exists, but the gateway does not exist yet // Ensure that blocking queries wake up if the gateway-service mapping exists, but the gateway does not exist yet

View File

@ -4492,8 +4492,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
expect := structs.GatewayServices{ expect := structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
CreateIndex: 21, CreateIndex: 21,
@ -4501,8 +4501,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
}, },
}, },
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
CreateIndex: 21, CreateIndex: 21,
@ -4534,8 +4534,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
CreateIndex: 21, CreateIndex: 21,
@ -4543,8 +4543,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
}, },
}, },
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
CreateIndex: 21, CreateIndex: 21,
@ -4589,8 +4589,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "api/ca.crt", CAFile: "api/ca.crt",
CertFile: "api/client.crt", CertFile: "api/client.crt",
@ -4602,8 +4602,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
}, },
}, },
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
CreateIndex: 22, CreateIndex: 22,
@ -4625,8 +4625,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "api/ca.crt", CAFile: "api/ca.crt",
CertFile: "api/client.crt", CertFile: "api/client.crt",
@ -4638,8 +4638,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
}, },
}, },
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
CreateIndex: 22, CreateIndex: 22,
@ -4647,8 +4647,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
}, },
}, },
{ {
Service: structs.NewServiceID("redis", nil), Service: structs.NewServiceName("redis", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "ca.crt", CAFile: "ca.crt",
CertFile: "client.crt", CertFile: "client.crt",
@ -4675,8 +4675,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "api/ca.crt", CAFile: "api/ca.crt",
CertFile: "api/client.crt", CertFile: "api/client.crt",
@ -4688,8 +4688,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
}, },
}, },
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
CreateIndex: 22, CreateIndex: 22,
@ -4719,8 +4719,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
// previously associated services should not be present // previously associated services should not be present
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
CreateIndex: 25, CreateIndex: 25,
@ -4749,8 +4749,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("gateway2", nil), Gateway: structs.NewServiceName("gateway2", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
FromWildcard: true, FromWildcard: true,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
@ -4759,8 +4759,8 @@ func TestStateStore_GatewayServices_Terminating(t *testing.T) {
}, },
}, },
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway2", nil), Gateway: structs.NewServiceName("gateway2", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
FromWildcard: true, FromWildcard: true,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
@ -4845,8 +4845,8 @@ func TestStateStore_GatewayServices_ServiceDeletion(t *testing.T) {
expect := structs.GatewayServices{ expect := structs.GatewayServices{
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "my_ca.pem", CAFile: "my_ca.pem",
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
@ -4866,8 +4866,8 @@ func TestStateStore_GatewayServices_ServiceDeletion(t *testing.T) {
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("other-gateway", nil), Gateway: structs.NewServiceName("other-gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
FromWildcard: true, FromWildcard: true,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
@ -4876,8 +4876,8 @@ func TestStateStore_GatewayServices_ServiceDeletion(t *testing.T) {
}, },
}, },
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("other-gateway", nil), Gateway: structs.NewServiceName("other-gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
FromWildcard: true, FromWildcard: true,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
@ -4903,8 +4903,8 @@ func TestStateStore_GatewayServices_ServiceDeletion(t *testing.T) {
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("gateway", nil), Gateway: structs.NewServiceName("gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
CAFile: "my_ca.pem", CAFile: "my_ca.pem",
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
@ -4923,8 +4923,8 @@ func TestStateStore_GatewayServices_ServiceDeletion(t *testing.T) {
expect = structs.GatewayServices{ expect = structs.GatewayServices{
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("other-gateway", nil), Gateway: structs.NewServiceName("other-gateway", nil),
GatewayKind: structs.ServiceKindTerminatingGateway, GatewayKind: structs.ServiceKindTerminatingGateway,
FromWildcard: true, FromWildcard: true,
RaftIndex: structs.RaftIndex{ RaftIndex: structs.RaftIndex{
@ -5016,8 +5016,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
t.Run("ingress1 gateway services", func(t *testing.T) { t.Run("ingress1 gateway services", func(t *testing.T) {
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress1", nil), Gateway: structs.NewServiceName("ingress1", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 1111, Port: 1111,
Protocol: "http", Protocol: "http",
@ -5028,8 +5028,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
}, },
}, },
{ {
Gateway: structs.NewServiceID("ingress1", nil), Gateway: structs.NewServiceName("ingress1", nil),
Service: structs.NewServiceID("service2", nil), Service: structs.NewServiceName("service2", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 2222, Port: 2222,
Protocol: "http", Protocol: "http",
@ -5048,8 +5048,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
t.Run("ingress2 gateway services", func(t *testing.T) { t.Run("ingress2 gateway services", func(t *testing.T) {
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress2", nil), Gateway: structs.NewServiceName("ingress2", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 3333, Port: 3333,
Protocol: "http", Protocol: "http",
@ -5075,8 +5075,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
t.Run("wildcard gateway services", func(t *testing.T) { t.Run("wildcard gateway services", func(t *testing.T) {
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("wildcardIngress", nil), Gateway: structs.NewServiceName("wildcardIngress", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 4444, Port: 4444,
Protocol: "http", Protocol: "http",
@ -5087,8 +5087,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
}, },
}, },
{ {
Gateway: structs.NewServiceID("wildcardIngress", nil), Gateway: structs.NewServiceName("wildcardIngress", nil),
Service: structs.NewServiceID("service2", nil), Service: structs.NewServiceName("service2", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 4444, Port: 4444,
Protocol: "http", Protocol: "http",
@ -5099,8 +5099,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
}, },
}, },
{ {
Gateway: structs.NewServiceID("wildcardIngress", nil), Gateway: structs.NewServiceName("wildcardIngress", nil),
Service: structs.NewServiceID("service3", nil), Service: structs.NewServiceName("service3", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 4444, Port: 4444,
Protocol: "http", Protocol: "http",
@ -5120,8 +5120,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
t.Run("gateway with duplicate service", func(t *testing.T) { t.Run("gateway with duplicate service", func(t *testing.T) {
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress3", nil), Gateway: structs.NewServiceName("ingress3", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 5555, Port: 5555,
Protocol: "http", Protocol: "http",
@ -5132,8 +5132,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
}, },
}, },
{ {
Gateway: structs.NewServiceID("ingress3", nil), Gateway: structs.NewServiceName("ingress3", nil),
Service: structs.NewServiceID("service2", nil), Service: structs.NewServiceName("service2", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 5555, Port: 5555,
Protocol: "http", Protocol: "http",
@ -5144,8 +5144,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
}, },
}, },
{ {
Gateway: structs.NewServiceID("ingress3", nil), Gateway: structs.NewServiceName("ingress3", nil),
Service: structs.NewServiceID("service3", nil), Service: structs.NewServiceName("service3", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 5555, Port: 5555,
Protocol: "http", Protocol: "http",
@ -5156,8 +5156,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
}, },
}, },
{ {
Gateway: structs.NewServiceID("ingress3", nil), Gateway: structs.NewServiceName("ingress3", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 6666, Port: 6666,
Protocol: "http", Protocol: "http",
@ -5187,8 +5187,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
t.Run("check ingress2 gateway services again", func(t *testing.T) { t.Run("check ingress2 gateway services again", func(t *testing.T) {
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress2", nil), Gateway: structs.NewServiceName("ingress2", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 3333, Port: 3333,
Protocol: "http", Protocol: "http",
@ -5256,8 +5256,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress1", nil), Gateway: structs.NewServiceName("ingress1", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 1111, Port: 1111,
Protocol: "http", Protocol: "http",
@ -5268,8 +5268,8 @@ func TestStateStore_GatewayServices_Ingress(t *testing.T) {
}, },
}, },
{ {
Gateway: structs.NewServiceID("ingress1", nil), Gateway: structs.NewServiceName("ingress1", nil),
Service: structs.NewServiceID("service2", nil), Service: structs.NewServiceName("service2", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 2222, Port: 2222,
Protocol: "http", Protocol: "http",
@ -5400,8 +5400,8 @@ func TestStateStore_GatewayServices_IngressProtocolFiltering(t *testing.T) {
require := require.New(t) require := require.New(t)
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress1", nil), Gateway: structs.NewServiceName("ingress1", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 4444, Port: 4444,
Protocol: "http", Protocol: "http",
@ -5429,8 +5429,8 @@ func TestStateStore_GatewayServices_IngressProtocolFiltering(t *testing.T) {
require := require.New(t) require := require.New(t)
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress1", nil), Gateway: structs.NewServiceName("ingress1", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 4444, Port: 4444,
Protocol: "http", Protocol: "http",
@ -5441,8 +5441,8 @@ func TestStateStore_GatewayServices_IngressProtocolFiltering(t *testing.T) {
}, },
}, },
{ {
Gateway: structs.NewServiceID("ingress1", nil), Gateway: structs.NewServiceName("ingress1", nil),
Service: structs.NewServiceID("service2", nil), Service: structs.NewServiceName("service2", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 4444, Port: 4444,
Protocol: "http", Protocol: "http",
@ -5473,8 +5473,8 @@ func TestStateStore_GatewayServices_IngressProtocolFiltering(t *testing.T) {
require := require.New(t) require := require.New(t)
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress1", nil), Gateway: structs.NewServiceName("ingress1", nil),
Service: structs.NewServiceID("service2", nil), Service: structs.NewServiceName("service2", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 4444, Port: 4444,
Protocol: "http", Protocol: "http",
@ -5503,8 +5503,8 @@ func TestStateStore_GatewayServices_IngressProtocolFiltering(t *testing.T) {
require := require.New(t) require := require.New(t)
expected := structs.GatewayServices{ expected := structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress1", nil), Gateway: structs.NewServiceName("ingress1", nil),
Service: structs.NewServiceID("service1", nil), Service: structs.NewServiceName("service1", nil),
GatewayKind: structs.ServiceKindIngressGateway, GatewayKind: structs.ServiceKindIngressGateway,
Port: 4444, Port: 4444,
Protocol: "grpc", Protocol: "grpc",

View File

@ -266,7 +266,7 @@ func (s *Store) DeleteConfigEntry(idx uint64, kind, name string, entMeta *struct
// If the config entry is for terminating or ingress gateways we delete entries from the memdb table // If the config entry is for terminating or ingress gateways we delete entries from the memdb table
// that associates gateways <-> services. // that associates gateways <-> services.
if kind == structs.TerminatingGateway || kind == structs.IngressGateway { if kind == structs.TerminatingGateway || kind == structs.IngressGateway {
if _, err := tx.DeleteAll(gatewayServicesTableName, "gateway", structs.NewServiceID(name, entMeta)); err != nil { if _, err := tx.DeleteAll(gatewayServicesTableName, "gateway", structs.NewServiceName(name, entMeta)); err != nil {
return fmt.Errorf("failed to truncate gateway services table: %v", err) return fmt.Errorf("failed to truncate gateway services table: %v", err)
} }
if err := indexUpdateMaxTxn(tx, idx, gatewayServicesTableName); err != nil { if err := indexUpdateMaxTxn(tx, idx, gatewayServicesTableName); err != nil {
@ -855,7 +855,7 @@ func (s *Store) validateProposedIngressProtocolsInServiceGraph(
return fmt.Errorf("type %T is not an ingress gateway config entry", next) return fmt.Errorf("type %T is not an ingress gateway config entry", next)
} }
validationFn := func(svc structs.ServiceID, expectedProto string) error { validationFn := func(svc structs.ServiceName, expectedProto string) error {
_, svcProto, err := s.protocolForService(tx, nil, svc) _, svcProto, err := s.protocolForService(tx, nil, svc)
if err != nil { if err != nil {
return err return err
@ -874,7 +874,7 @@ func (s *Store) validateProposedIngressProtocolsInServiceGraph(
if s.Name == structs.WildcardSpecifier { if s.Name == structs.WildcardSpecifier {
continue continue
} }
err := validationFn(s.ToServiceID(), l.Protocol) err := validationFn(s.ToServiceName(), l.Protocol)
if err != nil { if err != nil {
return err return err
} }
@ -888,7 +888,7 @@ func (s *Store) validateProposedIngressProtocolsInServiceGraph(
func (s *Store) protocolForService( func (s *Store) protocolForService(
tx *memdb.Txn, tx *memdb.Txn,
ws memdb.WatchSet, ws memdb.WatchSet,
svc structs.ServiceID, svc structs.ServiceName,
) (uint64, string, error) { ) (uint64, string, error) {
// Get the global proxy defaults (for default protocol) // Get the global proxy defaults (for default protocol)
maxIdx, proxyConfig, err := s.configEntryTxn(tx, ws, structs.ProxyDefaults, structs.ProxyConfigGlobal, structs.DefaultEnterpriseMeta()) maxIdx, proxyConfig, err := s.configEntryTxn(tx, ws, structs.ProxyDefaults, structs.ProxyConfigGlobal, structs.DefaultEnterpriseMeta())
@ -896,7 +896,7 @@ func (s *Store) protocolForService(
return 0, "", err return 0, "", err
} }
idx, serviceDefaults, err := s.configEntryTxn(tx, ws, structs.ServiceDefaults, svc.ID, &svc.EnterpriseMeta) idx, serviceDefaults, err := s.configEntryTxn(tx, ws, structs.ServiceDefaults, svc.Name, &svc.EnterpriseMeta)
if err != nil { if err != nil {
return 0, "", err return 0, "", err
} }
@ -910,7 +910,7 @@ func (s *Store) protocolForService(
entries.AddEntries(serviceDefaults) entries.AddEntries(serviceDefaults)
} }
req := discoverychain.CompileRequest{ req := discoverychain.CompileRequest{
ServiceName: svc.ID, ServiceName: svc.Name,
EvaluateInNamespace: svc.NamespaceOrDefault(), EvaluateInNamespace: svc.NamespaceOrDefault(),
EvaluateInDatacenter: "dc1", EvaluateInDatacenter: "dc1",
// Use a dummy trust domain since that won't affect the protocol here. // Use a dummy trust domain since that won't affect the protocol here.

View File

@ -59,51 +59,51 @@ func (c *configSnapshotConnectProxy) IsEmpty() bool {
} }
type configSnapshotTerminatingGateway struct { type configSnapshotTerminatingGateway struct {
// WatchedServices is a map of service id to a cancel function. This cancel // WatchedServices is a map of service name to a cancel function. This cancel
// function is tied to the watch of linked service instances for the given // function is tied to the watch of linked service instances for the given
// id. If the linked services watch would indicate the removal of // id. If the linked services watch would indicate the removal of
// a service altogether we then cancel watching that service for its endpoints. // a service altogether we then cancel watching that service for its endpoints.
WatchedServices map[structs.ServiceID]context.CancelFunc WatchedServices map[structs.ServiceName]context.CancelFunc
// WatchedIntentions is a map of service id to a cancel function. // WatchedIntentions is a map of service name to a cancel function.
// This cancel function is tied to the watch of intentions for linked services. // This cancel function is tied to the watch of intentions for linked services.
// As with WatchedServices, intention watches will be cancelled when services // As with WatchedServices, intention watches will be cancelled when services
// are no longer linked to the gateway. // are no longer linked to the gateway.
WatchedIntentions map[structs.ServiceID]context.CancelFunc WatchedIntentions map[structs.ServiceName]context.CancelFunc
// WatchedLeaves is a map of ServiceID to a cancel function. // WatchedLeaves is a map of ServiceName to a cancel function.
// This cancel function is tied to the watch of leaf certs for linked services. // This cancel function is tied to the watch of leaf certs for linked services.
// As with WatchedServices, leaf watches will be cancelled when services // As with WatchedServices, leaf watches will be cancelled when services
// are no longer linked to the gateway. // are no longer linked to the gateway.
WatchedLeaves map[structs.ServiceID]context.CancelFunc WatchedLeaves map[structs.ServiceName]context.CancelFunc
// ServiceLeaves is a map of ServiceID to a leaf cert. // ServiceLeaves is a map of ServiceName to a leaf cert.
// Terminating gateways will present different certificates depending // Terminating gateways will present different certificates depending
// on the service that the caller is trying to reach. // on the service that the caller is trying to reach.
ServiceLeaves map[structs.ServiceID]*structs.IssuedCert ServiceLeaves map[structs.ServiceName]*structs.IssuedCert
// WatchedResolvers is a map of ServiceID to a cancel function. // WatchedResolvers is a map of ServiceName to a cancel function.
// This cancel function is tied to the watch of resolvers for linked services. // This cancel function is tied to the watch of resolvers for linked services.
// As with WatchedServices, resolver watches will be cancelled when services // As with WatchedServices, resolver watches will be cancelled when services
// are no longer linked to the gateway. // are no longer linked to the gateway.
WatchedResolvers map[structs.ServiceID]context.CancelFunc WatchedResolvers map[structs.ServiceName]context.CancelFunc
// ServiceResolvers is a map of service id to an associated // ServiceResolvers is a map of service name to an associated
// service-resolver config entry for that service. // service-resolver config entry for that service.
ServiceResolvers map[structs.ServiceID]*structs.ServiceResolverConfigEntry ServiceResolvers map[structs.ServiceName]*structs.ServiceResolverConfigEntry
// ServiceGroups is a map of service id to the service instances of that // ServiceGroups is a map of service name to the service instances of that
// service in the local datacenter. // service in the local datacenter.
ServiceGroups map[structs.ServiceID]structs.CheckServiceNodes ServiceGroups map[structs.ServiceName]structs.CheckServiceNodes
// GatewayServices is a map of service id to the config entry association // GatewayServices is a map of service name to the config entry association
// between the gateway and a service. TLS configuration stored here is // between the gateway and a service. TLS configuration stored here is
// used for TLS origination from the gateway to the linked service. // used for TLS origination from the gateway to the linked service.
GatewayServices map[structs.ServiceID]structs.GatewayService GatewayServices map[structs.ServiceName]structs.GatewayService
// HostnameServices is a map of service id to service instances with a hostname as the address. // HostnameServices is a map of service name to service instances with a hostname as the address.
// If hostnames are configured they must be provided to Envoy via CDS not EDS. // If hostnames are configured they must be provided to Envoy via CDS not EDS.
HostnameServices map[structs.ServiceID]structs.CheckServiceNodes HostnameServices map[structs.ServiceName]structs.CheckServiceNodes
} }
func (c *configSnapshotTerminatingGateway) IsEmpty() bool { func (c *configSnapshotTerminatingGateway) IsEmpty() bool {
@ -122,12 +122,12 @@ func (c *configSnapshotTerminatingGateway) IsEmpty() bool {
} }
type configSnapshotMeshGateway struct { type configSnapshotMeshGateway struct {
// WatchedServices is a map of service id to a cancel function. This cancel // WatchedServices is a map of service name to a cancel function. This cancel
// function is tied to the watch of connect enabled services for the given // function is tied to the watch of connect enabled services for the given
// id. If the main datacenter services watch would indicate the removal of // id. If the main datacenter services watch would indicate the removal of
// a service altogether we then cancel watching that service for its // a service altogether we then cancel watching that service for its
// connect endpoints. // connect endpoints.
WatchedServices map[structs.ServiceID]context.CancelFunc WatchedServices map[structs.ServiceName]context.CancelFunc
// WatchedServicesSet indicates that the watch on the datacenters services // WatchedServicesSet indicates that the watch on the datacenters services
// has completed. Even when there are no connect services, this being set // has completed. Even when there are no connect services, this being set
@ -142,13 +142,13 @@ type configSnapshotMeshGateway struct {
// that datacenter. // that datacenter.
WatchedDatacenters map[string]context.CancelFunc WatchedDatacenters map[string]context.CancelFunc
// ServiceGroups is a map of service id to the service instances of that // ServiceGroups is a map of service name to the service instances of that
// service in the local datacenter. // service in the local datacenter.
ServiceGroups map[structs.ServiceID]structs.CheckServiceNodes ServiceGroups map[structs.ServiceName]structs.CheckServiceNodes
// ServiceResolvers is a map of service id to an associated // ServiceResolvers is a map of service name to an associated
// service-resolver config entry for that service. // service-resolver config entry for that service.
ServiceResolvers map[structs.ServiceID]*structs.ServiceResolverConfigEntry ServiceResolvers map[structs.ServiceName]*structs.ServiceResolverConfigEntry
// GatewayGroups is a map of datacenter names to services of kind // GatewayGroups is a map of datacenter names to services of kind
// mesh-gateway in that datacenter. // mesh-gateway in that datacenter.

View File

@ -545,21 +545,21 @@ func (s *state) initialConfigSnapshot() ConfigSnapshot {
snap.ConnectProxy.WatchedServiceChecks = make(map[structs.ServiceID][]structs.CheckType) snap.ConnectProxy.WatchedServiceChecks = make(map[structs.ServiceID][]structs.CheckType)
snap.ConnectProxy.PreparedQueryEndpoints = make(map[string]structs.CheckServiceNodes) snap.ConnectProxy.PreparedQueryEndpoints = make(map[string]structs.CheckServiceNodes)
case structs.ServiceKindTerminatingGateway: case structs.ServiceKindTerminatingGateway:
snap.TerminatingGateway.WatchedServices = make(map[structs.ServiceID]context.CancelFunc) snap.TerminatingGateway.WatchedServices = make(map[structs.ServiceName]context.CancelFunc)
snap.TerminatingGateway.WatchedLeaves = make(map[structs.ServiceID]context.CancelFunc) snap.TerminatingGateway.WatchedLeaves = make(map[structs.ServiceName]context.CancelFunc)
snap.TerminatingGateway.WatchedIntentions = make(map[structs.ServiceID]context.CancelFunc) snap.TerminatingGateway.WatchedIntentions = make(map[structs.ServiceName]context.CancelFunc)
snap.TerminatingGateway.WatchedResolvers = make(map[structs.ServiceID]context.CancelFunc) snap.TerminatingGateway.WatchedResolvers = make(map[structs.ServiceName]context.CancelFunc)
snap.TerminatingGateway.ServiceLeaves = make(map[structs.ServiceID]*structs.IssuedCert) snap.TerminatingGateway.ServiceLeaves = make(map[structs.ServiceName]*structs.IssuedCert)
snap.TerminatingGateway.ServiceGroups = make(map[structs.ServiceID]structs.CheckServiceNodes) snap.TerminatingGateway.ServiceGroups = make(map[structs.ServiceName]structs.CheckServiceNodes)
snap.TerminatingGateway.ServiceResolvers = make(map[structs.ServiceID]*structs.ServiceResolverConfigEntry) snap.TerminatingGateway.ServiceResolvers = make(map[structs.ServiceName]*structs.ServiceResolverConfigEntry)
snap.TerminatingGateway.GatewayServices = make(map[structs.ServiceID]structs.GatewayService) snap.TerminatingGateway.GatewayServices = make(map[structs.ServiceName]structs.GatewayService)
snap.TerminatingGateway.HostnameServices = make(map[structs.ServiceID]structs.CheckServiceNodes) snap.TerminatingGateway.HostnameServices = make(map[structs.ServiceName]structs.CheckServiceNodes)
case structs.ServiceKindMeshGateway: case structs.ServiceKindMeshGateway:
snap.MeshGateway.WatchedServices = make(map[structs.ServiceID]context.CancelFunc) snap.MeshGateway.WatchedServices = make(map[structs.ServiceName]context.CancelFunc)
snap.MeshGateway.WatchedDatacenters = make(map[string]context.CancelFunc) snap.MeshGateway.WatchedDatacenters = make(map[string]context.CancelFunc)
snap.MeshGateway.ServiceGroups = make(map[structs.ServiceID]structs.CheckServiceNodes) snap.MeshGateway.ServiceGroups = make(map[structs.ServiceName]structs.CheckServiceNodes)
snap.MeshGateway.GatewayGroups = make(map[string]structs.CheckServiceNodes) snap.MeshGateway.GatewayGroups = make(map[string]structs.CheckServiceNodes)
snap.MeshGateway.ServiceResolvers = make(map[structs.ServiceID]*structs.ServiceResolverConfigEntry) snap.MeshGateway.ServiceResolvers = make(map[structs.ServiceName]*structs.ServiceResolverConfigEntry)
snap.MeshGateway.HostnameDatacenters = make(map[string]structs.CheckServiceNodes) snap.MeshGateway.HostnameDatacenters = make(map[string]structs.CheckServiceNodes)
// there is no need to initialize the map of service resolvers as we // there is no need to initialize the map of service resolvers as we
// fully rebuild it every time we get updates // fully rebuild it every time we get updates
@ -921,7 +921,7 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
return fmt.Errorf("invalid type for response: %T", u.Result) return fmt.Errorf("invalid type for response: %T", u.Result)
} }
svcMap := make(map[structs.ServiceID]struct{}) svcMap := make(map[structs.ServiceName]struct{})
for _, svc := range services.Services { for _, svc := range services.Services {
// Make sure to add every service to this map, we use it to cancel watches below. // Make sure to add every service to this map, we use it to cancel watches below.
svcMap[svc.Service] = struct{}{} svcMap[svc.Service] = struct{}{}
@ -935,7 +935,7 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
err := s.cache.Notify(ctx, cachetype.HealthServicesName, &structs.ServiceSpecificRequest{ err := s.cache.Notify(ctx, cachetype.HealthServicesName, &structs.ServiceSpecificRequest{
Datacenter: s.source.Datacenter, Datacenter: s.source.Datacenter,
QueryOptions: structs.QueryOptions{Token: s.token}, QueryOptions: structs.QueryOptions{Token: s.token},
ServiceName: svc.Service.ID, ServiceName: svc.Service.Name,
EnterpriseMeta: svc.Service.EnterpriseMeta, EnterpriseMeta: svc.Service.EnterpriseMeta,
// The gateway acts as the service's proxy, so we do NOT want to discover other proxies // The gateway acts as the service's proxy, so we do NOT want to discover other proxies
@ -965,7 +965,7 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
Entries: []structs.IntentionMatchEntry{ Entries: []structs.IntentionMatchEntry{
{ {
Namespace: svc.Service.NamespaceOrDefault(), Namespace: svc.Service.NamespaceOrDefault(),
Name: svc.Service.ID, Name: svc.Service.Name,
}, },
}, },
}, },
@ -989,7 +989,7 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
err := s.cache.Notify(ctx, cachetype.ConnectCALeafName, &cachetype.ConnectCALeafRequest{ err := s.cache.Notify(ctx, cachetype.ConnectCALeafName, &cachetype.ConnectCALeafRequest{
Datacenter: s.source.Datacenter, Datacenter: s.source.Datacenter,
Token: s.token, Token: s.token,
Service: svc.Service.ID, Service: svc.Service.Name,
EnterpriseMeta: svc.Service.EnterpriseMeta, EnterpriseMeta: svc.Service.EnterpriseMeta,
}, serviceLeafIDPrefix+svc.Service.String(), s.ch) }, serviceLeafIDPrefix+svc.Service.String(), s.ch)
@ -1012,7 +1012,7 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
Datacenter: s.source.Datacenter, Datacenter: s.source.Datacenter,
QueryOptions: structs.QueryOptions{Token: s.token}, QueryOptions: structs.QueryOptions{Token: s.token},
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: svc.Service.ID, Name: svc.Service.Name,
EnterpriseMeta: svc.Service.EnterpriseMeta, EnterpriseMeta: svc.Service.EnterpriseMeta,
}, serviceResolverIDPrefix+svc.Service.String(), s.ch) }, serviceResolverIDPrefix+svc.Service.String(), s.ch)
@ -1029,54 +1029,54 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
} }
// Delete gateway service mapping for services that were not in the update // Delete gateway service mapping for services that were not in the update
for sid, _ := range snap.TerminatingGateway.GatewayServices { for sn, _ := range snap.TerminatingGateway.GatewayServices {
if _, ok := svcMap[sid]; !ok { if _, ok := svcMap[sn]; !ok {
delete(snap.TerminatingGateway.GatewayServices, sid) delete(snap.TerminatingGateway.GatewayServices, sn)
} }
} }
// Clean up services with hostname mapping for services that were not in the update // Clean up services with hostname mapping for services that were not in the update
for sid, _ := range snap.TerminatingGateway.HostnameServices { for sn, _ := range snap.TerminatingGateway.HostnameServices {
if _, ok := svcMap[sid]; !ok { if _, ok := svcMap[sn]; !ok {
delete(snap.TerminatingGateway.HostnameServices, sid) delete(snap.TerminatingGateway.HostnameServices, sn)
} }
} }
// Cancel service instance watches for services that were not in the update // Cancel service instance watches for services that were not in the update
for sid, cancelFn := range snap.TerminatingGateway.WatchedServices { for sn, cancelFn := range snap.TerminatingGateway.WatchedServices {
if _, ok := svcMap[sid]; !ok { if _, ok := svcMap[sn]; !ok {
logger.Debug("canceling watch for service", "service", sid.String()) logger.Debug("canceling watch for service", "service", sn.String())
delete(snap.TerminatingGateway.WatchedServices, sid) delete(snap.TerminatingGateway.WatchedServices, sn)
delete(snap.TerminatingGateway.ServiceGroups, sid) delete(snap.TerminatingGateway.ServiceGroups, sn)
cancelFn() cancelFn()
} }
} }
// Cancel leaf cert watches for services that were not in the update // Cancel leaf cert watches for services that were not in the update
for sid, cancelFn := range snap.TerminatingGateway.WatchedLeaves { for sn, cancelFn := range snap.TerminatingGateway.WatchedLeaves {
if _, ok := svcMap[sid]; !ok { if _, ok := svcMap[sn]; !ok {
logger.Debug("canceling watch for leaf cert", "service", sid.String()) logger.Debug("canceling watch for leaf cert", "service", sn.String())
delete(snap.TerminatingGateway.WatchedLeaves, sid) delete(snap.TerminatingGateway.WatchedLeaves, sn)
delete(snap.TerminatingGateway.ServiceLeaves, sid) delete(snap.TerminatingGateway.ServiceLeaves, sn)
cancelFn() cancelFn()
} }
} }
// Cancel service-resolver watches for services that were not in the update // Cancel service-resolver watches for services that were not in the update
for sid, cancelFn := range snap.TerminatingGateway.WatchedResolvers { for sn, cancelFn := range snap.TerminatingGateway.WatchedResolvers {
if _, ok := svcMap[sid]; !ok { if _, ok := svcMap[sn]; !ok {
logger.Debug("canceling watch for service-resolver", "service", sid.String()) logger.Debug("canceling watch for service-resolver", "service", sn.String())
delete(snap.TerminatingGateway.WatchedResolvers, sid) delete(snap.TerminatingGateway.WatchedResolvers, sn)
delete(snap.TerminatingGateway.ServiceResolvers, sid) delete(snap.TerminatingGateway.ServiceResolvers, sn)
cancelFn() cancelFn()
} }
} }
// Cancel intention watches for services that were not in the update // Cancel intention watches for services that were not in the update
for sid, cancelFn := range snap.TerminatingGateway.WatchedIntentions { for sn, cancelFn := range snap.TerminatingGateway.WatchedIntentions {
if _, ok := svcMap[sid]; !ok { if _, ok := svcMap[sn]; !ok {
logger.Debug("canceling watch for intention", "service", sid.String()) logger.Debug("canceling watch for intention", "service", sn.String())
delete(snap.TerminatingGateway.WatchedIntentions, sid) delete(snap.TerminatingGateway.WatchedIntentions, sn)
// No additional deletions needed, since intentions aren't stored in snapshot // No additional deletions needed, since intentions aren't stored in snapshot
@ -1090,13 +1090,13 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
return fmt.Errorf("invalid type for response: %T", u.Result) return fmt.Errorf("invalid type for response: %T", u.Result)
} }
sid := structs.ServiceIDFromString(strings.TrimPrefix(u.CorrelationID, externalServiceIDPrefix)) sn := structs.ServiceNameFromString(strings.TrimPrefix(u.CorrelationID, externalServiceIDPrefix))
delete(snap.TerminatingGateway.ServiceGroups, sid) delete(snap.TerminatingGateway.ServiceGroups, sn)
delete(snap.TerminatingGateway.HostnameServices, sid) delete(snap.TerminatingGateway.HostnameServices, sn)
if len(resp.Nodes) > 0 { if len(resp.Nodes) > 0 {
snap.TerminatingGateway.ServiceGroups[sid] = resp.Nodes snap.TerminatingGateway.ServiceGroups[sn] = resp.Nodes
snap.TerminatingGateway.HostnameServices[sid] = s.hostnameEndpoints(logging.TerminatingGateway, snap.Datacenter, resp.Nodes) snap.TerminatingGateway.HostnameServices[sn] = s.hostnameEndpoints(logging.TerminatingGateway, snap.Datacenter, resp.Nodes)
} }
// Store leaf cert for watched service // Store leaf cert for watched service
@ -1106,8 +1106,8 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
return fmt.Errorf("invalid type for response: %T", u.Result) return fmt.Errorf("invalid type for response: %T", u.Result)
} }
sid := structs.ServiceIDFromString(strings.TrimPrefix(u.CorrelationID, serviceLeafIDPrefix)) sn := structs.ServiceNameFromString(strings.TrimPrefix(u.CorrelationID, serviceLeafIDPrefix))
snap.TerminatingGateway.ServiceLeaves[sid] = leaf snap.TerminatingGateway.ServiceLeaves[sn] = leaf
case strings.HasPrefix(u.CorrelationID, "service-resolver:"): case strings.HasPrefix(u.CorrelationID, "service-resolver:"):
configEntries, ok := u.Result.(*structs.IndexedConfigEntries) configEntries, ok := u.Result.(*structs.IndexedConfigEntries)
@ -1117,7 +1117,7 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
// There should only ever be one entry for a service resolver within a namespace // There should only ever be one entry for a service resolver within a namespace
if len(configEntries.Entries) == 1 { if len(configEntries.Entries) == 1 {
if resolver, ok := configEntries.Entries[0].(*structs.ServiceResolverConfigEntry); ok { if resolver, ok := configEntries.Entries[0].(*structs.ServiceResolverConfigEntry); ok {
snap.TerminatingGateway.ServiceResolvers[structs.NewServiceID(resolver.Name, &resolver.EnterpriseMeta)] = resolver snap.TerminatingGateway.ServiceResolvers[structs.NewServiceName(resolver.Name, &resolver.EnterpriseMeta)] = resolver
} }
} }
@ -1169,32 +1169,31 @@ func (s *state) handleUpdateMeshGateway(u cache.UpdateEvent, snap *ConfigSnapsho
return fmt.Errorf("invalid type for response: %T", u.Result) return fmt.Errorf("invalid type for response: %T", u.Result)
} }
svcMap := make(map[structs.ServiceID]struct{}) svcMap := make(map[structs.ServiceName]struct{})
for _, svc := range services.Services { for _, svc := range services.Services {
sid := svc.ToServiceID()
// Make sure to add every service to this map, we use it to cancel // Make sure to add every service to this map, we use it to cancel
// watches below. // watches below.
svcMap[sid] = struct{}{} svcMap[svc] = struct{}{}
if _, ok := snap.MeshGateway.WatchedServices[sid]; !ok { if _, ok := snap.MeshGateway.WatchedServices[svc]; !ok {
ctx, cancel := context.WithCancel(s.ctx) ctx, cancel := context.WithCancel(s.ctx)
err := s.cache.Notify(ctx, cachetype.HealthServicesName, &structs.ServiceSpecificRequest{ err := s.cache.Notify(ctx, cachetype.HealthServicesName, &structs.ServiceSpecificRequest{
Datacenter: s.source.Datacenter, Datacenter: s.source.Datacenter,
QueryOptions: structs.QueryOptions{Token: s.token}, QueryOptions: structs.QueryOptions{Token: s.token},
ServiceName: svc.Name, ServiceName: svc.Name,
Connect: true, Connect: true,
EnterpriseMeta: sid.EnterpriseMeta, EnterpriseMeta: svc.EnterpriseMeta,
}, fmt.Sprintf("connect-service:%s", sid.String()), s.ch) }, fmt.Sprintf("connect-service:%s", svc.String()), s.ch)
if err != nil { if err != nil {
meshLogger.Error("failed to register watch for connect-service", meshLogger.Error("failed to register watch for connect-service",
"service", sid.String(), "service", svc.String(),
"error", err, "error", err,
) )
cancel() cancel()
return err return err
} }
snap.MeshGateway.WatchedServices[sid] = cancel snap.MeshGateway.WatchedServices[svc] = cancel
} }
} }
@ -1269,10 +1268,10 @@ func (s *state) handleUpdateMeshGateway(u cache.UpdateEvent, snap *ConfigSnapsho
return fmt.Errorf("invalid type for response: %T", u.Result) return fmt.Errorf("invalid type for response: %T", u.Result)
} }
resolvers := make(map[structs.ServiceID]*structs.ServiceResolverConfigEntry) resolvers := make(map[structs.ServiceName]*structs.ServiceResolverConfigEntry)
for _, entry := range configEntries.Entries { for _, entry := range configEntries.Entries {
if resolver, ok := entry.(*structs.ServiceResolverConfigEntry); ok { if resolver, ok := entry.(*structs.ServiceResolverConfigEntry); ok {
resolvers[structs.NewServiceID(resolver.Name, &resolver.EnterpriseMeta)] = resolver resolvers[structs.NewServiceName(resolver.Name, &resolver.EnterpriseMeta)] = resolver
} }
} }
snap.MeshGateway.ServiceResolvers = resolvers snap.MeshGateway.ServiceResolvers = resolvers
@ -1305,12 +1304,12 @@ func (s *state) handleUpdateMeshGateway(u cache.UpdateEvent, snap *ConfigSnapsho
return fmt.Errorf("invalid type for response: %T", u.Result) return fmt.Errorf("invalid type for response: %T", u.Result)
} }
sid := structs.ServiceIDFromString(strings.TrimPrefix(u.CorrelationID, "connect-service:")) sn := structs.ServiceNameFromString(strings.TrimPrefix(u.CorrelationID, "connect-service:"))
if len(resp.Nodes) > 0 { if len(resp.Nodes) > 0 {
snap.MeshGateway.ServiceGroups[sid] = resp.Nodes snap.MeshGateway.ServiceGroups[sn] = resp.Nodes
} else if _, ok := snap.MeshGateway.ServiceGroups[sid]; ok { } else if _, ok := snap.MeshGateway.ServiceGroups[sn]; ok {
delete(snap.MeshGateway.ServiceGroups, sid) delete(snap.MeshGateway.ServiceGroups, sn)
} }
case strings.HasPrefix(u.CorrelationID, "mesh-gateway:"): case strings.HasPrefix(u.CorrelationID, "mesh-gateway:"):
resp, ok := u.Result.(*structs.IndexedCheckServiceNodes) resp, ok := u.Result.(*structs.IndexedCheckServiceNodes)
@ -1412,7 +1411,7 @@ func (s *state) handleUpdateIngressGateway(u cache.UpdateEvent, snap *ConfigSnap
func makeUpstream(g *structs.GatewayService) structs.Upstream { func makeUpstream(g *structs.GatewayService) structs.Upstream {
upstream := structs.Upstream{ upstream := structs.Upstream{
DestinationName: g.Service.ID, DestinationName: g.Service.Name,
DestinationNamespace: g.Service.NamespaceOrDefault(), DestinationNamespace: g.Service.NamespaceOrDefault(),
LocalBindPort: g.Port, LocalBindPort: g.Port,
IngressHosts: g.Hosts, IngressHosts: g.Hosts,
@ -1565,11 +1564,11 @@ func (s *state) hostnameEndpoints(loggerName string, localDC string, nodes struc
if hasHostname && hasIP { if hasHostname && hasIP {
dc := nodes[0].Node.Datacenter dc := nodes[0].Node.Datacenter
sid := nodes[0].Service.CompoundServiceName() sn := nodes[0].Service.CompoundServiceName()
s.logger.Named(loggerName). s.logger.Named(loggerName).
Warn("service contains instances with mix of hostnames and IP addresses; only hostnames will be passed to Envoy", Warn("service contains instances with mix of hostnames and IP addresses; only hostnames will be passed to Envoy",
"dc", dc, "service", sid.String()) "dc", dc, "service", sn.String())
} }
return resp return resp
} }

View File

@ -596,10 +596,10 @@ func TestState_WatchesAndUpdates(t *testing.T) {
} }
// Used in terminating-gateway cases to account for differences in OSS/ent implementations of ServiceID.String() // Used in terminating-gateway cases to account for differences in OSS/ent implementations of ServiceID.String()
db := structs.NewServiceID("db", nil) db := structs.NewServiceName("db", nil)
dbStr := db.String() dbStr := db.String()
api := structs.NewServiceID("api", nil) api := structs.NewServiceName("api", nil)
apiStr := api.String() apiStr := api.String()
cases := map[string]testCase{ cases := map[string]testCase{
@ -855,8 +855,8 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Result: &structs.IndexedGatewayServices{ Result: &structs.IndexedGatewayServices{
Services: structs.GatewayServices{ Services: structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress-gateway", nil), Gateway: structs.NewServiceName("ingress-gateway", nil),
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Port: 9999, Port: 9999,
Protocol: "http", Protocol: "http",
}, },
@ -994,8 +994,8 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Result: &structs.IndexedGatewayServices{ Result: &structs.IndexedGatewayServices{
Services: structs.GatewayServices{ Services: structs.GatewayServices{
{ {
Gateway: structs.NewServiceID("ingress-gateway", nil), Gateway: structs.NewServiceName("ingress-gateway", nil),
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Hosts: []string{"test.example.com"}, Hosts: []string{"test.example.com"},
Port: 9999, Port: 9999,
}, },
@ -1105,8 +1105,8 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Result: &structs.IndexedGatewayServices{ Result: &structs.IndexedGatewayServices{
Services: structs.GatewayServices{ Services: structs.GatewayServices{
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("terminating-gateway", nil), Gateway: structs.NewServiceName("terminating-gateway", nil),
}, },
}, },
}, },
@ -1125,16 +1125,16 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Result: &structs.IndexedGatewayServices{ Result: &structs.IndexedGatewayServices{
Services: structs.GatewayServices{ Services: structs.GatewayServices{
{ {
Service: structs.NewServiceID("db", nil), Service: structs.NewServiceName("db", nil),
Gateway: structs.NewServiceID("terminating-gateway", nil), Gateway: structs.NewServiceName("terminating-gateway", nil),
}, },
{ {
Service: structs.NewServiceID("billing", nil), Service: structs.NewServiceName("billing", nil),
Gateway: structs.NewServiceID("terminating-gateway", nil), Gateway: structs.NewServiceName("terminating-gateway", nil),
}, },
{ {
Service: structs.NewServiceID("api", nil), Service: structs.NewServiceName("api", nil),
Gateway: structs.NewServiceID("terminating-gateway", nil), Gateway: structs.NewServiceName("terminating-gateway", nil),
}, },
}, },
}, },
@ -1142,9 +1142,9 @@ func TestState_WatchesAndUpdates(t *testing.T) {
}, },
}, },
verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) { verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) {
db := structs.NewServiceID("db", nil) db := structs.NewServiceName("db", nil)
billing := structs.NewServiceID("billing", nil) billing := structs.NewServiceName("billing", nil)
api := structs.NewServiceID("api", nil) api := structs.NewServiceName("api", nil)
require.True(t, snap.Valid(), "gateway with service list is valid") require.True(t, snap.Valid(), "gateway with service list is valid")
require.Len(t, snap.TerminatingGateway.WatchedServices, 3) require.Len(t, snap.TerminatingGateway.WatchedServices, 3)
@ -1199,7 +1199,7 @@ func TestState_WatchesAndUpdates(t *testing.T) {
}, },
verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) { verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) {
require.Len(t, snap.TerminatingGateway.ServiceGroups, 1) require.Len(t, snap.TerminatingGateway.ServiceGroups, 1)
require.Equal(t, snap.TerminatingGateway.ServiceGroups[structs.NewServiceID("db", nil)], require.Equal(t, snap.TerminatingGateway.ServiceGroups[structs.NewServiceName("db", nil)],
structs.CheckServiceNodes{ structs.CheckServiceNodes{
{ {
Node: &structs.Node{ Node: &structs.Node{
@ -1299,11 +1299,11 @@ func TestState_WatchesAndUpdates(t *testing.T) {
}, },
}, },
} }
sid := structs.NewServiceID("api", nil) sn := structs.NewServiceName("api", nil)
require.Equal(t, snap.TerminatingGateway.ServiceGroups[sid], expect) require.Equal(t, snap.TerminatingGateway.ServiceGroups[sn], expect)
// The instance in node3 should not be present in HostnameDatacenters because it has a valid IP // The instance in node3 should not be present in HostnameDatacenters because it has a valid IP
require.ElementsMatch(t, snap.TerminatingGateway.HostnameServices[sid], expect[:2]) require.ElementsMatch(t, snap.TerminatingGateway.HostnameServices[sn], expect[:2])
}, },
}, },
verificationStage{ verificationStage{
@ -1318,7 +1318,7 @@ func TestState_WatchesAndUpdates(t *testing.T) {
}, },
}, },
verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) { verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) {
require.Equal(t, snap.TerminatingGateway.ServiceLeaves[structs.NewServiceID("db", nil)], issuedCert) require.Equal(t, snap.TerminatingGateway.ServiceLeaves[structs.NewServiceName("db", nil)], issuedCert)
}, },
}, },
verificationStage{ verificationStage{
@ -1353,7 +1353,7 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Datacenter: "dc2", Datacenter: "dc2",
}, },
} }
require.Equal(t, want, snap.TerminatingGateway.ServiceResolvers[structs.NewServiceID("db", nil)]) require.Equal(t, want, snap.TerminatingGateway.ServiceResolvers[structs.NewServiceName("db", nil)])
}, },
}, },
verificationStage{ verificationStage{
@ -1363,8 +1363,8 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Result: &structs.IndexedGatewayServices{ Result: &structs.IndexedGatewayServices{
Services: structs.GatewayServices{ Services: structs.GatewayServices{
{ {
Service: structs.NewServiceID("billing", nil), Service: structs.NewServiceName("billing", nil),
Gateway: structs.NewServiceID("terminating-gateway", nil), Gateway: structs.NewServiceName("terminating-gateway", nil),
}, },
}, },
}, },
@ -1372,7 +1372,7 @@ func TestState_WatchesAndUpdates(t *testing.T) {
}, },
}, },
verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) { verifySnapshot: func(t testing.TB, snap *ConfigSnapshot) {
billing := structs.NewServiceID("billing", nil) billing := structs.NewServiceName("billing", nil)
require.True(t, snap.Valid(), "gateway with service list is valid") require.True(t, snap.Valid(), "gateway with service list is valid")

View File

@ -1373,17 +1373,17 @@ func testConfigSnapshotMeshGateway(t testing.T, populateServices bool, useFedera
if populateServices { if populateServices {
snap.MeshGateway = configSnapshotMeshGateway{ snap.MeshGateway = configSnapshotMeshGateway{
WatchedServices: map[structs.ServiceID]context.CancelFunc{ WatchedServices: map[structs.ServiceName]context.CancelFunc{
structs.NewServiceID("foo", nil): nil, structs.NewServiceName("foo", nil): nil,
structs.NewServiceID("bar", nil): nil, structs.NewServiceName("bar", nil): nil,
}, },
WatchedServicesSet: true, WatchedServicesSet: true,
WatchedDatacenters: map[string]context.CancelFunc{ WatchedDatacenters: map[string]context.CancelFunc{
"dc2": nil, "dc2": nil,
}, },
ServiceGroups: map[structs.ServiceID]structs.CheckServiceNodes{ ServiceGroups: map[structs.ServiceName]structs.CheckServiceNodes{
structs.NewServiceID("foo", nil): TestGatewayServiceGroupFooDC1(t), structs.NewServiceName("foo", nil): TestGatewayServiceGroupFooDC1(t),
structs.NewServiceID("bar", nil): TestGatewayServiceGroupBarDC1(t), structs.NewServiceName("bar", nil): TestGatewayServiceGroupBarDC1(t),
}, },
GatewayGroups: map[string]structs.CheckServiceNodes{ GatewayGroups: map[string]structs.CheckServiceNodes{
"dc2": TestGatewayNodesDC2(t), "dc2": TestGatewayNodesDC2(t),
@ -1607,7 +1607,7 @@ func testConfigSnapshotTerminatingGateway(t testing.T, populateServices bool) *C
Datacenter: "dc1", Datacenter: "dc1",
} }
if populateServices { if populateServices {
web := structs.NewServiceID("web", nil) web := structs.NewServiceName("web", nil)
webNodes := TestUpstreamNodes(t) webNodes := TestUpstreamNodes(t)
webNodes[0].Service.Meta = map[string]string{ webNodes[0].Service.Meta = map[string]string{
"version": "1", "version": "1",
@ -1616,7 +1616,7 @@ func testConfigSnapshotTerminatingGateway(t testing.T, populateServices bool) *C
"version": "2", "version": "2",
} }
api := structs.NewServiceID("api", nil) api := structs.NewServiceName("api", nil)
apiNodes := structs.CheckServiceNodes{ apiNodes := structs.CheckServiceNodes{
structs.CheckServiceNode{ structs.CheckServiceNode{
Node: &structs.Node{ Node: &structs.Node{
@ -1673,11 +1673,11 @@ func testConfigSnapshotTerminatingGateway(t testing.T, populateServices bool) *C
} }
snap.TerminatingGateway = configSnapshotTerminatingGateway{ snap.TerminatingGateway = configSnapshotTerminatingGateway{
ServiceGroups: map[structs.ServiceID]structs.CheckServiceNodes{ ServiceGroups: map[structs.ServiceName]structs.CheckServiceNodes{
web: webNodes, web: webNodes,
api: apiNodes, api: apiNodes,
}, },
GatewayServices: map[structs.ServiceID]structs.GatewayService{ GatewayServices: map[structs.ServiceName]structs.GatewayService{
web: { web: {
Service: web, Service: web,
CAFile: "ca.cert.pem", CAFile: "ca.cert.pem",
@ -1689,16 +1689,16 @@ func testConfigSnapshotTerminatingGateway(t testing.T, populateServices bool) *C
KeyFile: "api.key.pem", KeyFile: "api.key.pem",
}, },
}, },
HostnameServices: map[structs.ServiceID]structs.CheckServiceNodes{ HostnameServices: map[structs.ServiceName]structs.CheckServiceNodes{
api: {apiNodes[0], apiNodes[1]}, api: {apiNodes[0], apiNodes[1]},
}, },
} }
snap.TerminatingGateway.ServiceLeaves = map[structs.ServiceID]*structs.IssuedCert{ snap.TerminatingGateway.ServiceLeaves = map[structs.ServiceName]*structs.IssuedCert{
structs.NewServiceID("web", nil): { structs.NewServiceName("web", nil): {
CertPEM: golden(t, "test-leaf-cert"), CertPEM: golden(t, "test-leaf-cert"),
PrivateKeyPEM: golden(t, "test-leaf-key"), PrivateKeyPEM: golden(t, "test-leaf-key"),
}, },
structs.NewServiceID("api", nil): { structs.NewServiceName("api", nil): {
CertPEM: golden(t, "alt-test-leaf-cert"), CertPEM: golden(t, "alt-test-leaf-cert"),
PrivateKeyPEM: golden(t, "alt-test-leaf-key"), PrivateKeyPEM: golden(t, "alt-test-leaf-key"),
}, },

View File

@ -231,8 +231,8 @@ func (e *IngressGatewayConfigEntry) GetEnterpriseMeta() *EnterpriseMeta {
return &e.EnterpriseMeta return &e.EnterpriseMeta
} }
func (s *IngressService) ToServiceID() ServiceID { func (s *IngressService) ToServiceName() ServiceName {
return NewServiceID(s.Name, &s.EnterpriseMeta) return NewServiceName(s.Name, &s.EnterpriseMeta)
} }
// TerminatingGatewayConfigEntry manages the configuration for a terminating service // TerminatingGatewayConfigEntry manages the configuration for a terminating service
@ -360,17 +360,17 @@ func (e *TerminatingGatewayConfigEntry) GetEnterpriseMeta() *EnterpriseMeta {
// GatewayService is used to associate gateways with their linked services. // GatewayService is used to associate gateways with their linked services.
type GatewayService struct { type GatewayService struct {
Gateway ServiceID Gateway ServiceName
Service ServiceID Service ServiceName
GatewayKind ServiceKind GatewayKind ServiceKind
Port int Port int `json:",omitempty"`
Protocol string Protocol string `json:",omitempty"`
Hosts []string Hosts []string `json:",omitempty"`
CAFile string CAFile string `json:",omitempty"`
CertFile string CertFile string `json:",omitempty"`
KeyFile string KeyFile string `json:",omitempty"`
SNI string SNI string `json:",omitempty"`
FromWildcard bool FromWildcard bool `json:",omitempty"`
RaftIndex RaftIndex
} }

View File

@ -840,12 +840,10 @@ func (s *ServiceNode) ToNodeService() *NodeService {
} }
} }
func (sn *ServiceNode) compoundID(preferName bool) ServiceID { func (sn *ServiceNode) CompoundServiceID() ServiceID {
var id string id := sn.ServiceID
if sn.ServiceID == "" || (preferName && sn.ServiceName != "") { if id == "" {
id = sn.ServiceName id = sn.ServiceName
} else {
id = sn.ServiceID
} }
// copy the ent meta and normalize it // copy the ent meta and normalize it
@ -858,12 +856,20 @@ func (sn *ServiceNode) compoundID(preferName bool) ServiceID {
} }
} }
func (sn *ServiceNode) CompoundServiceID() ServiceID { func (sn *ServiceNode) CompoundServiceName() ServiceName {
return sn.compoundID(false) name := sn.ServiceName
} if name == "" {
name = sn.ServiceID
}
func (sn *ServiceNode) CompoundServiceName() ServiceID { // copy the ent meta and normalize it
return sn.compoundID(true) entMeta := sn.EnterpriseMeta
entMeta.Normalize()
return ServiceName{
Name: name,
EnterpriseMeta: entMeta,
}
} }
// Weights represent the weight used by DNS for a given status // Weights represent the weight used by DNS for a given status
@ -1000,11 +1006,35 @@ func (ns *NodeService) compoundID(preferName bool) ServiceID {
} }
func (ns *NodeService) CompoundServiceID() ServiceID { func (ns *NodeService) CompoundServiceID() ServiceID {
return ns.compoundID(false) id := ns.ID
if id == "" {
id = ns.Service
}
// copy the ent meta and normalize it
entMeta := ns.EnterpriseMeta
entMeta.Normalize()
return ServiceID{
ID: id,
EnterpriseMeta: entMeta,
}
} }
func (ns *NodeService) CompoundServiceName() ServiceID { func (ns *NodeService) CompoundServiceName() ServiceName {
return ns.compoundID(true) name := ns.Service
if name == "" {
name = ns.ID
}
// copy the ent meta and normalize it
entMeta := ns.EnterpriseMeta
entMeta.Normalize()
return ServiceName{
Name: name,
EnterpriseMeta: entMeta,
}
} }
// ServiceConnect are the shared Connect settings between all service // ServiceConnect are the shared Connect settings between all service
@ -1727,6 +1757,30 @@ type ServiceName struct {
EnterpriseMeta EnterpriseMeta
} }
func NewServiceName(name string, entMeta *EnterpriseMeta) ServiceName {
var ret ServiceName
ret.Name = name
if entMeta == nil {
entMeta = DefaultEnterpriseMeta()
}
ret.EnterpriseMeta = *entMeta
ret.EnterpriseMeta.Normalize()
return ret
}
func (n *ServiceName) Matches(o *ServiceName) bool {
if n == nil && o == nil {
return true
}
if n == nil || o == nil || n.Name != o.Name || !n.EnterpriseMeta.Matches(&o.EnterpriseMeta) {
return false
}
return true
}
func (si *ServiceName) ToServiceID() ServiceID { func (si *ServiceName) ToServiceID() ServiceID {
return ServiceID{ID: si.Name, EnterpriseMeta: si.EnterpriseMeta} return ServiceID{ID: si.Name, EnterpriseMeta: si.EnterpriseMeta}
} }

View File

@ -106,6 +106,19 @@ func ServiceIDFromString(input string) ServiceID {
return ServiceID{ID: id} return ServiceID{ID: id}
} }
func ParseServiceNameString(input string) (string, *EnterpriseMeta) {
return input, DefaultEnterpriseMeta()
}
func (n *ServiceName) String() string {
return n.Name
}
func ServiceNameFromString(input string) ServiceName {
id, _ := ParseServiceNameString(input)
return ServiceName{Name: id}
}
func (cid *CheckID) String() string { func (cid *CheckID) String() string {
return string(cid.ID) return string(cid.ID)
} }

View File

@ -2124,8 +2124,8 @@ func TestSnapshotRequestResponse_MsgpackEncodeDecode(t *testing.T) {
} }
func TestGatewayService_IsSame(t *testing.T) { func TestGatewayService_IsSame(t *testing.T) {
gateway := NewServiceID("gateway", nil) gateway := NewServiceName("gateway", nil)
svc := NewServiceID("web", nil) svc := NewServiceName("web", nil)
kind := ServiceKindTerminatingGateway kind := ServiceKindTerminatingGateway
ca := "ca.pem" ca := "ca.pem"
cert := "client.pem" cert := "client.pem"
@ -2169,8 +2169,8 @@ func TestGatewayService_IsSame(t *testing.T) {
t.Fatalf("should be the same") t.Fatalf("should be the same")
} }
} }
check(func() { other.Gateway = NewServiceID("other", nil) }, func() { other.Gateway = gateway }) check(func() { other.Gateway = NewServiceName("other", nil) }, func() { other.Gateway = gateway })
check(func() { other.Service = NewServiceID("other", nil) }, func() { other.Service = svc }) check(func() { other.Service = NewServiceName("other", nil) }, func() { other.Service = svc })
check(func() { other.GatewayKind = ServiceKindIngressGateway }, func() { other.GatewayKind = kind }) check(func() { other.GatewayKind = ServiceKindIngressGateway }, func() { other.GatewayKind = kind })
check(func() { other.CAFile = "/certs/cert.pem" }, func() { other.CAFile = ca }) check(func() { other.CAFile = "/certs/cert.pem" }, func() { other.CAFile = ca })
check(func() { other.CertFile = "/certs/cert.pem" }, func() { other.CertFile = cert }) check(func() { other.CertFile = "/certs/cert.pem" }, func() { other.CertFile = cert })

View File

@ -220,7 +220,7 @@ func summarizeServices(dump structs.ServiceDump) []*ServiceSummary {
for _, csn := range dump { for _, csn := range dump {
if csn.GatewayService != nil { if csn.GatewayService != nil {
sum := getService(csn.GatewayService.Service) sum := getService(csn.GatewayService.Service.ToServiceID())
sum.GatewayConfig.ListenerPort = csn.GatewayService.Port sum.GatewayConfig.ListenerPort = csn.GatewayService.Port
} }

View File

@ -184,8 +184,8 @@ func (s *Server) clustersFromSnapshotMeshGateway(cfgSnap *proxycfg.ConfigSnapsho
} }
func (s *Server) makeGatewayServiceClusters(cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) { func (s *Server) makeGatewayServiceClusters(cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) {
var services map[structs.ServiceID]structs.CheckServiceNodes var services map[structs.ServiceName]structs.CheckServiceNodes
var resolvers map[structs.ServiceID]*structs.ServiceResolverConfigEntry var resolvers map[structs.ServiceName]*structs.ServiceResolverConfigEntry
var hostnameEndpoints structs.CheckServiceNodes var hostnameEndpoints structs.CheckServiceNodes
switch cfgSnap.Kind { switch cfgSnap.Kind {
@ -202,7 +202,7 @@ func (s *Server) makeGatewayServiceClusters(cfgSnap *proxycfg.ConfigSnapshot) ([
clusters := make([]proto.Message, 0, len(services)) clusters := make([]proto.Message, 0, len(services))
for svc, _ := range services { for svc, _ := range services {
clusterName := connect.ServiceSNI(svc.ID, "", svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain) clusterName := connect.ServiceSNI(svc.Name, "", svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain)
resolver, hasResolver := resolvers[svc] resolver, hasResolver := resolvers[svc]
if !hasResolver { if !hasResolver {
@ -236,7 +236,7 @@ func (s *Server) makeGatewayServiceClusters(cfgSnap *proxycfg.ConfigSnapshot) ([
} }
opts := gatewayClusterOpts{ opts := gatewayClusterOpts{
name: connect.ServiceSNI(svc.ID, name, svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain), name: connect.ServiceSNI(svc.Name, name, svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain),
hostnameEndpoints: subsetHostnameEndpoints, hostnameEndpoints: subsetHostnameEndpoints,
onlyPassing: subset.OnlyPassing, onlyPassing: subset.OnlyPassing,
connectTimeout: resolver.ConnectTimeout, connectTimeout: resolver.ConnectTimeout,
@ -691,7 +691,7 @@ func (s *Server) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, opts gatewayC
} }
// injectTerminatingGatewayTLSContext adds an UpstreamTlsContext to a cluster for TLS origination // injectTerminatingGatewayTLSContext adds an UpstreamTlsContext to a cluster for TLS origination
func injectTerminatingGatewayTLSContext(cfgSnap *proxycfg.ConfigSnapshot, cluster *envoy.Cluster, service structs.ServiceID) { func injectTerminatingGatewayTLSContext(cfgSnap *proxycfg.ConfigSnapshot, cluster *envoy.Cluster, service structs.ServiceName) {
if mapping, ok := cfgSnap.TerminatingGateway.GatewayServices[service]; ok && mapping.CAFile != "" { if mapping, ok := cfgSnap.TerminatingGateway.GatewayServices[service]; ok && mapping.CAFile != "" {
cluster.TlsContext = &envoyauth.UpstreamTlsContext{ cluster.TlsContext = &envoyauth.UpstreamTlsContext{
CommonTlsContext: makeCommonTLSContextFromFiles(mapping.CAFile, mapping.CertFile, mapping.KeyFile), CommonTlsContext: makeCommonTLSContextFromFiles(mapping.CAFile, mapping.CertFile, mapping.KeyFile),

View File

@ -268,8 +268,8 @@ func TestClustersFromSnapshot(t *testing.T) {
name: "mesh-gateway-service-subsets", name: "mesh-gateway-service-subsets",
create: proxycfg.TestConfigSnapshotMeshGateway, create: proxycfg.TestConfigSnapshotMeshGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.MeshGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("bar", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "bar", Name: "bar",
Subsets: map[string]structs.ServiceResolverSubset{ Subsets: map[string]structs.ServiceResolverSubset{
@ -289,8 +289,8 @@ func TestClustersFromSnapshot(t *testing.T) {
name: "mesh-gateway-ignore-extra-resolvers", name: "mesh-gateway-ignore-extra-resolvers",
create: proxycfg.TestConfigSnapshotMeshGateway, create: proxycfg.TestConfigSnapshotMeshGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.MeshGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("bar", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "bar", Name: "bar",
DefaultSubset: "v2", DefaultSubset: "v2",
@ -304,7 +304,7 @@ func TestClustersFromSnapshot(t *testing.T) {
}, },
}, },
}, },
structs.NewServiceID("notfound", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("notfound", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "notfound", Name: "notfound",
DefaultSubset: "v2", DefaultSubset: "v2",
@ -325,8 +325,8 @@ func TestClustersFromSnapshot(t *testing.T) {
name: "mesh-gateway-service-timeouts", name: "mesh-gateway-service-timeouts",
create: proxycfg.TestConfigSnapshotMeshGateway, create: proxycfg.TestConfigSnapshotMeshGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.MeshGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("bar", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "bar", Name: "bar",
ConnectTimeout: 10 * time.Second, ConnectTimeout: 10 * time.Second,
@ -432,8 +432,8 @@ func TestClustersFromSnapshot(t *testing.T) {
name: "terminating-gateway-service-subsets", name: "terminating-gateway-service-subsets",
create: proxycfg.TestConfigSnapshotTerminatingGateway, create: proxycfg.TestConfigSnapshotTerminatingGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("web", nil): { structs.NewServiceName("web", nil): {
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "web", Name: "web",
Subsets: map[string]structs.ServiceResolverSubset{ Subsets: map[string]structs.ServiceResolverSubset{
@ -453,8 +453,8 @@ func TestClustersFromSnapshot(t *testing.T) {
name: "terminating-gateway-hostname-service-subsets", name: "terminating-gateway-hostname-service-subsets",
create: proxycfg.TestConfigSnapshotTerminatingGateway, create: proxycfg.TestConfigSnapshotTerminatingGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("api", nil): { structs.NewServiceName("api", nil): {
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "api", Name: "api",
Subsets: map[string]structs.ServiceResolverSubset{ Subsets: map[string]structs.ServiceResolverSubset{
@ -470,8 +470,8 @@ func TestClustersFromSnapshot(t *testing.T) {
name: "terminating-gateway-ignore-extra-resolvers", name: "terminating-gateway-ignore-extra-resolvers",
create: proxycfg.TestConfigSnapshotTerminatingGateway, create: proxycfg.TestConfigSnapshotTerminatingGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("web", nil): { structs.NewServiceName("web", nil): {
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "web", Name: "web",
DefaultSubset: "v2", DefaultSubset: "v2",
@ -485,7 +485,7 @@ func TestClustersFromSnapshot(t *testing.T) {
}, },
}, },
}, },
structs.NewServiceID("notfound", nil): { structs.NewServiceName("notfound", nil): {
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "notfound", Name: "notfound",
DefaultSubset: "v2", DefaultSubset: "v2",

View File

@ -211,8 +211,8 @@ func (s *Server) endpointsFromSnapshotMeshGateway(cfgSnap *proxycfg.ConfigSnapsh
func (s *Server) endpointsFromServicesAndResolvers( func (s *Server) endpointsFromServicesAndResolvers(
cfgSnap *proxycfg.ConfigSnapshot, cfgSnap *proxycfg.ConfigSnapshot,
services map[structs.ServiceID]structs.CheckServiceNodes, services map[structs.ServiceName]structs.CheckServiceNodes,
resolvers map[structs.ServiceID]*structs.ServiceResolverConfigEntry) ([]proto.Message, error) { resolvers map[structs.ServiceName]*structs.ServiceResolverConfigEntry) ([]proto.Message, error) {
resources := make([]proto.Message, 0, len(services)) resources := make([]proto.Message, 0, len(services))
@ -249,7 +249,7 @@ func (s *Server) endpointsFromServicesAndResolvers(
// now generate the load assignment for all subsets // now generate the load assignment for all subsets
for subsetName, groups := range clusterEndpoints { for subsetName, groups := range clusterEndpoints {
clusterName := connect.ServiceSNI(svc.ID, subsetName, svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain) clusterName := connect.ServiceSNI(svc.Name, subsetName, svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain)
la := makeLoadAssignment( la := makeLoadAssignment(
clusterName, clusterName,
groups, groups,

View File

@ -326,8 +326,8 @@ func Test_endpointsFromSnapshot(t *testing.T) {
name: "mesh-gateway-service-subsets", name: "mesh-gateway-service-subsets",
create: proxycfg.TestConfigSnapshotMeshGateway, create: proxycfg.TestConfigSnapshotMeshGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.MeshGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("bar", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "bar", Name: "bar",
Subsets: map[string]structs.ServiceResolverSubset{ Subsets: map[string]structs.ServiceResolverSubset{
@ -340,7 +340,7 @@ func Test_endpointsFromSnapshot(t *testing.T) {
}, },
}, },
}, },
structs.NewServiceID("foo", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("foo", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "foo", Name: "foo",
Subsets: map[string]structs.ServiceResolverSubset{ Subsets: map[string]structs.ServiceResolverSubset{
@ -360,8 +360,8 @@ func Test_endpointsFromSnapshot(t *testing.T) {
name: "mesh-gateway-default-service-subset", name: "mesh-gateway-default-service-subset",
create: proxycfg.TestConfigSnapshotMeshGateway, create: proxycfg.TestConfigSnapshotMeshGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.MeshGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("bar", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("bar", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "bar", Name: "bar",
DefaultSubset: "v2", DefaultSubset: "v2",
@ -375,7 +375,7 @@ func Test_endpointsFromSnapshot(t *testing.T) {
}, },
}, },
}, },
structs.NewServiceID("foo", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("foo", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "foo", Name: "foo",
DefaultSubset: "v2", DefaultSubset: "v2",
@ -481,8 +481,8 @@ func Test_endpointsFromSnapshot(t *testing.T) {
name: "terminating-gateway-service-subsets", name: "terminating-gateway-service-subsets",
create: proxycfg.TestConfigSnapshotTerminatingGateway, create: proxycfg.TestConfigSnapshotTerminatingGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("web", nil): { structs.NewServiceName("web", nil): {
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "web", Name: "web",
Subsets: map[string]structs.ServiceResolverSubset{ Subsets: map[string]structs.ServiceResolverSubset{
@ -495,7 +495,7 @@ func Test_endpointsFromSnapshot(t *testing.T) {
}, },
}, },
}, },
structs.NewServiceID("web", nil): { structs.NewServiceName("web", nil): {
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "web", Name: "web",
Subsets: map[string]structs.ServiceResolverSubset{ Subsets: map[string]structs.ServiceResolverSubset{
@ -515,8 +515,8 @@ func Test_endpointsFromSnapshot(t *testing.T) {
name: "terminating-gateway-default-service-subset", name: "terminating-gateway-default-service-subset",
create: proxycfg.TestConfigSnapshotTerminatingGateway, create: proxycfg.TestConfigSnapshotTerminatingGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("web", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("web", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "web", Name: "web",
DefaultSubset: "v2", DefaultSubset: "v2",
@ -530,7 +530,7 @@ func Test_endpointsFromSnapshot(t *testing.T) {
}, },
}, },
}, },
structs.NewServiceID("web", nil): &structs.ServiceResolverConfigEntry{ structs.NewServiceName("web", nil): &structs.ServiceResolverConfigEntry{
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "web", Name: "web",
DefaultSubset: "v2", DefaultSubset: "v2",

View File

@ -557,7 +557,7 @@ func (s *Server) makeTerminatingGatewayListener(name, addr string, port int, cfg
// Make a FilterChain for each linked service // Make a FilterChain for each linked service
// Match on the cluster name, // Match on the cluster name,
for svc, _ := range cfgSnap.TerminatingGateway.ServiceGroups { for svc, _ := range cfgSnap.TerminatingGateway.ServiceGroups {
clusterName := connect.ServiceSNI(svc.ID, "", svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain) clusterName := connect.ServiceSNI(svc.Name, "", svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain)
resolver, hasResolver := cfgSnap.TerminatingGateway.ServiceResolvers[svc] resolver, hasResolver := cfgSnap.TerminatingGateway.ServiceResolvers[svc]
// Skip the service if we don't have a cert to present for mTLS // Skip the service if we don't have a cert to present for mTLS
@ -579,7 +579,7 @@ func (s *Server) makeTerminatingGatewayListener(name, addr string, port int, cfg
if hasResolver { if hasResolver {
// generate 1 filter chain for each service subset // generate 1 filter chain for each service subset
for subsetName := range resolver.Subsets { for subsetName := range resolver.Subsets {
clusterName := connect.ServiceSNI(svc.ID, subsetName, svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain) clusterName := connect.ServiceSNI(svc.Name, subsetName, svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain)
clusterChain, err := s.sniFilterChainTerminatingGateway(name, clusterName, token, svc, cfgSnap) clusterChain, err := s.sniFilterChainTerminatingGateway(name, clusterName, token, svc, cfgSnap)
if err != nil { if err != nil {
@ -607,7 +607,7 @@ func (s *Server) makeTerminatingGatewayListener(name, addr string, port int, cfg
return l, nil return l, nil
} }
func (s *Server) sniFilterChainTerminatingGateway(listener, cluster, token string, service structs.ServiceID, func (s *Server) sniFilterChainTerminatingGateway(listener, cluster, token string, service structs.ServiceName,
cfgSnap *proxycfg.ConfigSnapshot) (envoylistener.FilterChain, error) { cfgSnap *proxycfg.ConfigSnapshot) (envoylistener.FilterChain, error) {
authFilter, err := makeExtAuthFilter(token) authFilter, err := makeExtAuthFilter(token)
@ -620,7 +620,7 @@ func (s *Server) sniFilterChainTerminatingGateway(listener, cluster, token strin
} }
// The cluster name here doesn't matter as the sni_cluster filter will fill it in for us. // The cluster name here doesn't matter as the sni_cluster filter will fill it in for us.
statPrefix := fmt.Sprintf("terminating_gateway_%s_%s_", service.NamespaceOrDefault(), service.ID) statPrefix := fmt.Sprintf("terminating_gateway_%s_%s_", service.NamespaceOrDefault(), service.Name)
tcpProxy, err := makeTCPProxyFilter(listener, "", statPrefix) tcpProxy, err := makeTCPProxyFilter(listener, "", statPrefix)
if err != nil { if err != nil {
return envoylistener.FilterChain{}, err return envoylistener.FilterChain{}, err

View File

@ -361,8 +361,8 @@ func TestListenersFromSnapshot(t *testing.T) {
name: "terminating-gateway-service-subsets", name: "terminating-gateway-service-subsets",
create: proxycfg.TestConfigSnapshotTerminatingGateway, create: proxycfg.TestConfigSnapshotTerminatingGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceID]*structs.ServiceResolverConfigEntry{ snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
structs.NewServiceID("web", nil): { structs.NewServiceName("web", nil): {
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "web", Name: "web",
Subsets: map[string]structs.ServiceResolverSubset{ Subsets: map[string]structs.ServiceResolverSubset{
@ -375,7 +375,7 @@ func TestListenersFromSnapshot(t *testing.T) {
}, },
}, },
}, },
structs.NewServiceID("web", nil): { structs.NewServiceName("web", nil): {
Kind: structs.ServiceResolver, Kind: structs.ServiceResolver,
Name: "web", Name: "web",
Subsets: map[string]structs.ServiceResolverSubset{ Subsets: map[string]structs.ServiceResolverSubset{
@ -423,7 +423,7 @@ func TestListenersFromSnapshot(t *testing.T) {
name: "terminating-gateway-no-api-cert", name: "terminating-gateway-no-api-cert",
create: proxycfg.TestConfigSnapshotTerminatingGateway, create: proxycfg.TestConfigSnapshotTerminatingGateway,
setup: func(snap *proxycfg.ConfigSnapshot) { setup: func(snap *proxycfg.ConfigSnapshot) {
snap.TerminatingGateway.ServiceLeaves[structs.NewServiceID("api", nil)] = nil snap.TerminatingGateway.ServiceLeaves[structs.NewServiceName("api", nil)] = nil
}, },
}, },
{ {