2018-10-03 12:36:38 +00:00
|
|
|
package proxycfg
|
|
|
|
|
|
|
|
import (
|
2019-06-18 00:52:01 +00:00
|
|
|
"context"
|
2019-07-02 14:29:09 +00:00
|
|
|
"fmt"
|
2020-04-14 23:46:40 +00:00
|
|
|
"io/ioutil"
|
2019-07-12 19:16:21 +00:00
|
|
|
"path"
|
2020-04-14 23:46:40 +00:00
|
|
|
"path/filepath"
|
2018-10-03 12:36:38 +00:00
|
|
|
"sync"
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/cache"
|
|
|
|
cachetype "github.com/hashicorp/consul/agent/cache-types"
|
|
|
|
"github.com/hashicorp/consul/agent/connect"
|
2019-07-12 19:16:21 +00:00
|
|
|
"github.com/hashicorp/consul/agent/consul/discoverychain"
|
2018-10-03 12:36:38 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2020-06-19 19:31:39 +00:00
|
|
|
"github.com/hashicorp/consul/api"
|
2018-10-03 12:36:38 +00:00
|
|
|
"github.com/mitchellh/go-testing-interface"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestCacheTypes encapsulates all the different cache types proxycfg.State will
|
2018-10-09 16:57:26 +00:00
|
|
|
// watch/request for controlling one during testing.
|
2018-10-03 12:36:38 +00:00
|
|
|
type TestCacheTypes struct {
|
2019-09-26 02:55:52 +00:00
|
|
|
roots *ControllableCacheType
|
|
|
|
leaf *ControllableCacheType
|
|
|
|
intentions *ControllableCacheType
|
|
|
|
health *ControllableCacheType
|
|
|
|
query *ControllableCacheType
|
|
|
|
compiledChain *ControllableCacheType
|
|
|
|
serviceHTTPChecks *ControllableCacheType
|
2018-10-03 12:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewTestCacheTypes creates a set of ControllableCacheTypes for all types that
|
|
|
|
// proxycfg will watch suitable for testing a proxycfg.State or Manager.
|
|
|
|
func NewTestCacheTypes(t testing.T) *TestCacheTypes {
|
|
|
|
t.Helper()
|
|
|
|
ct := &TestCacheTypes{
|
2019-09-26 02:55:52 +00:00
|
|
|
roots: NewControllableCacheType(t),
|
|
|
|
leaf: NewControllableCacheType(t),
|
|
|
|
intentions: NewControllableCacheType(t),
|
|
|
|
health: NewControllableCacheType(t),
|
|
|
|
query: NewControllableCacheType(t),
|
|
|
|
compiledChain: NewControllableCacheType(t),
|
|
|
|
serviceHTTPChecks: NewControllableCacheType(t),
|
2018-10-03 12:36:38 +00:00
|
|
|
}
|
|
|
|
ct.query.blocking = false
|
|
|
|
return ct
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestCacheWithTypes registers ControllableCacheTypes for all types that
|
|
|
|
// proxycfg will watch suitable for testing a proxycfg.State or Manager.
|
|
|
|
func TestCacheWithTypes(t testing.T, types *TestCacheTypes) *cache.Cache {
|
2020-07-28 16:24:30 +00:00
|
|
|
c := cache.New(cache.Options{})
|
2020-04-14 22:29:30 +00:00
|
|
|
c.RegisterType(cachetype.ConnectCARootName, types.roots)
|
|
|
|
c.RegisterType(cachetype.ConnectCALeafName, types.leaf)
|
|
|
|
c.RegisterType(cachetype.IntentionMatchName, types.intentions)
|
|
|
|
c.RegisterType(cachetype.HealthServicesName, types.health)
|
|
|
|
c.RegisterType(cachetype.PreparedQueryName, types.query)
|
|
|
|
c.RegisterType(cachetype.CompiledDiscoveryChainName, types.compiledChain)
|
|
|
|
c.RegisterType(cachetype.ServiceHTTPChecksName, types.serviceHTTPChecks)
|
2019-07-02 03:10:51 +00:00
|
|
|
|
2018-10-03 12:36:38 +00:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-10-09 16:57:26 +00:00
|
|
|
// TestCerts generates a CA and Leaf suitable for returning as mock CA
|
2018-10-03 12:36:38 +00:00
|
|
|
// root/leaf cache requests.
|
|
|
|
func TestCerts(t testing.T) (*structs.IndexedCARoots, *structs.IssuedCert) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
ca := connect.TestCA(t, nil)
|
|
|
|
roots := &structs.IndexedCARoots{
|
|
|
|
ActiveRootID: ca.ID,
|
2019-07-02 14:29:09 +00:00
|
|
|
TrustDomain: fmt.Sprintf("%s.consul", connect.TestClusterID),
|
2018-10-03 12:36:38 +00:00
|
|
|
Roots: []*structs.CARoot{ca},
|
|
|
|
}
|
|
|
|
return roots, TestLeafForCA(t, ca)
|
|
|
|
}
|
|
|
|
|
2018-10-09 16:57:26 +00:00
|
|
|
// TestLeafForCA generates new Leaf suitable for returning as mock CA
|
|
|
|
// leaf cache response, signed by an existing CA.
|
2018-10-03 12:36:38 +00:00
|
|
|
func TestLeafForCA(t testing.T, ca *structs.CARoot) *structs.IssuedCert {
|
|
|
|
leafPEM, pkPEM := connect.TestLeaf(t, "web", ca)
|
|
|
|
|
|
|
|
leafCert, err := connect.ParseCert(leafPEM)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return &structs.IssuedCert{
|
2019-09-23 17:52:35 +00:00
|
|
|
SerialNumber: connect.EncodeSerialNumber(leafCert.SerialNumber),
|
2018-10-03 12:36:38 +00:00
|
|
|
CertPEM: leafPEM,
|
|
|
|
PrivateKeyPEM: pkPEM,
|
|
|
|
Service: "web",
|
|
|
|
ServiceURI: leafCert.URIs[0].String(),
|
|
|
|
ValidAfter: leafCert.NotBefore,
|
|
|
|
ValidBefore: leafCert.NotAfter,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestIntentions returns a sample intentions match result useful to
|
|
|
|
// mocking service discovery cache results.
|
|
|
|
func TestIntentions(t testing.T) *structs.IndexedIntentionMatches {
|
|
|
|
return &structs.IndexedIntentionMatches{
|
|
|
|
Matches: []structs.Intentions{
|
|
|
|
[]*structs.Intention{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-03 12:36:38 +00:00
|
|
|
ID: "foo",
|
|
|
|
SourceNS: "default",
|
|
|
|
SourceName: "billing",
|
|
|
|
DestinationNS: "default",
|
|
|
|
DestinationName: "web",
|
|
|
|
Action: structs.IntentionActionAllow,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestUpstreamNodes returns a sample service discovery result useful to
|
|
|
|
// mocking service discovery cache results.
|
|
|
|
func TestUpstreamNodes(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test1",
|
|
|
|
Node: "test1",
|
|
|
|
Address: "10.10.1.1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test2",
|
|
|
|
Node: "test2",
|
|
|
|
Address: "10.10.1.2",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:30:35 +00:00
|
|
|
func TestUpstreamNodesInStatus(t testing.T, status string) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test1",
|
|
|
|
Node: "test1",
|
|
|
|
Address: "10.10.1.1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
&structs.HealthCheck{
|
|
|
|
Node: "test1",
|
|
|
|
ServiceName: "web",
|
|
|
|
Name: "force",
|
|
|
|
Status: status,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test2",
|
|
|
|
Node: "test2",
|
|
|
|
Address: "10.10.1.2",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
&structs.HealthCheck{
|
|
|
|
Node: "test2",
|
|
|
|
ServiceName: "web",
|
|
|
|
Name: "force",
|
|
|
|
Status: status,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 19:16:21 +00:00
|
|
|
func TestUpstreamNodesDC2(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test1",
|
|
|
|
Node: "test1",
|
|
|
|
Address: "10.20.1.1",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test2",
|
|
|
|
Node: "test2",
|
|
|
|
Address: "10.20.1.2",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:30:35 +00:00
|
|
|
func TestUpstreamNodesInStatusDC2(t testing.T, status string) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test1",
|
|
|
|
Node: "test1",
|
|
|
|
Address: "10.20.1.1",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
&structs.HealthCheck{
|
|
|
|
Node: "test1",
|
|
|
|
ServiceName: "web",
|
|
|
|
Name: "force",
|
|
|
|
Status: status,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test2",
|
|
|
|
Node: "test2",
|
|
|
|
Address: "10.20.1.2",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
&structs.HealthCheck{
|
|
|
|
Node: "test2",
|
|
|
|
ServiceName: "web",
|
|
|
|
Name: "force",
|
|
|
|
Status: status,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpstreamNodesDC3(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test1",
|
|
|
|
Node: "test1",
|
|
|
|
Address: "10.30.1.1",
|
|
|
|
Datacenter: "dc3",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test2",
|
|
|
|
Node: "test2",
|
|
|
|
Address: "10.30.1.2",
|
|
|
|
Datacenter: "dc3",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 19:16:21 +00:00
|
|
|
func TestUpstreamNodesAlternate(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "alt-test1",
|
|
|
|
Node: "alt-test1",
|
|
|
|
Address: "10.20.1.1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "alt-test2",
|
|
|
|
Node: "alt-test2",
|
|
|
|
Address: "10.20.1.2",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeService(t),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:30:35 +00:00
|
|
|
func TestGatewayNodesDC1(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-1",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.10.1.1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.10.1.1", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.10.1.1", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "198.118.1.1", Port: 443}),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-2",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.10.1.2",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.10.1.2", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.0.1.2", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "198.118.1.2", Port: 443}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 00:52:01 +00:00
|
|
|
func TestGatewayNodesDC2(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-1",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.0.1.1",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.0.1.1", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "198.18.1.1", Port: 443}),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-2",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.0.1.2",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.0.1.2", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.0.1.2", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "198.18.1.2", Port: 443}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:30:35 +00:00
|
|
|
func TestGatewayNodesDC3(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-1",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.1",
|
|
|
|
Datacenter: "dc3",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.1", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "198.38.1.1", Port: 443}),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-2",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.2",
|
|
|
|
Datacenter: "dc3",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.2", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.30.1.2", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "198.38.1.2", Port: 443}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 21:28:45 +00:00
|
|
|
func TestGatewayNodesDC4Hostname(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-1",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.1",
|
|
|
|
Datacenter: "dc4",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.1", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-2",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.2",
|
|
|
|
Datacenter: "dc4",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.2", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.30.1.2", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "456.us-west-2.elb.notaws.com", Port: 443}),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-3",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.3",
|
|
|
|
Datacenter: "dc4",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.3", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.30.1.3", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "198.38.1.1", Port: 443}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGatewayNodesDC5Hostname(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-1",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.1",
|
|
|
|
Datacenter: "dc5",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.1", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-2",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.2",
|
|
|
|
Datacenter: "dc5",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.2", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.30.1.2", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "456.us-west-2.elb.notaws.com", Port: 443}),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-3",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.3",
|
|
|
|
Datacenter: "dc5",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.3", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.30.1.3", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "198.38.1.1", Port: 443}),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-19 19:31:39 +00:00
|
|
|
func TestGatewayNodesDC6Hostname(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-1",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.1",
|
|
|
|
Datacenter: "dc6",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.1", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "123.us-east-1.elb.notaws.com", Port: 443}),
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Status: api.HealthCritical,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:43:35 +00:00
|
|
|
func TestGatewayServiceGroupBarDC1(t testing.T) structs.CheckServiceNodes {
|
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "bar-node-1",
|
|
|
|
Node: "bar-node-1",
|
|
|
|
Address: "10.1.1.4",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "bar-sidecar-proxy",
|
|
|
|
Address: "172.16.1.6",
|
|
|
|
Port: 2222,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"version": "1",
|
|
|
|
},
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceName: "bar",
|
|
|
|
Upstreams: structs.TestUpstreams(t),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "bar-node-2",
|
|
|
|
Node: "bar-node-2",
|
|
|
|
Address: "10.1.1.5",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "bar-sidecar-proxy",
|
|
|
|
Address: "172.16.1.7",
|
|
|
|
Port: 2222,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"version": "1",
|
|
|
|
},
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceName: "bar",
|
|
|
|
Upstreams: structs.TestUpstreams(t),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "bar-node-3",
|
|
|
|
Node: "bar-node-3",
|
|
|
|
Address: "10.1.1.6",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "bar-sidecar-proxy",
|
|
|
|
Address: "172.16.1.8",
|
|
|
|
Port: 2222,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"version": "2",
|
|
|
|
},
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceName: "bar",
|
|
|
|
Upstreams: structs.TestUpstreams(t),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGatewayServiceGroupFooDC1(t testing.T) structs.CheckServiceNodes {
|
2019-06-18 00:52:01 +00:00
|
|
|
return structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "foo-node-1",
|
|
|
|
Node: "foo-node-1",
|
|
|
|
Address: "10.1.1.1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
2019-07-02 13:43:35 +00:00
|
|
|
Service: &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "foo-sidecar-proxy",
|
|
|
|
Address: "172.16.1.3",
|
|
|
|
Port: 2222,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"version": "1",
|
|
|
|
},
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceName: "foo",
|
|
|
|
Upstreams: structs.TestUpstreams(t),
|
|
|
|
},
|
|
|
|
},
|
2019-06-18 00:52:01 +00:00
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "foo-node-2",
|
|
|
|
Node: "foo-node-2",
|
|
|
|
Address: "10.1.1.2",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
2019-07-02 13:43:35 +00:00
|
|
|
Service: &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "foo-sidecar-proxy",
|
|
|
|
Address: "172.16.1.4",
|
|
|
|
Port: 2222,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"version": "1",
|
|
|
|
},
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceName: "foo",
|
|
|
|
Upstreams: structs.TestUpstreams(t),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "foo-node-3",
|
|
|
|
Node: "foo-node-3",
|
|
|
|
Address: "10.1.1.3",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "foo-sidecar-proxy",
|
|
|
|
Address: "172.16.1.5",
|
|
|
|
Port: 2222,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"version": "2",
|
|
|
|
},
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceName: "foo",
|
|
|
|
Upstreams: structs.TestUpstreams(t),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "foo-node-4",
|
|
|
|
Node: "foo-node-4",
|
|
|
|
Address: "10.1.1.7",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "foo-sidecar-proxy",
|
|
|
|
Address: "172.16.1.9",
|
|
|
|
Port: 2222,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"version": "2",
|
|
|
|
},
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceName: "foo",
|
|
|
|
Upstreams: structs.TestUpstreams(t),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
&structs.HealthCheck{
|
|
|
|
Node: "foo-node-4",
|
|
|
|
ServiceName: "foo-sidecar-proxy",
|
|
|
|
Name: "proxy-alive",
|
|
|
|
Status: "warning",
|
|
|
|
},
|
|
|
|
},
|
2019-06-18 00:52:01 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 12:36:38 +00:00
|
|
|
// TestConfigSnapshot returns a fully populated snapshot
|
|
|
|
func TestConfigSnapshot(t testing.T) *ConfigSnapshot {
|
|
|
|
roots, leaf := TestCerts(t)
|
2019-08-22 20:11:56 +00:00
|
|
|
|
|
|
|
// no entries implies we'll get a default chain
|
|
|
|
dbChain := discoverychain.TestCompileConfigEntries(
|
|
|
|
t, "db", "default", "dc1",
|
|
|
|
connect.TestClusterID+".consul", "dc1", nil)
|
|
|
|
|
2018-10-03 12:36:38 +00:00
|
|
|
return &ConfigSnapshot{
|
2019-06-27 14:31:19 +00:00
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
2019-06-18 00:52:01 +00:00
|
|
|
Service: "web-sidecar-proxy",
|
2020-01-24 15:04:58 +00:00
|
|
|
ProxyID: structs.NewServiceID("web-sidecar-proxy", nil),
|
2018-10-03 12:36:38 +00:00
|
|
|
Address: "0.0.0.0",
|
|
|
|
Port: 9999,
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceID: "web",
|
|
|
|
DestinationServiceName: "web",
|
|
|
|
LocalServiceAddress: "127.0.0.1",
|
|
|
|
LocalServicePort: 8080,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
Upstreams: structs.TestUpstreams(t),
|
|
|
|
},
|
|
|
|
Roots: roots,
|
2019-06-18 00:52:01 +00:00
|
|
|
ConnectProxy: configSnapshotConnectProxy{
|
2020-04-16 21:00:48 +00:00
|
|
|
ConfigSnapshotUpstreams: ConfigSnapshotUpstreams{
|
|
|
|
Leaf: leaf,
|
|
|
|
DiscoveryChain: map[string]*structs.CompiledDiscoveryChain{
|
|
|
|
"db": dbChain,
|
|
|
|
},
|
|
|
|
WatchedUpstreamEndpoints: map[string]map[string]structs.CheckServiceNodes{
|
2020-06-16 17:19:31 +00:00
|
|
|
"db": {
|
2020-04-16 21:00:48 +00:00
|
|
|
"db.default.dc1": TestUpstreamNodes(t),
|
|
|
|
},
|
|
|
|
},
|
2019-08-22 20:11:56 +00:00
|
|
|
},
|
2020-01-24 15:04:58 +00:00
|
|
|
PreparedQueryEndpoints: map[string]structs.CheckServiceNodes{
|
2019-07-29 15:15:55 +00:00
|
|
|
"prepared_query:geo-cache": TestUpstreamNodes(t),
|
2019-06-18 00:52:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 19:16:21 +00:00
|
|
|
// TestConfigSnapshotDiscoveryChain returns a fully populated snapshot using a discovery chain
|
|
|
|
func TestConfigSnapshotDiscoveryChain(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "simple")
|
|
|
|
}
|
|
|
|
|
2019-08-19 17:19:44 +00:00
|
|
|
func TestConfigSnapshotDiscoveryChainExternalSNI(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "external-sni")
|
|
|
|
}
|
|
|
|
|
2019-08-02 03:03:34 +00:00
|
|
|
func TestConfigSnapshotDiscoveryChainWithOverrides(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "simple-with-overrides")
|
|
|
|
}
|
|
|
|
|
2019-07-12 19:16:21 +00:00
|
|
|
func TestConfigSnapshotDiscoveryChainWithFailover(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "failover")
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:30:35 +00:00
|
|
|
func TestConfigSnapshotDiscoveryChainWithFailoverThroughRemoteGateway(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "failover-through-remote-gateway")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithFailoverThroughRemoteGatewayTriggered(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "failover-through-remote-gateway-triggered")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithDoubleFailoverThroughRemoteGateway(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "failover-through-double-remote-gateway")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithDoubleFailoverThroughRemoteGatewayTriggered(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "failover-through-double-remote-gateway-triggered")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithFailoverThroughLocalGateway(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "failover-through-local-gateway")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithFailoverThroughLocalGatewayTriggered(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "failover-through-local-gateway-triggered")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithDoubleFailoverThroughLocalGateway(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "failover-through-double-local-gateway")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithDoubleFailoverThroughLocalGatewayTriggered(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "failover-through-double-local-gateway-triggered")
|
|
|
|
}
|
|
|
|
|
2019-07-12 19:16:21 +00:00
|
|
|
func TestConfigSnapshotDiscoveryChain_SplitterWithResolverRedirectMultiDC(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "splitter-with-resolver-redirect-multidc")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithEntries(t testing.T, additionalEntries ...structs.ConfigEntry) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "simple", additionalEntries...)
|
|
|
|
}
|
|
|
|
|
2019-08-22 20:11:56 +00:00
|
|
|
func TestConfigSnapshotDiscoveryChainDefault(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "default")
|
|
|
|
}
|
|
|
|
|
2020-04-14 21:30:00 +00:00
|
|
|
func TestConfigSnapshotDiscoveryChainWithSplitter(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "chain-and-splitter")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithGRPCRouter(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "grpc-router")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotDiscoveryChainWithRouter(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotDiscoveryChain(t, "chain-and-router")
|
|
|
|
}
|
|
|
|
|
2019-07-12 19:16:21 +00:00
|
|
|
func testConfigSnapshotDiscoveryChain(t testing.T, variation string, additionalEntries ...structs.ConfigEntry) *ConfigSnapshot {
|
|
|
|
roots, leaf := TestCerts(t)
|
|
|
|
|
2020-04-13 21:47:53 +00:00
|
|
|
snap := &ConfigSnapshot{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "web-sidecar-proxy",
|
|
|
|
ProxyID: structs.NewServiceID("web-sidecar-proxy", nil),
|
|
|
|
Address: "0.0.0.0",
|
|
|
|
Port: 9999,
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceID: "web",
|
|
|
|
DestinationServiceName: "web",
|
|
|
|
LocalServiceAddress: "127.0.0.1",
|
|
|
|
LocalServicePort: 8080,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
Upstreams: structs.TestUpstreams(t),
|
|
|
|
},
|
|
|
|
Roots: roots,
|
|
|
|
ConnectProxy: configSnapshotConnectProxy{
|
|
|
|
ConfigSnapshotUpstreams: setupTestVariationConfigEntriesAndSnapshot(
|
|
|
|
t, variation, leaf, additionalEntries...,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
|
|
|
|
return snap
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupTestVariationConfigEntriesAndSnapshot(
|
|
|
|
t testing.T,
|
|
|
|
variation string,
|
|
|
|
leaf *structs.IssuedCert,
|
|
|
|
additionalEntries ...structs.ConfigEntry,
|
|
|
|
) ConfigSnapshotUpstreams {
|
2019-07-12 19:16:21 +00:00
|
|
|
// Compile a chain.
|
2019-08-02 03:03:34 +00:00
|
|
|
var (
|
|
|
|
entries []structs.ConfigEntry
|
|
|
|
compileSetup func(req *discoverychain.CompileRequest)
|
|
|
|
)
|
2020-04-13 21:47:53 +00:00
|
|
|
|
2019-07-12 19:16:21 +00:00
|
|
|
switch variation {
|
2019-08-22 20:11:56 +00:00
|
|
|
case "default":
|
|
|
|
// no config entries
|
2019-08-02 03:03:34 +00:00
|
|
|
case "simple-with-overrides":
|
|
|
|
compileSetup = func(req *discoverychain.CompileRequest) {
|
|
|
|
req.OverrideMeshGateway.Mode = structs.MeshGatewayModeLocal
|
|
|
|
req.OverrideProtocol = "grpc"
|
|
|
|
req.OverrideConnectTimeout = 66 * time.Second
|
|
|
|
}
|
|
|
|
fallthrough
|
2019-07-12 19:16:21 +00:00
|
|
|
case "simple":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
)
|
2019-08-19 17:19:44 +00:00
|
|
|
case "external-sni":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
ExternalSNI: "db.some.other.service.mesh",
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
)
|
2019-07-12 19:16:21 +00:00
|
|
|
case "failover":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Service: "fail",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2019-08-05 18:30:35 +00:00
|
|
|
case "failover-through-remote-gateway-triggered":
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-remote-gateway":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
MeshGateway: structs.MeshGatewayConfig{
|
|
|
|
Mode: structs.MeshGatewayModeRemote,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "failover-through-double-remote-gateway-triggered":
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-double-remote-gateway":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
MeshGateway: structs.MeshGatewayConfig{
|
|
|
|
Mode: structs.MeshGatewayModeRemote,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc2", "dc3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "failover-through-local-gateway-triggered":
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-local-gateway":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
MeshGateway: structs.MeshGatewayConfig{
|
|
|
|
Mode: structs.MeshGatewayModeLocal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "failover-through-double-local-gateway-triggered":
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-double-local-gateway":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
MeshGateway: structs.MeshGatewayConfig{
|
|
|
|
Mode: structs.MeshGatewayModeLocal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc2", "dc3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2019-07-12 19:16:21 +00:00
|
|
|
case "splitter-with-resolver-redirect-multidc":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 50, Service: "db-dc1"},
|
|
|
|
{Weight: 50, Service: "db-dc2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db-dc1",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "db",
|
|
|
|
ServiceSubset: "v1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db-dc2",
|
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "db",
|
|
|
|
ServiceSubset: "v2",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2019-07-12 19:16:21 +00:00
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2019-07-12 19:16:21 +00:00
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2020-04-14 21:30:00 +00:00
|
|
|
case "chain-and-splitter":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "db",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 95.5, Service: "big-side"},
|
|
|
|
{Weight: 4, Service: "goldilocks-side"},
|
|
|
|
{Weight: 0.5, Service: "lil-bit-side"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "grpc-router":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "grpc",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "db",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/fgrpc.PingServer/Ping",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "prefix",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "chain-and-router":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
ConnectTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
&structs.ProxyConfigEntry{
|
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "split-3-ways",
|
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 95.5, Service: "big-side"},
|
|
|
|
{Weight: 4, Service: "goldilocks-side"},
|
|
|
|
{Weight: 0.5, Service: "lil-bit-side"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "db",
|
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/prefix",
|
|
|
|
}),
|
|
|
|
Destination: toService("prefix"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/exact",
|
|
|
|
}),
|
|
|
|
Destination: toService("exact"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathRegex: "/regex",
|
|
|
|
}),
|
|
|
|
Destination: toService("regex"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Present: true,
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-present"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Present: true,
|
|
|
|
Invert: true,
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-not-present"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Exact: "exact",
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-exact"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Prefix: "prefix",
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-prefix"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Suffix: "suffix",
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-suffix"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Regex: "regex",
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-regex"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
Methods: []string{"GET", "PUT"},
|
|
|
|
}),
|
|
|
|
Destination: toService("just-methods"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
Header: []structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
{
|
|
|
|
Name: "x-debug",
|
|
|
|
Exact: "exact",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Methods: []string{"GET", "PUT"},
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-exact-with-method"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchParam(structs.ServiceRouteHTTPMatchQueryParam{
|
|
|
|
Name: "secretparam1",
|
|
|
|
Exact: "exact",
|
|
|
|
}),
|
|
|
|
Destination: toService("prm-exact"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchParam(structs.ServiceRouteHTTPMatchQueryParam{
|
|
|
|
Name: "secretparam2",
|
|
|
|
Regex: "regex",
|
|
|
|
}),
|
|
|
|
Destination: toService("prm-regex"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchParam(structs.ServiceRouteHTTPMatchQueryParam{
|
|
|
|
Name: "secretparam3",
|
|
|
|
Present: true,
|
|
|
|
}),
|
|
|
|
Destination: toService("prm-present"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: nil,
|
|
|
|
Destination: toService("nil-match"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{},
|
|
|
|
Destination: toService("empty-match-1"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{},
|
|
|
|
},
|
|
|
|
Destination: toService("empty-match-2"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/prefix",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "prefix-rewrite-1",
|
|
|
|
PrefixRewrite: "/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/prefix",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "prefix-rewrite-2",
|
|
|
|
PrefixRewrite: "/nested/newlocation",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/timeout",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "req-timeout",
|
|
|
|
RequestTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/retry-connect",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "retry-connect",
|
|
|
|
NumRetries: 15,
|
|
|
|
RetryOnConnectFailure: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/retry-codes",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "retry-codes",
|
|
|
|
NumRetries: 15,
|
|
|
|
RetryOnStatusCodes: []uint32{401, 409, 451},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/retry-both",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "retry-both",
|
|
|
|
RetryOnConnectFailure: true,
|
|
|
|
RetryOnStatusCodes: []uint32{401, 409, 451},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/split-3-ways",
|
|
|
|
}),
|
|
|
|
Destination: toService("split-3-ways"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2020-04-16 23:24:11 +00:00
|
|
|
case "http-multiple-services":
|
2019-07-12 19:16:21 +00:00
|
|
|
default:
|
|
|
|
t.Fatalf("unexpected variation: %q", variation)
|
2020-04-13 21:47:53 +00:00
|
|
|
return ConfigSnapshotUpstreams{}
|
2019-07-12 19:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(additionalEntries) > 0 {
|
|
|
|
entries = append(entries, additionalEntries...)
|
|
|
|
}
|
|
|
|
|
2019-08-19 18:03:03 +00:00
|
|
|
dbChain := discoverychain.TestCompileConfigEntries(t, "db", "default", "dc1", connect.TestClusterID+".consul", "dc1", compileSetup, entries...)
|
2019-07-12 19:16:21 +00:00
|
|
|
|
2020-04-13 21:47:53 +00:00
|
|
|
snap := ConfigSnapshotUpstreams{
|
|
|
|
Leaf: leaf,
|
|
|
|
DiscoveryChain: map[string]*structs.CompiledDiscoveryChain{
|
|
|
|
"db": dbChain,
|
2019-07-12 19:16:21 +00:00
|
|
|
},
|
2020-04-13 21:47:53 +00:00
|
|
|
WatchedUpstreamEndpoints: map[string]map[string]structs.CheckServiceNodes{
|
2020-06-16 17:19:31 +00:00
|
|
|
"db": {
|
2020-04-13 21:47:53 +00:00
|
|
|
"db.default.dc1": TestUpstreamNodes(t),
|
2019-07-12 19:16:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
switch variation {
|
2019-08-22 20:11:56 +00:00
|
|
|
case "default":
|
2019-08-02 03:03:34 +00:00
|
|
|
case "simple-with-overrides":
|
2019-07-12 19:16:21 +00:00
|
|
|
case "simple":
|
2019-08-19 17:19:44 +00:00
|
|
|
case "external-sni":
|
2019-07-12 19:16:21 +00:00
|
|
|
case "failover":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["fail.default.dc1"] =
|
2019-07-12 19:16:21 +00:00
|
|
|
TestUpstreamNodesAlternate(t)
|
2019-08-05 18:30:35 +00:00
|
|
|
case "failover-through-remote-gateway-triggered":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc1"] =
|
2019-08-05 18:30:35 +00:00
|
|
|
TestUpstreamNodesInStatus(t, "critical")
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-remote-gateway":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc2"] =
|
2019-08-05 18:30:35 +00:00
|
|
|
TestUpstreamNodesDC2(t)
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
2020-06-16 17:19:31 +00:00
|
|
|
"db": {
|
2019-08-05 18:30:35 +00:00
|
|
|
"dc2": TestGatewayNodesDC2(t),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case "failover-through-double-remote-gateway-triggered":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc1"] =
|
2019-08-05 18:30:35 +00:00
|
|
|
TestUpstreamNodesInStatus(t, "critical")
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc2"] =
|
2019-08-05 18:30:35 +00:00
|
|
|
TestUpstreamNodesInStatusDC2(t, "critical")
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-double-remote-gateway":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc3"] = TestUpstreamNodesDC2(t)
|
|
|
|
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
2020-06-16 17:19:31 +00:00
|
|
|
"db": {
|
2019-08-05 18:30:35 +00:00
|
|
|
"dc2": TestGatewayNodesDC2(t),
|
|
|
|
"dc3": TestGatewayNodesDC3(t),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case "failover-through-local-gateway-triggered":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc1"] =
|
2019-08-05 18:30:35 +00:00
|
|
|
TestUpstreamNodesInStatus(t, "critical")
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-local-gateway":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc2"] =
|
2019-08-05 18:30:35 +00:00
|
|
|
TestUpstreamNodesDC2(t)
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
2020-06-16 17:19:31 +00:00
|
|
|
"db": {
|
2019-08-05 18:30:35 +00:00
|
|
|
"dc1": TestGatewayNodesDC1(t),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case "failover-through-double-local-gateway-triggered":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc1"] =
|
2019-08-05 18:30:35 +00:00
|
|
|
TestUpstreamNodesInStatus(t, "critical")
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc2"] =
|
2019-08-05 18:30:35 +00:00
|
|
|
TestUpstreamNodesInStatusDC2(t, "critical")
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-double-local-gateway":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"]["db.default.dc3"] = TestUpstreamNodesDC2(t)
|
|
|
|
snap.WatchedGatewayEndpoints = map[string]map[string]structs.CheckServiceNodes{
|
2020-06-16 17:19:31 +00:00
|
|
|
"db": {
|
2019-08-05 18:30:35 +00:00
|
|
|
"dc1": TestGatewayNodesDC1(t),
|
|
|
|
},
|
|
|
|
}
|
2019-07-12 19:16:21 +00:00
|
|
|
case "splitter-with-resolver-redirect-multidc":
|
2020-04-13 21:47:53 +00:00
|
|
|
snap.WatchedUpstreamEndpoints["db"] = map[string]structs.CheckServiceNodes{
|
2019-08-02 20:34:54 +00:00
|
|
|
"v1.db.default.dc1": TestUpstreamNodes(t),
|
|
|
|
"v2.db.default.dc2": TestUpstreamNodesDC2(t),
|
2019-07-12 19:16:21 +00:00
|
|
|
}
|
2020-04-14 21:30:00 +00:00
|
|
|
case "chain-and-splitter":
|
|
|
|
case "grpc-router":
|
|
|
|
case "chain-and-router":
|
2020-04-16 23:24:11 +00:00
|
|
|
case "http-multiple-services":
|
|
|
|
snap.WatchedUpstreamEndpoints["foo"] = map[string]structs.CheckServiceNodes{
|
|
|
|
"foo.default.dc1": TestUpstreamNodes(t),
|
|
|
|
}
|
|
|
|
snap.WatchedUpstreamEndpoints["bar"] = map[string]structs.CheckServiceNodes{
|
|
|
|
"bar.default.dc1": TestUpstreamNodesAlternate(t),
|
|
|
|
}
|
2019-07-12 19:16:21 +00:00
|
|
|
default:
|
|
|
|
t.Fatalf("unexpected variation: %q", variation)
|
2020-04-13 21:47:53 +00:00
|
|
|
return ConfigSnapshotUpstreams{}
|
2019-07-12 19:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return snap
|
|
|
|
}
|
|
|
|
|
2019-06-18 00:52:01 +00:00
|
|
|
func TestConfigSnapshotMeshGateway(t testing.T) *ConfigSnapshot {
|
2020-03-09 20:59:02 +00:00
|
|
|
return testConfigSnapshotMeshGateway(t, true, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotMeshGatewayUsingFederationStates(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotMeshGateway(t, true, true)
|
2019-10-17 21:46:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotMeshGatewayNoServices(t testing.T) *ConfigSnapshot {
|
2020-03-09 20:59:02 +00:00
|
|
|
return testConfigSnapshotMeshGateway(t, false, false)
|
2019-10-17 21:46:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 20:59:02 +00:00
|
|
|
func testConfigSnapshotMeshGateway(t testing.T, populateServices bool, useFederationStates bool) *ConfigSnapshot {
|
2019-06-18 00:52:01 +00:00
|
|
|
roots, _ := TestCerts(t)
|
2019-10-17 21:46:49 +00:00
|
|
|
snap := &ConfigSnapshot{
|
2019-06-18 00:52:01 +00:00
|
|
|
Kind: structs.ServiceKindMeshGateway,
|
|
|
|
Service: "mesh-gateway",
|
2020-01-24 15:04:58 +00:00
|
|
|
ProxyID: structs.NewServiceID("mesh-gateway", nil),
|
2019-06-18 00:52:01 +00:00
|
|
|
Address: "1.2.3.4",
|
|
|
|
Port: 8443,
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
Config: map[string]interface{}{},
|
|
|
|
},
|
|
|
|
TaggedAddresses: map[string]structs.ServiceAddress{
|
2020-06-16 17:19:31 +00:00
|
|
|
structs.TaggedAddressLAN: {
|
2019-06-18 00:52:01 +00:00
|
|
|
Address: "1.2.3.4",
|
|
|
|
Port: 8443,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
structs.TaggedAddressWAN: {
|
2019-06-18 00:52:01 +00:00
|
|
|
Address: "198.18.0.1",
|
|
|
|
Port: 443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Roots: roots,
|
|
|
|
Datacenter: "dc1",
|
|
|
|
MeshGateway: configSnapshotMeshGateway{
|
2019-10-17 21:46:49 +00:00
|
|
|
WatchedServicesSet: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if populateServices {
|
|
|
|
snap.MeshGateway = configSnapshotMeshGateway{
|
2020-06-12 14:57:41 +00:00
|
|
|
WatchedServices: map[structs.ServiceName]context.CancelFunc{
|
|
|
|
structs.NewServiceName("foo", nil): nil,
|
|
|
|
structs.NewServiceName("bar", nil): nil,
|
2019-06-18 00:52:01 +00:00
|
|
|
},
|
2019-10-17 21:46:49 +00:00
|
|
|
WatchedServicesSet: true,
|
2019-06-18 00:52:01 +00:00
|
|
|
WatchedDatacenters: map[string]context.CancelFunc{
|
|
|
|
"dc2": nil,
|
|
|
|
},
|
2020-06-12 14:57:41 +00:00
|
|
|
ServiceGroups: map[structs.ServiceName]structs.CheckServiceNodes{
|
|
|
|
structs.NewServiceName("foo", nil): TestGatewayServiceGroupFooDC1(t),
|
|
|
|
structs.NewServiceName("bar", nil): TestGatewayServiceGroupBarDC1(t),
|
2019-06-18 00:52:01 +00:00
|
|
|
},
|
|
|
|
GatewayGroups: map[string]structs.CheckServiceNodes{
|
|
|
|
"dc2": TestGatewayNodesDC2(t),
|
2020-06-03 21:28:45 +00:00
|
|
|
"dc4": TestGatewayNodesDC4Hostname(t),
|
2020-06-19 19:31:39 +00:00
|
|
|
"dc6": TestGatewayNodesDC6Hostname(t),
|
2020-06-03 21:28:45 +00:00
|
|
|
},
|
|
|
|
HostnameDatacenters: map[string]structs.CheckServiceNodes{
|
|
|
|
"dc4": {
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-1",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.1",
|
|
|
|
Datacenter: "dc4",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.1", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-2",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.2",
|
|
|
|
Datacenter: "dc4",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.2", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.30.1.2", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "456.us-west-2.elb.notaws.com", Port: 443}),
|
|
|
|
},
|
|
|
|
},
|
2020-06-19 19:31:39 +00:00
|
|
|
"dc6": {
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "mesh-gateway-1",
|
|
|
|
Node: "mesh-gateway",
|
|
|
|
Address: "10.30.1.1",
|
|
|
|
Datacenter: "dc6",
|
|
|
|
},
|
|
|
|
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
|
|
|
|
"10.30.1.1", 8443,
|
|
|
|
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
|
|
|
|
structs.ServiceAddress{Address: "123.us-east-1.elb.notaws.com", Port: 443}),
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Status: api.HealthCritical,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-18 00:52:01 +00:00
|
|
|
},
|
2019-10-17 21:46:49 +00:00
|
|
|
}
|
2020-03-09 20:59:02 +00:00
|
|
|
if useFederationStates {
|
|
|
|
snap.MeshGateway.FedStateGateways = map[string]structs.CheckServiceNodes{
|
|
|
|
"dc2": TestGatewayNodesDC2(t),
|
2020-06-03 21:28:45 +00:00
|
|
|
"dc4": TestGatewayNodesDC4Hostname(t),
|
2020-06-19 19:31:39 +00:00
|
|
|
"dc6": TestGatewayNodesDC6Hostname(t),
|
2020-03-09 20:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete(snap.MeshGateway.GatewayGroups, "dc2")
|
|
|
|
}
|
2018-10-03 12:36:38 +00:00
|
|
|
}
|
2019-10-17 21:46:49 +00:00
|
|
|
|
|
|
|
return snap
|
2018-10-03 12:36:38 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 21:30:00 +00:00
|
|
|
func TestConfigSnapshotIngress(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "simple")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 23:36:20 +00:00
|
|
|
func TestConfigSnapshotIngressWithTLSListener(t testing.T) *ConfigSnapshot {
|
|
|
|
snap := testConfigSnapshotIngressGateway(t, true, "tcp", "default")
|
|
|
|
snap.IngressGateway.TLSEnabled = true
|
|
|
|
return snap
|
|
|
|
}
|
|
|
|
|
2020-04-14 21:30:00 +00:00
|
|
|
func TestConfigSnapshotIngressWithOverrides(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "simple-with-overrides")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
func TestConfigSnapshotIngress_SplitterWithResolverRedirectMultiDC(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "http", "splitter-with-resolver-redirect-multidc")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngress_HTTPMultipleServices(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotIngressGateway(t, true, "http", "http-multiple-services")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressExternalSNI(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "external-sni")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithFailover(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "failover")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithFailoverThroughRemoteGateway(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "failover-through-remote-gateway")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithFailoverThroughRemoteGatewayTriggered(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "failover-through-remote-gateway-triggered")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithDoubleFailoverThroughRemoteGateway(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "failover-through-double-remote-gateway")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithDoubleFailoverThroughRemoteGatewayTriggered(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "failover-through-double-remote-gateway-triggered")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithFailoverThroughLocalGateway(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "failover-through-local-gateway")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithFailoverThroughLocalGatewayTriggered(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "failover-through-local-gateway-triggered")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithDoubleFailoverThroughLocalGateway(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "failover-through-double-local-gateway")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithDoubleFailoverThroughLocalGatewayTriggered(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "failover-through-double-local-gateway-triggered")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithSplitter(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "http", "chain-and-splitter")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithGRPCRouter(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "http", "grpc-router")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressWithRouter(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "http", "chain-and-router")
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:00:48 +00:00
|
|
|
func TestConfigSnapshotIngressGateway(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "tcp", "default")
|
2020-04-16 21:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotIngressGatewayNoServices(t testing.T) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, false, "tcp", "default")
|
2020-04-16 21:00:48 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 21:30:00 +00:00
|
|
|
func TestConfigSnapshotIngressDiscoveryChainWithEntries(t testing.T, additionalEntries ...structs.ConfigEntry) *ConfigSnapshot {
|
2020-04-16 23:24:11 +00:00
|
|
|
return testConfigSnapshotIngressGateway(t, true, "http", "simple", additionalEntries...)
|
2020-04-14 21:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testConfigSnapshotIngressGateway(
|
2020-04-16 23:24:11 +00:00
|
|
|
t testing.T, populateServices bool, protocol, variation string,
|
2020-04-14 21:30:00 +00:00
|
|
|
additionalEntries ...structs.ConfigEntry,
|
|
|
|
) *ConfigSnapshot {
|
2020-04-16 21:00:48 +00:00
|
|
|
roots, leaf := TestCerts(t)
|
|
|
|
snap := &ConfigSnapshot{
|
|
|
|
Kind: structs.ServiceKindIngressGateway,
|
|
|
|
Service: "ingress-gateway",
|
|
|
|
ProxyID: structs.NewServiceID("ingress-gateway", nil),
|
|
|
|
Address: "1.2.3.4",
|
|
|
|
Roots: roots,
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
if populateServices {
|
|
|
|
snap.IngressGateway = configSnapshotIngressGateway{
|
2020-04-13 21:47:53 +00:00
|
|
|
ConfigSnapshotUpstreams: setupTestVariationConfigEntriesAndSnapshot(
|
2020-04-14 21:30:00 +00:00
|
|
|
t, variation, leaf, additionalEntries...,
|
2020-04-13 21:47:53 +00:00
|
|
|
),
|
2020-04-16 23:24:11 +00:00
|
|
|
Upstreams: map[IngressListenerKey]structs.Upstreams{
|
2020-06-16 17:19:31 +00:00
|
|
|
{protocol, 9191}: {
|
2020-04-16 23:24:11 +00:00
|
|
|
{
|
|
|
|
// We rely on this one having default type in a few tests...
|
|
|
|
DestinationName: "db",
|
|
|
|
LocalBindPort: 9191,
|
|
|
|
LocalBindAddress: "2.3.4.5",
|
|
|
|
},
|
2020-04-16 21:00:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return snap
|
|
|
|
}
|
|
|
|
|
2019-09-26 02:55:52 +00:00
|
|
|
func TestConfigSnapshotExposeConfig(t testing.T) *ConfigSnapshot {
|
|
|
|
return &ConfigSnapshot{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "web-proxy",
|
2020-01-24 15:04:58 +00:00
|
|
|
ProxyID: structs.NewServiceID("web-proxy", nil),
|
2019-09-26 02:55:52 +00:00
|
|
|
Address: "1.2.3.4",
|
|
|
|
Port: 8080,
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
2020-02-03 14:26:47 +00:00
|
|
|
DestinationServiceName: "web",
|
|
|
|
DestinationServiceID: "web",
|
|
|
|
LocalServicePort: 8080,
|
2019-09-26 02:55:52 +00:00
|
|
|
Expose: structs.ExposeConfig{
|
|
|
|
Checks: false,
|
|
|
|
Paths: []structs.ExposePath{
|
|
|
|
{
|
|
|
|
LocalPathPort: 8080,
|
|
|
|
Path: "/health1",
|
|
|
|
ListenerPort: 21500,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
LocalPathPort: 8080,
|
|
|
|
Path: "/health2",
|
|
|
|
ListenerPort: 21501,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 16:33:01 +00:00
|
|
|
func TestConfigSnapshotTerminatingGateway(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotTerminatingGateway(t, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotTerminatingGatewayNoServices(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotTerminatingGateway(t, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testConfigSnapshotTerminatingGateway(t testing.T, populateServices bool) *ConfigSnapshot {
|
|
|
|
roots, _ := TestCerts(t)
|
|
|
|
|
|
|
|
snap := &ConfigSnapshot{
|
|
|
|
Kind: structs.ServiceKindTerminatingGateway,
|
|
|
|
Service: "terminating-gateway",
|
|
|
|
ProxyID: structs.NewServiceID("terminating-gateway", nil),
|
|
|
|
Address: "1.2.3.4",
|
|
|
|
TaggedAddresses: map[string]structs.ServiceAddress{
|
2020-06-16 17:19:31 +00:00
|
|
|
structs.TaggedAddressWAN: {
|
2020-04-13 16:33:01 +00:00
|
|
|
Address: "198.18.0.1",
|
|
|
|
Port: 443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Port: 8443,
|
|
|
|
Roots: roots,
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
if populateServices {
|
2020-06-12 14:57:41 +00:00
|
|
|
web := structs.NewServiceName("web", nil)
|
2020-04-13 16:33:01 +00:00
|
|
|
webNodes := TestUpstreamNodes(t)
|
2020-04-14 14:59:23 +00:00
|
|
|
webNodes[0].Service.Meta = map[string]string{
|
|
|
|
"version": "1",
|
|
|
|
}
|
|
|
|
webNodes[1].Service.Meta = map[string]string{
|
|
|
|
"version": "2",
|
|
|
|
}
|
2020-04-13 16:33:01 +00:00
|
|
|
|
2020-06-12 14:57:41 +00:00
|
|
|
api := structs.NewServiceName("api", nil)
|
2020-06-03 21:28:45 +00:00
|
|
|
apiNodes := structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "api",
|
|
|
|
Node: "test1",
|
|
|
|
Address: "10.10.1.1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "api",
|
|
|
|
Address: "api.mydomain",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Status: "critical",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test2",
|
|
|
|
Node: "test2",
|
|
|
|
Address: "10.10.1.2",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "api",
|
|
|
|
Address: "api.altdomain",
|
|
|
|
Port: 8081,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"domain": "alt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test3",
|
|
|
|
Node: "test3",
|
|
|
|
Address: "10.10.1.3",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "api",
|
|
|
|
Address: "10.10.1.3",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
},
|
2020-06-19 19:31:39 +00:00
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test4",
|
|
|
|
Node: "test4",
|
|
|
|
Address: "10.10.1.4",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "api",
|
|
|
|
Address: "api.thirddomain",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has failing instance
|
|
|
|
db := structs.NewServiceName("db", nil)
|
|
|
|
dbNodes := structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "db",
|
|
|
|
Node: "test4",
|
|
|
|
Address: "10.10.1.4",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "db",
|
|
|
|
Address: "db.mydomain",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Status: "critical",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has passing instance but failing subset
|
|
|
|
cache := structs.NewServiceName("cache", nil)
|
|
|
|
cacheNodes := structs.CheckServiceNodes{
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "cache",
|
|
|
|
Node: "test5",
|
|
|
|
Address: "10.10.1.5",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "cache",
|
|
|
|
Address: "cache.mydomain",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "cache",
|
|
|
|
Node: "test5",
|
|
|
|
Address: "10.10.1.5",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "cache",
|
|
|
|
Address: "cache.mydomain",
|
|
|
|
Port: 8081,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"Env": "prod",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{
|
|
|
|
Status: "critical",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-04-13 16:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
snap.TerminatingGateway = configSnapshotTerminatingGateway{
|
2020-06-12 14:57:41 +00:00
|
|
|
ServiceGroups: map[structs.ServiceName]structs.CheckServiceNodes{
|
2020-06-19 19:31:39 +00:00
|
|
|
web: webNodes,
|
|
|
|
api: apiNodes,
|
|
|
|
db: dbNodes,
|
|
|
|
cache: cacheNodes,
|
2020-04-13 16:33:01 +00:00
|
|
|
},
|
2020-06-12 14:57:41 +00:00
|
|
|
GatewayServices: map[structs.ServiceName]structs.GatewayService{
|
2020-04-27 22:25:37 +00:00
|
|
|
web: {
|
|
|
|
Service: web,
|
|
|
|
CAFile: "ca.cert.pem",
|
|
|
|
},
|
|
|
|
api: {
|
|
|
|
Service: api,
|
|
|
|
CAFile: "ca.cert.pem",
|
|
|
|
CertFile: "api.cert.pem",
|
|
|
|
KeyFile: "api.key.pem",
|
|
|
|
},
|
2020-06-19 19:31:39 +00:00
|
|
|
db: {
|
|
|
|
Service: db,
|
|
|
|
},
|
|
|
|
cache: {
|
|
|
|
Service: cache,
|
|
|
|
},
|
2020-04-27 22:25:37 +00:00
|
|
|
},
|
2020-06-12 14:57:41 +00:00
|
|
|
HostnameServices: map[structs.ServiceName]structs.CheckServiceNodes{
|
2020-06-19 19:31:39 +00:00
|
|
|
api: {apiNodes[0], apiNodes[1]},
|
|
|
|
db: {dbNodes[0]},
|
|
|
|
cache: {cacheNodes[0], cacheNodes[1]},
|
2020-06-03 21:28:45 +00:00
|
|
|
},
|
2020-04-14 23:46:40 +00:00
|
|
|
}
|
2020-06-12 14:57:41 +00:00
|
|
|
snap.TerminatingGateway.ServiceLeaves = map[structs.ServiceName]*structs.IssuedCert{
|
|
|
|
structs.NewServiceName("web", nil): {
|
2020-04-14 23:46:40 +00:00
|
|
|
CertPEM: golden(t, "test-leaf-cert"),
|
|
|
|
PrivateKeyPEM: golden(t, "test-leaf-key"),
|
|
|
|
},
|
2020-06-12 14:57:41 +00:00
|
|
|
structs.NewServiceName("api", nil): {
|
2020-04-14 23:46:40 +00:00
|
|
|
CertPEM: golden(t, "alt-test-leaf-cert"),
|
|
|
|
PrivateKeyPEM: golden(t, "alt-test-leaf-key"),
|
2020-04-13 16:33:01 +00:00
|
|
|
},
|
2020-06-19 19:31:39 +00:00
|
|
|
structs.NewServiceName("db", nil): {
|
|
|
|
CertPEM: golden(t, "db-test-leaf-cert"),
|
|
|
|
PrivateKeyPEM: golden(t, "db-test-leaf-key"),
|
|
|
|
},
|
|
|
|
structs.NewServiceName("cache", nil): {
|
|
|
|
CertPEM: golden(t, "cache-test-leaf-cert"),
|
|
|
|
PrivateKeyPEM: golden(t, "cache-test-leaf-key"),
|
|
|
|
},
|
2020-04-13 16:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return snap
|
|
|
|
}
|
|
|
|
|
2020-04-02 07:35:04 +00:00
|
|
|
func TestConfigSnapshotGRPCExposeHTTP1(t testing.T) *ConfigSnapshot {
|
|
|
|
return &ConfigSnapshot{
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Service: "grpc-proxy",
|
|
|
|
ProxyID: structs.NewServiceID("grpc-proxy", nil),
|
|
|
|
Address: "1.2.3.4",
|
|
|
|
Port: 8080,
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceName: "grpc",
|
|
|
|
DestinationServiceID: "grpc",
|
|
|
|
LocalServicePort: 8080,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "grpc",
|
|
|
|
},
|
|
|
|
Expose: structs.ExposeConfig{
|
|
|
|
Checks: false,
|
|
|
|
Paths: []structs.ExposePath{
|
|
|
|
{
|
|
|
|
LocalPathPort: 8090,
|
|
|
|
Path: "/healthz",
|
|
|
|
ListenerPort: 21500,
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:06:23 +00:00
|
|
|
func TestConfigSnapshotIngress_MultipleListenersDuplicateService(t testing.T) *ConfigSnapshot {
|
|
|
|
snap := TestConfigSnapshotIngress_HTTPMultipleServices(t)
|
|
|
|
|
|
|
|
snap.IngressGateway.Upstreams = map[IngressListenerKey]structs.Upstreams{
|
2020-06-16 17:19:31 +00:00
|
|
|
{Protocol: "http", Port: 8080}: {
|
2020-04-21 21:06:23 +00:00
|
|
|
{
|
|
|
|
DestinationName: "foo",
|
|
|
|
LocalBindPort: 8080,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
DestinationName: "bar",
|
|
|
|
LocalBindPort: 8080,
|
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{Protocol: "http", Port: 443}: {
|
2020-04-21 21:06:23 +00:00
|
|
|
{
|
|
|
|
DestinationName: "foo",
|
|
|
|
LocalBindPort: 443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fooChain := discoverychain.TestCompileConfigEntries(t, "foo", "default", "dc1", connect.TestClusterID+".consul", "dc1", nil)
|
|
|
|
barChain := discoverychain.TestCompileConfigEntries(t, "bar", "default", "dc1", connect.TestClusterID+".consul", "dc1", nil)
|
|
|
|
|
|
|
|
snap.IngressGateway.DiscoveryChain = map[string]*structs.CompiledDiscoveryChain{
|
|
|
|
"foo": fooChain,
|
|
|
|
"bar": barChain,
|
|
|
|
}
|
|
|
|
|
|
|
|
return snap
|
|
|
|
}
|
|
|
|
|
2020-04-14 21:30:00 +00:00
|
|
|
func httpMatch(http *structs.ServiceRouteHTTPMatch) *structs.ServiceRouteMatch {
|
|
|
|
return &structs.ServiceRouteMatch{HTTP: http}
|
|
|
|
}
|
|
|
|
func httpMatchHeader(headers ...structs.ServiceRouteHTTPMatchHeader) *structs.ServiceRouteMatch {
|
|
|
|
return httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
Header: headers,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
func httpMatchParam(params ...structs.ServiceRouteHTTPMatchQueryParam) *structs.ServiceRouteMatch {
|
|
|
|
return httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
QueryParam: params,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
func toService(svc string) *structs.ServiceRouteDestination {
|
|
|
|
return &structs.ServiceRouteDestination{Service: svc}
|
|
|
|
}
|
|
|
|
|
2018-10-03 12:36:38 +00:00
|
|
|
// ControllableCacheType is a cache.Type that simulates a typical blocking RPC
|
2018-10-09 16:57:26 +00:00
|
|
|
// but lets us control the responses and when they are delivered easily.
|
2018-10-03 12:36:38 +00:00
|
|
|
type ControllableCacheType struct {
|
|
|
|
index uint64
|
2019-07-12 19:16:21 +00:00
|
|
|
value sync.Map
|
2018-10-03 12:36:38 +00:00
|
|
|
// Need a condvar to trigger all blocking requests (there might be multiple
|
|
|
|
// for same type due to background refresh and timing issues) when values
|
|
|
|
// change. Chans make it nondeterministic which one triggers or need extra
|
2018-10-09 16:57:26 +00:00
|
|
|
// locking to coordinate replacing after close etc.
|
2018-10-03 12:36:38 +00:00
|
|
|
triggerMu sync.Mutex
|
|
|
|
trigger *sync.Cond
|
|
|
|
blocking bool
|
|
|
|
lastReq atomic.Value
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewControllableCacheType returns a cache.Type that can be controlled for
|
|
|
|
// testing.
|
|
|
|
func NewControllableCacheType(t testing.T) *ControllableCacheType {
|
|
|
|
c := &ControllableCacheType{
|
|
|
|
index: 5,
|
|
|
|
blocking: true,
|
|
|
|
}
|
|
|
|
c.trigger = sync.NewCond(&c.triggerMu)
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set sets the response value to be returned from subsequent cache gets for the
|
|
|
|
// type.
|
2019-07-12 19:16:21 +00:00
|
|
|
func (ct *ControllableCacheType) Set(key string, value interface{}) {
|
2018-10-03 12:36:38 +00:00
|
|
|
atomic.AddUint64(&ct.index, 1)
|
2019-07-12 19:16:21 +00:00
|
|
|
ct.value.Store(key, value)
|
2018-10-03 12:36:38 +00:00
|
|
|
ct.triggerMu.Lock()
|
|
|
|
ct.trigger.Broadcast()
|
|
|
|
ct.triggerMu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch implements cache.Type. It simulates blocking or non-blocking queries.
|
|
|
|
func (ct *ControllableCacheType) Fetch(opts cache.FetchOptions, req cache.Request) (cache.FetchResult, error) {
|
|
|
|
index := atomic.LoadUint64(&ct.index)
|
|
|
|
|
|
|
|
ct.lastReq.Store(req)
|
|
|
|
|
|
|
|
shouldBlock := ct.blocking && opts.MinIndex > 0 && opts.MinIndex == index
|
|
|
|
if shouldBlock {
|
|
|
|
// Wait for return to be triggered. We ignore timeouts based on opts.Timeout
|
|
|
|
// since in practice they will always be way longer than our tests run for
|
|
|
|
// and the caller can simulate timeout by triggering return without changing
|
|
|
|
// index or value.
|
|
|
|
ct.triggerMu.Lock()
|
|
|
|
ct.trigger.Wait()
|
|
|
|
ct.triggerMu.Unlock()
|
|
|
|
}
|
|
|
|
|
2019-07-12 19:16:21 +00:00
|
|
|
info := req.CacheInfo()
|
|
|
|
key := path.Join(info.Key, info.Datacenter) // omit token for testing purposes
|
|
|
|
|
2018-10-03 12:36:38 +00:00
|
|
|
// reload index as it probably got bumped
|
|
|
|
index = atomic.LoadUint64(&ct.index)
|
2019-07-12 19:16:21 +00:00
|
|
|
val, _ := ct.value.Load(key)
|
2018-10-03 12:36:38 +00:00
|
|
|
|
|
|
|
if err, ok := val.(error); ok {
|
|
|
|
return cache.FetchResult{
|
|
|
|
Value: nil,
|
|
|
|
Index: index,
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
return cache.FetchResult{
|
|
|
|
Value: val,
|
|
|
|
Index: index,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-04-14 22:29:30 +00:00
|
|
|
func (ct *ControllableCacheType) RegisterOptions() cache.RegisterOptions {
|
|
|
|
return cache.RegisterOptions{
|
|
|
|
Refresh: ct.blocking,
|
|
|
|
SupportsBlocking: ct.blocking,
|
2020-07-20 20:09:20 +00:00
|
|
|
QueryTimeout: 10 * time.Minute,
|
2020-04-14 22:29:30 +00:00
|
|
|
}
|
2018-10-03 12:36:38 +00:00
|
|
|
}
|
2020-04-14 23:46:40 +00:00
|
|
|
|
|
|
|
// golden is used to read golden files stores in consul/agent/xds/testdata
|
|
|
|
func golden(t testing.T, name string) string {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
golden := filepath.Join("../xds/testdata", name+".golden")
|
|
|
|
expected, err := ioutil.ReadFile(golden)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return string(expected)
|
|
|
|
}
|