2019-03-22 19:37:14 +00:00
|
|
|
package xds
|
|
|
|
|
|
|
|
import (
|
2020-07-09 22:04:51 +00:00
|
|
|
"path/filepath"
|
2019-07-02 19:53:06 +00:00
|
|
|
"sort"
|
2019-03-22 19:37:14 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
|
|
|
|
envoy_endpoint_v3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
|
2021-02-22 21:00:15 +00:00
|
|
|
|
|
|
|
"github.com/mitchellh/copystructure"
|
2020-12-23 17:50:28 +00:00
|
|
|
testinf "github.com/mitchellh/go-testing-interface"
|
2021-02-22 21:00:15 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-12-23 17:50:28 +00:00
|
|
|
|
2019-06-18 00:52:01 +00:00
|
|
|
"github.com/hashicorp/consul/agent/proxycfg"
|
2019-03-22 19:37:14 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2020-07-31 20:52:49 +00:00
|
|
|
"github.com/hashicorp/consul/agent/xds/proxysupport"
|
2020-01-28 23:50:41 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
2019-03-22 19:37:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_makeLoadAssignment(t *testing.T) {
|
|
|
|
|
|
|
|
testCheckServiceNodes := structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "node1-id",
|
|
|
|
Node: "node1",
|
|
|
|
Address: "10.10.10.10",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "web",
|
|
|
|
Port: 1234,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
&structs.HealthCheck{
|
|
|
|
Node: "node1",
|
|
|
|
CheckID: "serfHealth",
|
|
|
|
Status: "passing",
|
|
|
|
},
|
|
|
|
&structs.HealthCheck{
|
|
|
|
Node: "node1",
|
|
|
|
ServiceID: "web",
|
|
|
|
CheckID: "web:check",
|
|
|
|
Status: "passing",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "node2-id",
|
|
|
|
Node: "node2",
|
|
|
|
Address: "10.10.10.20",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "web",
|
|
|
|
Port: 1234,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
&structs.HealthCheck{
|
|
|
|
Node: "node2",
|
|
|
|
CheckID: "serfHealth",
|
|
|
|
Status: "passing",
|
|
|
|
},
|
|
|
|
&structs.HealthCheck{
|
|
|
|
Node: "node2",
|
|
|
|
ServiceID: "web",
|
|
|
|
CheckID: "web:check",
|
|
|
|
Status: "passing",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
testWeightedCheckServiceNodesRaw, err := copystructure.Copy(testCheckServiceNodes)
|
|
|
|
require.NoError(t, err)
|
|
|
|
testWeightedCheckServiceNodes := testWeightedCheckServiceNodesRaw.(structs.CheckServiceNodes)
|
|
|
|
|
|
|
|
testWeightedCheckServiceNodes[0].Service.Weights = &structs.Weights{
|
|
|
|
Passing: 10,
|
|
|
|
Warning: 1,
|
|
|
|
}
|
|
|
|
testWeightedCheckServiceNodes[1].Service.Weights = &structs.Weights{
|
|
|
|
Passing: 5,
|
|
|
|
Warning: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
testWarningCheckServiceNodesRaw, err := copystructure.Copy(testWeightedCheckServiceNodes)
|
|
|
|
require.NoError(t, err)
|
|
|
|
testWarningCheckServiceNodes := testWarningCheckServiceNodesRaw.(structs.CheckServiceNodes)
|
|
|
|
|
|
|
|
testWarningCheckServiceNodes[0].Checks[0].Status = "warning"
|
|
|
|
testWarningCheckServiceNodes[1].Checks[0].Status = "warning"
|
|
|
|
|
2019-07-24 01:20:24 +00:00
|
|
|
// TODO(rb): test onlypassing
|
2019-03-22 19:37:14 +00:00
|
|
|
tests := []struct {
|
2019-08-02 20:34:54 +00:00
|
|
|
name string
|
|
|
|
clusterName string
|
|
|
|
endpoints []loadAssignmentEndpointGroup
|
2021-02-26 22:23:15 +00:00
|
|
|
want *envoy_endpoint_v3.ClusterLoadAssignment
|
2019-03-22 19:37:14 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no instances",
|
|
|
|
clusterName: "service:test",
|
2019-07-24 01:20:24 +00:00
|
|
|
endpoints: []loadAssignmentEndpointGroup{
|
|
|
|
{Endpoints: nil},
|
2019-07-02 03:10:51 +00:00
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
want: &envoy_endpoint_v3.ClusterLoadAssignment{
|
2019-03-22 19:37:14 +00:00
|
|
|
ClusterName: "service:test",
|
2021-02-26 22:23:15 +00:00
|
|
|
Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{{
|
|
|
|
LbEndpoints: []*envoy_endpoint_v3.LbEndpoint{},
|
2019-03-22 19:37:14 +00:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "instances, no weights",
|
|
|
|
clusterName: "service:test",
|
2019-07-24 01:20:24 +00:00
|
|
|
endpoints: []loadAssignmentEndpointGroup{
|
|
|
|
{Endpoints: testCheckServiceNodes},
|
2019-07-02 03:10:51 +00:00
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
want: &envoy_endpoint_v3.ClusterLoadAssignment{
|
2019-03-22 19:37:14 +00:00
|
|
|
ClusterName: "service:test",
|
2021-02-26 22:23:15 +00:00
|
|
|
Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{{
|
|
|
|
LbEndpoints: []*envoy_endpoint_v3.LbEndpoint{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
HostIdentifier: &envoy_endpoint_v3.LbEndpoint_Endpoint{
|
|
|
|
Endpoint: &envoy_endpoint_v3.Endpoint{
|
2020-06-23 20:19:56 +00:00
|
|
|
Address: makeAddress("10.10.10.10", 1234),
|
2019-06-07 12:10:43 +00:00
|
|
|
}},
|
2021-02-26 22:23:15 +00:00
|
|
|
HealthStatus: envoy_core_v3.HealthStatus_HEALTHY,
|
2019-03-22 19:37:14 +00:00
|
|
|
LoadBalancingWeight: makeUint32Value(1),
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
HostIdentifier: &envoy_endpoint_v3.LbEndpoint_Endpoint{
|
|
|
|
Endpoint: &envoy_endpoint_v3.Endpoint{
|
2020-06-23 20:19:56 +00:00
|
|
|
Address: makeAddress("10.10.10.20", 1234),
|
2019-06-07 12:10:43 +00:00
|
|
|
}},
|
2021-02-26 22:23:15 +00:00
|
|
|
HealthStatus: envoy_core_v3.HealthStatus_HEALTHY,
|
2019-03-22 19:37:14 +00:00
|
|
|
LoadBalancingWeight: makeUint32Value(1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "instances, healthy weights",
|
|
|
|
clusterName: "service:test",
|
2019-07-24 01:20:24 +00:00
|
|
|
endpoints: []loadAssignmentEndpointGroup{
|
|
|
|
{Endpoints: testWeightedCheckServiceNodes},
|
2019-07-02 03:10:51 +00:00
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
want: &envoy_endpoint_v3.ClusterLoadAssignment{
|
2019-03-22 19:37:14 +00:00
|
|
|
ClusterName: "service:test",
|
2021-02-26 22:23:15 +00:00
|
|
|
Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{{
|
|
|
|
LbEndpoints: []*envoy_endpoint_v3.LbEndpoint{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
HostIdentifier: &envoy_endpoint_v3.LbEndpoint_Endpoint{
|
|
|
|
Endpoint: &envoy_endpoint_v3.Endpoint{
|
2020-06-23 20:19:56 +00:00
|
|
|
Address: makeAddress("10.10.10.10", 1234),
|
2019-06-07 12:10:43 +00:00
|
|
|
}},
|
2021-02-26 22:23:15 +00:00
|
|
|
HealthStatus: envoy_core_v3.HealthStatus_HEALTHY,
|
2019-03-22 19:37:14 +00:00
|
|
|
LoadBalancingWeight: makeUint32Value(10),
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
HostIdentifier: &envoy_endpoint_v3.LbEndpoint_Endpoint{
|
|
|
|
Endpoint: &envoy_endpoint_v3.Endpoint{
|
2020-06-23 20:19:56 +00:00
|
|
|
Address: makeAddress("10.10.10.20", 1234),
|
2019-06-07 12:10:43 +00:00
|
|
|
}},
|
2021-02-26 22:23:15 +00:00
|
|
|
HealthStatus: envoy_core_v3.HealthStatus_HEALTHY,
|
2019-03-22 19:37:14 +00:00
|
|
|
LoadBalancingWeight: makeUint32Value(5),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "instances, warning weights",
|
|
|
|
clusterName: "service:test",
|
2019-07-24 01:20:24 +00:00
|
|
|
endpoints: []loadAssignmentEndpointGroup{
|
|
|
|
{Endpoints: testWarningCheckServiceNodes},
|
2019-07-02 03:10:51 +00:00
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
want: &envoy_endpoint_v3.ClusterLoadAssignment{
|
2019-03-22 19:37:14 +00:00
|
|
|
ClusterName: "service:test",
|
2021-02-26 22:23:15 +00:00
|
|
|
Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{{
|
|
|
|
LbEndpoints: []*envoy_endpoint_v3.LbEndpoint{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
HostIdentifier: &envoy_endpoint_v3.LbEndpoint_Endpoint{
|
|
|
|
Endpoint: &envoy_endpoint_v3.Endpoint{
|
2020-06-23 20:19:56 +00:00
|
|
|
Address: makeAddress("10.10.10.10", 1234),
|
2019-06-07 12:10:43 +00:00
|
|
|
}},
|
2021-02-26 22:23:15 +00:00
|
|
|
HealthStatus: envoy_core_v3.HealthStatus_HEALTHY,
|
2019-03-22 19:37:14 +00:00
|
|
|
LoadBalancingWeight: makeUint32Value(1),
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
HostIdentifier: &envoy_endpoint_v3.LbEndpoint_Endpoint{
|
|
|
|
Endpoint: &envoy_endpoint_v3.Endpoint{
|
2020-06-23 20:19:56 +00:00
|
|
|
Address: makeAddress("10.10.10.20", 1234),
|
2019-06-07 12:10:43 +00:00
|
|
|
}},
|
2021-02-26 22:23:15 +00:00
|
|
|
HealthStatus: envoy_core_v3.HealthStatus_UNHEALTHY,
|
2019-03-22 19:37:14 +00:00
|
|
|
LoadBalancingWeight: makeUint32Value(1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2019-07-24 01:20:24 +00:00
|
|
|
got := makeLoadAssignment(
|
|
|
|
tt.clusterName,
|
|
|
|
tt.endpoints,
|
2021-10-29 00:41:58 +00:00
|
|
|
proxycfg.GatewayKey{Datacenter: "dc1"},
|
2019-07-24 01:20:24 +00:00
|
|
|
)
|
2019-03-22 19:37:14 +00:00
|
|
|
require.Equal(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
func TestEndpointsFromSnapshot(t *testing.T) {
|
2020-12-07 18:42:55 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("too slow for testing.Short")
|
|
|
|
}
|
2019-06-18 00:52:01 +00:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
create func(t testinf.T) *proxycfg.ConfigSnapshot
|
|
|
|
// Setup is called before the test starts. It is passed the snapshot from
|
|
|
|
// create func and is allowed to modify it in any way to setup the
|
|
|
|
// test input.
|
|
|
|
setup func(snap *proxycfg.ConfigSnapshot)
|
|
|
|
overrideGoldenName string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "defaults",
|
|
|
|
create: proxycfg.TestConfigSnapshot,
|
|
|
|
setup: nil, // Default snapshot
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotMeshGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2020-03-09 20:59:02 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-using-federation-states",
|
|
|
|
create: proxycfg.TestConfigSnapshotMeshGatewayUsingFederationStates,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2019-10-17 21:46:49 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-no-services",
|
|
|
|
create: proxycfg.TestConfigSnapshotMeshGatewayNoServices,
|
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-with-chain",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChain,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2019-08-19 17:19:44 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-with-chain-external-sni",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainExternalSNI,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2019-08-02 03:03:34 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-with-chain-and-overrides",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithOverrides,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-with-chain-and-failover",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithFailover,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2019-08-05 18:30:35 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-with-tcp-chain-failover-through-remote-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithFailoverThroughRemoteGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-with-tcp-chain-failover-through-remote-gateway-triggered",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithFailoverThroughRemoteGatewayTriggered,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-with-tcp-chain-double-failover-through-remote-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithDoubleFailoverThroughRemoteGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-with-tcp-chain-double-failover-through-remote-gateway-triggered",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithDoubleFailoverThroughRemoteGatewayTriggered,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-with-tcp-chain-failover-through-local-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithFailoverThroughLocalGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-with-tcp-chain-failover-through-local-gateway-triggered",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithFailoverThroughLocalGatewayTriggered,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-with-tcp-chain-double-failover-through-local-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithDoubleFailoverThroughLocalGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-with-tcp-chain-double-failover-through-local-gateway-triggered",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithDoubleFailoverThroughLocalGatewayTriggered,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2020-05-26 08:57:22 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-with-default-chain-and-custom-cluster",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainDefault,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
snap.Proxy.Upstreams[0].Config["envoy_cluster_json"] =
|
|
|
|
customAppClusterJSON(t, customClusterJSONOptions{
|
2021-02-22 21:00:15 +00:00
|
|
|
Name: "myservice",
|
2020-05-26 08:57:22 +00:00
|
|
|
})
|
2021-03-17 19:40:49 +00:00
|
|
|
snap.ConnectProxy.UpstreamConfig = map[string]*structs.Upstream{
|
|
|
|
"db": {
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"envoy_cluster_json": customAppClusterJSON(t, customClusterJSONOptions{
|
|
|
|
Name: "myservice",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-05-26 08:57:22 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
{
|
|
|
|
name: "splitter-with-resolver-redirect",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChain_SplitterWithResolverRedirectMultiDC,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2019-07-02 13:43:35 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-service-subsets",
|
|
|
|
create: proxycfg.TestConfigSnapshotMeshGateway,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
2020-06-12 14:57:41 +00:00
|
|
|
snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
|
2020-06-16 17:19:31 +00:00
|
|
|
structs.NewServiceName("bar", nil): {
|
2019-07-02 13:43:35 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "bar",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2019-07-02 13:43:35 +00:00
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2019-07-02 13:43:35 +00:00
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
structs.NewServiceName("foo", nil): {
|
2019-07-02 13:43:35 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "foo",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2019-07-02 13:43:35 +00:00
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2019-07-02 13:43:35 +00:00
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-02-19 16:57:55 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-default-service-subset",
|
|
|
|
create: proxycfg.TestConfigSnapshotMeshGateway,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
2020-06-12 14:57:41 +00:00
|
|
|
snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
|
2020-06-16 17:19:31 +00:00
|
|
|
structs.NewServiceName("bar", nil): {
|
2020-02-19 16:57:55 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "bar",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2020-02-19 16:57:55 +00:00
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2020-02-19 16:57:55 +00:00
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
structs.NewServiceName("foo", nil): {
|
2020-02-19 16:57:55 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "foo",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2020-02-19 16:57:55 +00:00
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2020-02-19 16:57:55 +00:00
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-04-16 21:00:48 +00:00
|
|
|
{
|
|
|
|
name: "ingress-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-gateway-no-services",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressGatewayNoServices,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2020-04-14 21:30:00 +00:00
|
|
|
{
|
|
|
|
name: "ingress-with-chain",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngress,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-chain-external-sni",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressExternalSNI,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-chain-and-overrides",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithOverrides,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-chain-and-failover",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithFailover,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-tcp-chain-failover-through-remote-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithFailoverThroughRemoteGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-tcp-chain-failover-through-remote-gateway-triggered",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithFailoverThroughRemoteGatewayTriggered,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-tcp-chain-double-failover-through-remote-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithDoubleFailoverThroughRemoteGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-tcp-chain-double-failover-through-remote-gateway-triggered",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithDoubleFailoverThroughRemoteGatewayTriggered,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-tcp-chain-failover-through-local-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithFailoverThroughLocalGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-tcp-chain-failover-through-local-gateway-triggered",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithFailoverThroughLocalGatewayTriggered,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-tcp-chain-double-failover-through-local-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithDoubleFailoverThroughLocalGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-with-tcp-chain-double-failover-through-local-gateway-triggered",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithDoubleFailoverThroughLocalGatewayTriggered,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ingress-splitter-with-resolver-redirect",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngress_SplitterWithResolverRedirectMultiDC,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2020-04-13 16:33:01 +00:00
|
|
|
{
|
|
|
|
name: "terminating-gateway",
|
|
|
|
create: proxycfg.TestConfigSnapshotTerminatingGateway,
|
|
|
|
setup: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "terminating-gateway-no-services",
|
|
|
|
create: proxycfg.TestConfigSnapshotTerminatingGatewayNoServices,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2020-04-14 14:59:23 +00:00
|
|
|
{
|
|
|
|
name: "terminating-gateway-service-subsets",
|
|
|
|
create: proxycfg.TestConfigSnapshotTerminatingGateway,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
2020-06-12 14:57:41 +00:00
|
|
|
snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
|
|
|
|
structs.NewServiceName("web", nil): {
|
2020-04-14 14:59:23 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-12 14:57:41 +00:00
|
|
|
structs.NewServiceName("web", nil): {
|
2020-04-14 14:59:23 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "terminating-gateway-default-service-subset",
|
|
|
|
create: proxycfg.TestConfigSnapshotTerminatingGateway,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
2020-06-12 14:57:41 +00:00
|
|
|
snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
|
2020-06-16 17:19:31 +00:00
|
|
|
structs.NewServiceName("web", nil): {
|
2020-04-14 14:59:23 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
structs.NewServiceName("web", nil): {
|
2020-04-14 14:59:23 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-04-21 21:06:23 +00:00
|
|
|
{
|
|
|
|
name: "ingress-multiple-listeners-duplicate-service",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngress_MultipleListenersDuplicateService,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2019-06-18 00:52:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 20:04:31 +00:00
|
|
|
latestEnvoyVersion := proxysupport.EnvoyVersions[0]
|
2020-07-31 20:52:49 +00:00
|
|
|
for _, envoyVersion := range proxysupport.EnvoyVersions {
|
|
|
|
sf, err := determineSupportedProxyFeaturesFromString(envoyVersion)
|
|
|
|
require.NoError(t, err)
|
2020-07-09 22:04:51 +00:00
|
|
|
t.Run("envoy-"+envoyVersion, func(t *testing.T) {
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
// Sanity check default with no overrides first
|
|
|
|
snap := tt.create(t)
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2020-07-09 22:04:51 +00:00
|
|
|
// We need to replace the TLS certs with deterministic ones to make golden
|
|
|
|
// files workable. Note we don't update these otherwise they'd change
|
|
|
|
// golden files for every test case and so not be any use!
|
|
|
|
setupTLSRootsAndLeaf(t, snap)
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2020-07-09 22:04:51 +00:00
|
|
|
if tt.setup != nil {
|
|
|
|
tt.setup(snap)
|
|
|
|
}
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2020-07-09 22:04:51 +00:00
|
|
|
// Need server just for logger dependency
|
2021-04-29 18:54:05 +00:00
|
|
|
g := newResourceGenerator(testutil.Logger(t), nil, nil, false)
|
|
|
|
g.ProxyFeatures = sf
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2021-04-29 18:54:05 +00:00
|
|
|
endpoints, err := g.endpointsFromSnapshot(snap)
|
2021-02-26 22:23:15 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-07-09 22:04:51 +00:00
|
|
|
sort.Slice(endpoints, func(i, j int) bool {
|
2021-02-26 22:23:15 +00:00
|
|
|
return endpoints[i].(*envoy_endpoint_v3.ClusterLoadAssignment).ClusterName < endpoints[j].(*envoy_endpoint_v3.ClusterLoadAssignment).ClusterName
|
2020-07-09 22:04:51 +00:00
|
|
|
})
|
|
|
|
r, err := createResponse(EndpointType, "00000001", "00000001", endpoints)
|
2021-02-26 22:23:15 +00:00
|
|
|
require.NoError(t, err)
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
t.Run("current", func(t *testing.T) {
|
|
|
|
gotJSON := protoToJSON(t, r)
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
gName := tt.name
|
|
|
|
if tt.overrideGoldenName != "" {
|
|
|
|
gName = tt.overrideGoldenName
|
|
|
|
}
|
|
|
|
|
|
|
|
require.JSONEq(t, goldenEnvoy(t, filepath.Join("endpoints", gName), envoyVersion, latestEnvoyVersion, gotJSON), gotJSON)
|
|
|
|
})
|
2020-07-09 22:04:51 +00:00
|
|
|
})
|
|
|
|
}
|
2019-06-18 00:52:01 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|