|
|
|
@ -4,13 +4,14 @@ import (
|
|
|
|
|
"context" |
|
|
|
|
crand "crypto/rand" |
|
|
|
|
"fmt" |
|
|
|
|
"github.com/hashicorp/consul/acl" |
|
|
|
|
"reflect" |
|
|
|
|
"sort" |
|
|
|
|
"strings" |
|
|
|
|
"testing" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/acl" |
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-memdb" |
|
|
|
|
"github.com/hashicorp/go-uuid" |
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
@ -5753,6 +5754,10 @@ func TestStateStore_GatewayServices_ServiceDeletion(t *testing.T) {
|
|
|
|
|
assert.Nil(t, s.EnsureService(13, "foo", &structs.NodeService{ID: "db", Service: "db", Tags: nil, Address: "", Port: 5000})) |
|
|
|
|
assert.Nil(t, s.EnsureService(14, "foo", &structs.NodeService{ID: "api", Service: "api", Tags: nil, Address: "", Port: 5000})) |
|
|
|
|
|
|
|
|
|
// Connect services (should be ignored by terminating gateway)
|
|
|
|
|
assert.Nil(t, s.EnsureService(15, "foo", &structs.NodeService{ID: "web", Service: "web", Tags: nil, Address: "", Connect: structs.ServiceConnect{Native: true}, Port: 5000})) |
|
|
|
|
assert.Nil(t, s.EnsureService(16, "bar", &structs.NodeService{ID: "api", Service: "api", Tags: nil, Address: "", Connect: structs.ServiceConnect{Native: true}, Port: 5000})) |
|
|
|
|
|
|
|
|
|
// Register two gateways
|
|
|
|
|
assert.Nil(t, s.EnsureService(17, "bar", &structs.NodeService{Kind: structs.ServiceKindTerminatingGateway, ID: "gateway", Service: "gateway", Port: 443})) |
|
|
|
|
assert.Nil(t, s.EnsureService(18, "baz", &structs.NodeService{Kind: structs.ServiceKindTerminatingGateway, ID: "other-gateway", Service: "other-gateway", Port: 443})) |
|
|
|
@ -5895,6 +5900,16 @@ func TestStateStore_GatewayServices_ServiceDeletion(t *testing.T) {
|
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
assert.Equal(t, expect, out) |
|
|
|
|
|
|
|
|
|
// Delete the non-connect instance of api
|
|
|
|
|
assert.Nil(t, s.DeleteService(21, "foo", "api", nil, "")) |
|
|
|
|
|
|
|
|
|
// Gateway with wildcard entry should have no services left, because the last
|
|
|
|
|
// non-connect instance of 'api' was deleted.
|
|
|
|
|
idx, out, err = s.GatewayServices(ws, "other-gateway", nil) |
|
|
|
|
assert.Nil(t, err) |
|
|
|
|
assert.Equal(t, idx, uint64(21)) |
|
|
|
|
assert.Empty(t, out) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestStateStore_CheckIngressServiceNodes(t *testing.T) { |
|
|
|
@ -5904,7 +5919,7 @@ func TestStateStore_CheckIngressServiceNodes(t *testing.T) {
|
|
|
|
|
t.Run("check service1 ingress gateway", func(t *testing.T) { |
|
|
|
|
idx, results, err := s.CheckIngressServiceNodes(ws, "service1", nil) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
require.Equal(t, uint64(15), idx) |
|
|
|
|
require.Equal(t, uint64(18), idx) |
|
|
|
|
// Multiple instances of the ingress2 service
|
|
|
|
|
require.Len(t, results, 4) |
|
|
|
|
|
|
|
|
@ -5923,7 +5938,7 @@ func TestStateStore_CheckIngressServiceNodes(t *testing.T) {
|
|
|
|
|
t.Run("check service2 ingress gateway", func(t *testing.T) { |
|
|
|
|
idx, results, err := s.CheckIngressServiceNodes(ws, "service2", nil) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
require.Equal(t, uint64(15), idx) |
|
|
|
|
require.Equal(t, uint64(18), idx) |
|
|
|
|
require.Len(t, results, 2) |
|
|
|
|
|
|
|
|
|
ids := make(map[string]struct{}) |
|
|
|
@ -5941,7 +5956,7 @@ func TestStateStore_CheckIngressServiceNodes(t *testing.T) {
|
|
|
|
|
ws := memdb.NewWatchSet() |
|
|
|
|
idx, results, err := s.CheckIngressServiceNodes(ws, "service3", nil) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
require.Equal(t, uint64(15), idx) |
|
|
|
|
require.Equal(t, uint64(18), idx) |
|
|
|
|
require.Len(t, results, 1) |
|
|
|
|
require.Equal(t, "wildcardIngress", results[0].Service.ID) |
|
|
|
|
}) |
|
|
|
@ -5952,17 +5967,17 @@ func TestStateStore_CheckIngressServiceNodes(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
idx, results, err := s.CheckIngressServiceNodes(ws, "service1", nil) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
require.Equal(t, uint64(15), idx) |
|
|
|
|
require.Equal(t, uint64(18), idx) |
|
|
|
|
require.Len(t, results, 3) |
|
|
|
|
|
|
|
|
|
idx, results, err = s.CheckIngressServiceNodes(ws, "service2", nil) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
require.Equal(t, uint64(15), idx) |
|
|
|
|
require.Equal(t, uint64(18), idx) |
|
|
|
|
require.Len(t, results, 1) |
|
|
|
|
|
|
|
|
|
idx, results, err = s.CheckIngressServiceNodes(ws, "service3", nil) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
require.Equal(t, uint64(15), idx) |
|
|
|
|
require.Equal(t, uint64(18), idx) |
|
|
|
|
// TODO(ingress): index goes backward when deleting last config entry
|
|
|
|
|
// require.Equal(t,uint64(11), idx)
|
|
|
|
|
require.Len(t, results, 0) |
|
|
|
@ -6346,8 +6361,8 @@ func TestStateStore_GatewayServices_IngressProtocolFiltering(t *testing.T) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
testRegisterNode(t, s, 0, "node1") |
|
|
|
|
testRegisterService(t, s, 1, "node1", "service1") |
|
|
|
|
testRegisterService(t, s, 2, "node1", "service2") |
|
|
|
|
testRegisterConnectService(t, s, 1, "node1", "service1") |
|
|
|
|
testRegisterConnectService(t, s, 2, "node1", "service2") |
|
|
|
|
assert.NoError(t, s.EnsureConfigEntry(4, ingress1)) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -6510,15 +6525,17 @@ func setupIngressState(t *testing.T, s *Store) memdb.WatchSet {
|
|
|
|
|
testRegisterNode(t, s, 0, "node1") |
|
|
|
|
testRegisterNode(t, s, 1, "node2") |
|
|
|
|
|
|
|
|
|
// Register a service against the nodes.
|
|
|
|
|
// Register some connect and non-connect services against the nodes.
|
|
|
|
|
testRegisterIngressService(t, s, 3, "node1", "wildcardIngress") |
|
|
|
|
testRegisterIngressService(t, s, 4, "node1", "ingress1") |
|
|
|
|
testRegisterIngressService(t, s, 5, "node1", "ingress2") |
|
|
|
|
testRegisterIngressService(t, s, 6, "node2", "ingress2") |
|
|
|
|
testRegisterIngressService(t, s, 7, "node1", "nothingIngress") |
|
|
|
|
testRegisterService(t, s, 8, "node1", "service1") |
|
|
|
|
testRegisterService(t, s, 9, "node2", "service2") |
|
|
|
|
testRegisterService(t, s, 10, "node2", "service3") |
|
|
|
|
testRegisterConnectService(t, s, 8, "node1", "service1") |
|
|
|
|
testRegisterConnectService(t, s, 9, "node2", "service2") |
|
|
|
|
testRegisterConnectService(t, s, 10, "node2", "service3") |
|
|
|
|
testRegisterService(t, s, 17, "node1", "service4") |
|
|
|
|
testRegisterService(t, s, 18, "node2", "service5") |
|
|
|
|
|
|
|
|
|
// Default protocol to http
|
|
|
|
|
proxyDefaults := &structs.ProxyConfigEntry{ |
|
|
|
@ -7883,6 +7900,7 @@ func TestCatalog_upstreamsFromRegistration_Ingress(t *testing.T) {
|
|
|
|
|
Address: "127.0.0.3", |
|
|
|
|
Port: 443, |
|
|
|
|
EnterpriseMeta: *defaultMeta, |
|
|
|
|
Connect: structs.ServiceConnect{Native: true}, |
|
|
|
|
} |
|
|
|
|
require.NoError(t, s.EnsureService(5, "foo", &svc)) |
|
|
|
|
assert.True(t, watchFired(ws)) |
|
|
|
|