diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 7acaa10706..c91070ea0d 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -2524,7 +2524,7 @@ func updateGatewayNamespace(tx WriteTxn, idx uint64, service *structs.GatewaySer continue } - existing, err := tx.First(tableGatewayServices, "id", service.Gateway, sn.CompoundServiceName(), service.Port) + existing, err := tx.First(tableGatewayServices, indexID, service.Gateway, sn.CompoundServiceName(), service.Port) if err != nil { return fmt.Errorf("gateway service lookup failed: %s", err) } @@ -2559,7 +2559,7 @@ func updateGatewayNamespace(tx WriteTxn, idx uint64, service *structs.GatewaySer func updateGatewayService(tx WriteTxn, idx uint64, mapping *structs.GatewayService) error { // Check if mapping already exists in table if it's already in the table // Avoid insert if nothing changed - existing, err := tx.First(tableGatewayServices, "id", mapping.Gateway, mapping.Service, mapping.Port) + existing, err := tx.First(tableGatewayServices, indexID, mapping.Gateway, mapping.Service, mapping.Port) if err != nil { return fmt.Errorf("gateway service lookup failed: %s", err) } @@ -2658,7 +2658,7 @@ func (s *Store) DumpGatewayServices(ws memdb.WatchSet) (uint64, structs.GatewayS tx := s.db.ReadTxn() defer tx.Abort() - iter, err := tx.Get(tableGatewayServices, "id") + iter, err := tx.Get(tableGatewayServices, indexID) if err != nil { return 0, nil, fmt.Errorf("failed to dump gateway-services: %s", err) } diff --git a/agent/consul/state/catalog_oss_test.go b/agent/consul/state/catalog_oss_test.go index 49bb76f210..cbaa1bf1f2 100644 --- a/agent/consul/state/catalog_oss_test.go +++ b/agent/consul/state/catalog_oss_test.go @@ -62,8 +62,7 @@ func testIndexerTableMeshTopology() map[string]indexerTestCase { }, indexUpstream: { read: indexValue{ - source: structs.ServiceName{Name: "UpStReAm"}, - + source: structs.ServiceName{Name: "UpStReAm"}, expected: []byte("upstream\x00"), }, write: indexValue{ @@ -73,8 +72,7 @@ func testIndexerTableMeshTopology() map[string]indexerTestCase { }, indexDownstream: { read: indexValue{ - source: structs.ServiceName{Name: "DownStream"}, - + source: structs.ServiceName{Name: "DownStream"}, expected: []byte("downstream\x00"), }, write: indexValue{ @@ -85,6 +83,51 @@ func testIndexerTableMeshTopology() map[string]indexerTestCase { } } +func testIndexerTableGatewayServices() map[string]indexerTestCase { + obj := &structs.GatewayService{ + Gateway: structs.ServiceName{Name: "GateWay"}, + Service: structs.ServiceName{Name: "SerVice"}, + Port: 50123, + } + encodedPort := string([]byte{0x96, 0x8f, 0x06, 0, 0, 0, 0, 0, 0, 0}) + return map[string]indexerTestCase{ + indexID: { + read: indexValue{ + source: []interface{}{ + structs.ServiceName{Name: "GateWay"}, + structs.ServiceName{Name: "SerVice"}, + 50123, + }, + expected: []byte("gateway\x00service\x00" + encodedPort), + }, + write: indexValue{ + source: obj, + expected: []byte("gateway\x00service\x00" + encodedPort), + }, + }, + indexGateway: { + read: indexValue{ + source: structs.ServiceName{Name: "GateWay"}, + expected: []byte("gateway\x00"), + }, + write: indexValue{ + source: obj, + expected: []byte("gateway\x00"), + }, + }, + indexService: { + read: indexValue{ + source: structs.ServiceName{Name: "SerVice"}, + expected: []byte("service\x00"), + }, + write: indexValue{ + source: obj, + expected: []byte("service\x00"), + }, + }, + } +} + func testIndexerTableNodes() map[string]indexerTestCase { return map[string]indexerTestCase{ indexID: { diff --git a/agent/consul/state/schema_test.go b/agent/consul/state/schema_test.go index 95c05a6fae..4851a314d8 100644 --- a/agent/consul/state/schema_test.go +++ b/agent/consul/state/schema_test.go @@ -128,11 +128,12 @@ func TestNewDBSchema_Indexers(t *testing.T) { require.NoError(t, schema.Validate()) var testcases = map[string]func() map[string]indexerTestCase{ - tableChecks: testIndexerTableChecks, - tableServices: testIndexerTableServices, - tableNodes: testIndexerTableNodes, - tableConfigEntries: testIndexerTableConfigEntries, - tableMeshTopology: testIndexerTableMeshTopology, + tableChecks: testIndexerTableChecks, + tableServices: testIndexerTableServices, + tableNodes: testIndexerTableNodes, + tableConfigEntries: testIndexerTableConfigEntries, + tableMeshTopology: testIndexerTableMeshTopology, + tableGatewayServices: testIndexerTableGatewayServices, } for _, table := range schema.Tables {