2019-03-22 19:37:14 +00:00
|
|
|
package xds
|
|
|
|
|
|
|
|
import (
|
2019-04-29 16:27:57 +00:00
|
|
|
"bytes"
|
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"
|
2019-04-29 16:27:57 +00:00
|
|
|
"text/template"
|
2020-03-17 19:50:14 +00:00
|
|
|
"time"
|
2019-03-22 19:37:14 +00:00
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
|
2021-02-22 21:00:15 +00:00
|
|
|
|
2020-09-02 21:13:50 +00:00
|
|
|
"github.com/golang/protobuf/ptypes/wrappers"
|
2020-12-23 17:50:28 +00:00
|
|
|
testinf "github.com/mitchellh/go-testing-interface"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-03-22 19:37:14 +00:00
|
|
|
"github.com/hashicorp/consul/agent/proxycfg"
|
2019-07-02 13:43:35 +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
|
|
|
)
|
|
|
|
|
2019-04-29 16:27:57 +00:00
|
|
|
func TestClustersFromSnapshot(t *testing.T) {
|
2020-12-07 18:42:55 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("too slow for testing.Short")
|
|
|
|
}
|
2019-04-29 16:27:57 +00:00
|
|
|
|
2019-03-22 19:37:14 +00:00
|
|
|
tests := []struct {
|
2019-06-18 00:52:01 +00:00
|
|
|
name string
|
|
|
|
create func(t testinf.T) *proxycfg.ConfigSnapshot
|
2019-04-29 16:27:57 +00:00
|
|
|
// Setup is called before the test starts. It is passed the snapshot from
|
2019-06-18 00:52:01 +00:00
|
|
|
// create func and is allowed to modify it in any way to setup the
|
2019-04-29 16:27:57 +00:00
|
|
|
// test input.
|
|
|
|
setup func(snap *proxycfg.ConfigSnapshot)
|
|
|
|
overrideGoldenName string
|
2019-03-22 19:37:14 +00:00
|
|
|
}{
|
|
|
|
{
|
2019-06-18 00:52:01 +00:00
|
|
|
name: "defaults",
|
|
|
|
create: proxycfg.TestConfigSnapshot,
|
|
|
|
setup: nil, // Default snapshot
|
2019-04-29 16:27:57 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-18 00:52:01 +00:00
|
|
|
name: "custom-local-app",
|
|
|
|
create: proxycfg.TestConfigSnapshot,
|
2019-04-29 16:27:57 +00:00
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
snap.Proxy.Config["envoy_local_cluster_json"] =
|
|
|
|
customAppClusterJSON(t, customClusterJSONOptions{
|
2021-02-22 21:00:15 +00:00
|
|
|
Name: "mylocal",
|
2019-04-29 16:27:57 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-06-18 00:52:01 +00:00
|
|
|
name: "custom-upstream",
|
|
|
|
create: proxycfg.TestConfigSnapshot,
|
2019-04-29 16:27:57 +00:00
|
|
|
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",
|
2019-04-29 16:27:57 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
2019-08-22 20:11:56 +00:00
|
|
|
{
|
|
|
|
name: "custom-upstream-default-chain",
|
|
|
|
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",
|
2019-04-29 16:27:57 +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",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2019-04-29 16:27:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "custom-upstream-ignores-tls",
|
2019-06-18 00:52:01 +00:00
|
|
|
create: proxycfg.TestConfigSnapshot,
|
2019-04-29 16:27:57 +00:00
|
|
|
overrideGoldenName: "custom-upstream", // should be the same
|
|
|
|
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",
|
2019-04-29 16:27:57 +00:00
|
|
|
// Attempt to override the TLS context should be ignored
|
2021-02-22 21:00:15 +00:00
|
|
|
TLSContext: `"allowRenegotiation": false`,
|
2019-04-29 16:27:57 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-06-18 00:52:01 +00:00
|
|
|
name: "custom-timeouts",
|
|
|
|
create: proxycfg.TestConfigSnapshot,
|
2019-04-29 16:27:57 +00:00
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
snap.Proxy.Config["local_connect_timeout_ms"] = 1234
|
|
|
|
snap.Proxy.Upstreams[0].Config["connect_timeout_ms"] = 2345
|
2019-03-22 19:37:14 +00:00
|
|
|
},
|
|
|
|
},
|
2019-12-03 20:13:33 +00:00
|
|
|
{
|
|
|
|
name: "custom-limits-max-connections-only",
|
|
|
|
create: proxycfg.TestConfigSnapshot,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
for i := range snap.Proxy.Upstreams {
|
|
|
|
// We check if Config is nil because the prepared_query upstream is
|
|
|
|
// initialized without a Config map. Use Upstreams[i] syntax to
|
|
|
|
// modify the actual ConfigSnapshot instead of copying the Upstream
|
|
|
|
// in the range.
|
|
|
|
if snap.Proxy.Upstreams[i].Config == nil {
|
|
|
|
snap.Proxy.Upstreams[i].Config = map[string]interface{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
snap.Proxy.Upstreams[i].Config["limits"] = map[string]interface{}{
|
|
|
|
"max_connections": 500,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "custom-limits-set-to-zero",
|
|
|
|
create: proxycfg.TestConfigSnapshot,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
for i := range snap.Proxy.Upstreams {
|
|
|
|
if snap.Proxy.Upstreams[i].Config == nil {
|
|
|
|
snap.Proxy.Upstreams[i].Config = map[string]interface{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
snap.Proxy.Upstreams[i].Config["limits"] = map[string]interface{}{
|
|
|
|
"max_connections": 0,
|
|
|
|
"max_pending_requests": 0,
|
|
|
|
"max_concurrent_requests": 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "custom-limits",
|
|
|
|
create: proxycfg.TestConfigSnapshot,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
for i := range snap.Proxy.Upstreams {
|
|
|
|
if snap.Proxy.Upstreams[i].Config == nil {
|
|
|
|
snap.Proxy.Upstreams[i].Config = map[string]interface{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
snap.Proxy.Upstreams[i].Config["limits"] = map[string]interface{}{
|
|
|
|
"max_connections": 500,
|
|
|
|
"max_pending_requests": 600,
|
|
|
|
"max_concurrent_requests": 700,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
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,
|
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
{
|
|
|
|
name: "splitter-with-resolver-redirect",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChain_SplitterWithResolverRedirectMultiDC,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2020-08-28 20:27:40 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-lb-in-resolver",
|
|
|
|
create: proxycfg.TestConfigSnapshotDiscoveryChainWithLB,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2019-09-26 02:55:52 +00:00
|
|
|
{
|
|
|
|
name: "expose-paths-local-app-paths",
|
|
|
|
create: proxycfg.TestConfigSnapshotExposeConfig,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "expose-paths-new-cluster-http2",
|
|
|
|
create: proxycfg.TestConfigSnapshotExposeConfig,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
snap.Proxy.Expose.Paths[1] = structs.ExposePath{
|
|
|
|
LocalPathPort: 9090,
|
|
|
|
Path: "/grpc.health.v1.Health/Check",
|
|
|
|
ListenerPort: 21501,
|
|
|
|
Protocol: "http2",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-04-02 07:35:04 +00:00
|
|
|
{
|
|
|
|
name: "expose-paths-grpc-new-cluster-http1",
|
|
|
|
create: proxycfg.TestConfigSnapshotGRPCExposeHTTP1,
|
|
|
|
},
|
2019-06-18 00:52:01 +00:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
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-02-19 16:57:55 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-ignore-extra-resolvers",
|
|
|
|
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("notfound", nil): {
|
2020-02-19 16:57:55 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "notfound",
|
|
|
|
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-03-17 19:50:14 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-service-timeouts",
|
|
|
|
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-03-17 19:50:14 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "bar",
|
|
|
|
ConnectTimeout: 10 * time.Second,
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
2020-06-16 17:19:31 +00:00
|
|
|
"v1": {
|
2020-03-17 19:50:14 +00:00
|
|
|
Filter: "Service.Meta.Version == 1",
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"v2": {
|
2020-03-17 19:50:14 +00:00
|
|
|
Filter: "Service.Meta.Version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-08-28 20:27:40 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-non-hash-lb-injected",
|
|
|
|
create: proxycfg.TestConfigSnapshotMeshGateway,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
|
|
|
|
structs.NewServiceName("bar", nil): {
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "bar",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.Version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.Version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
2020-09-02 15:10:50 +00:00
|
|
|
LoadBalancer: &structs.LoadBalancer{
|
2020-09-11 15:21:43 +00:00
|
|
|
Policy: "least_request",
|
|
|
|
LeastRequestConfig: &structs.LeastRequestConfig{
|
|
|
|
ChoiceCount: 5,
|
2020-08-28 20:27:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh-gateway-hash-lb-ignored",
|
|
|
|
create: proxycfg.TestConfigSnapshotMeshGateway,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
snap.MeshGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
|
|
|
|
structs.NewServiceName("bar", nil): {
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "bar",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.Version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.Version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
2020-09-02 15:10:50 +00:00
|
|
|
LoadBalancer: &structs.LoadBalancer{
|
2020-09-11 15:21:43 +00:00
|
|
|
Policy: "ring_hash",
|
|
|
|
RingHashConfig: &structs.RingHashConfig{
|
|
|
|
MinimumRingSize: 20,
|
|
|
|
MaximumRingSize: 50,
|
2020-08-28 20:27:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
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-08-28 20:27:40 +00:00
|
|
|
{
|
|
|
|
name: "ingress-lb-in-resolver",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngressWithLB,
|
|
|
|
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-19 19:31:39 +00:00
|
|
|
structs.NewServiceName("cache", nil): {
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "cache",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"prod": {
|
|
|
|
Filter: "Service.Meta.Env == prod",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-04-14 14:59:23 +00:00
|
|
|
}
|
2020-09-03 14:57:48 +00:00
|
|
|
snap.TerminatingGateway.ServiceConfigs[structs.NewServiceName("web", nil)] = &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
}
|
|
|
|
snap.TerminatingGateway.ServiceConfigs[structs.NewServiceName("cache", nil)] = &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
}
|
2020-04-14 14:59:23 +00:00
|
|
|
},
|
|
|
|
},
|
2020-06-03 21:28:45 +00:00
|
|
|
{
|
|
|
|
name: "terminating-gateway-hostname-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("api", nil): {
|
2020-06-03 21:28:45 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "api",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"alt": {
|
|
|
|
Filter: "Service.Meta.domain == alt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-19 19:31:39 +00:00
|
|
|
structs.NewServiceName("cache", nil): {
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "cache",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"prod": {
|
|
|
|
Filter: "Service.Meta.Env == prod",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-03 21:28:45 +00:00
|
|
|
}
|
2020-09-03 14:57:48 +00:00
|
|
|
snap.TerminatingGateway.ServiceConfigs[structs.NewServiceName("api", nil)] = &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
}
|
|
|
|
snap.TerminatingGateway.ServiceConfigs[structs.NewServiceName("cache", nil)] = &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
}
|
2020-06-03 21:28:45 +00:00
|
|
|
},
|
|
|
|
},
|
2020-04-14 14:59:23 +00:00
|
|
|
{
|
|
|
|
name: "terminating-gateway-ignore-extra-resolvers",
|
|
|
|
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",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
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("notfound", nil): {
|
2020-04-14 14:59:23 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "notfound",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.Version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.Version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-09-03 14:57:48 +00:00
|
|
|
snap.TerminatingGateway.ServiceConfigs[structs.NewServiceName("web", nil)] = &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
}
|
2020-04-14 14:59:23 +00:00
|
|
|
},
|
|
|
|
},
|
2020-08-28 20:27:40 +00:00
|
|
|
{
|
|
|
|
name: "terminating-gateway-lb-config",
|
|
|
|
create: proxycfg.TestConfigSnapshotTerminatingGateway,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
|
|
|
snap.TerminatingGateway.ServiceResolvers = map[structs.ServiceName]*structs.ServiceResolverConfigEntry{
|
|
|
|
structs.NewServiceName("web", nil): {
|
|
|
|
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-09-02 15:10:50 +00:00
|
|
|
LoadBalancer: &structs.LoadBalancer{
|
2020-09-11 15:21:43 +00:00
|
|
|
Policy: "ring_hash",
|
|
|
|
RingHashConfig: &structs.RingHashConfig{
|
|
|
|
MinimumRingSize: 20,
|
|
|
|
MaximumRingSize: 50,
|
2020-08-28 20:27:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-09-03 14:57:48 +00:00
|
|
|
snap.TerminatingGateway.ServiceConfigs[structs.NewServiceName("web", nil)] = &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
}
|
2020-08-28 20:27:40 +00:00
|
|
|
},
|
|
|
|
},
|
2020-04-21 21:06:23 +00:00
|
|
|
{
|
|
|
|
name: "ingress-multiple-listeners-duplicate-service",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngress_MultipleListenersDuplicateService,
|
|
|
|
setup: nil,
|
|
|
|
},
|
2021-03-17 19:40:49 +00:00
|
|
|
{
|
|
|
|
name: "transparent-proxy",
|
|
|
|
create: proxycfg.TestConfigSnapshot,
|
|
|
|
setup: func(snap *proxycfg.ConfigSnapshot) {
|
2021-04-12 15:35:14 +00:00
|
|
|
snap.Proxy.Mode = structs.ProxyModeTransparent
|
|
|
|
|
2021-04-28 22:13:29 +00:00
|
|
|
snap.ConnectProxy.MeshConfigSet = true
|
|
|
|
snap.ConnectProxy.MeshConfig = &structs.MeshConfigEntry{
|
|
|
|
TransparentProxy: structs.TransparentProxyMeshConfig{
|
2021-04-12 15:35:14 +00:00
|
|
|
CatalogDestinationsOnly: false,
|
|
|
|
},
|
|
|
|
}
|
2021-03-17 19:40:49 +00:00
|
|
|
},
|
|
|
|
},
|
2019-03-22 19:37:14 +00:00
|
|
|
}
|
2019-04-29 16:27:57 +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-04-29 16:27:57 +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
|
|
|
|
// golder files for every test case and so not be any use!
|
|
|
|
setupTLSRootsAndLeaf(t, snap)
|
2019-04-29 16:27:57 +00:00
|
|
|
|
2020-07-09 22:04:51 +00:00
|
|
|
if tt.setup != nil {
|
|
|
|
tt.setup(snap)
|
|
|
|
}
|
2019-04-29 16:27:57 +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-04-29 16:27:57 +00:00
|
|
|
|
2021-04-29 18:54:05 +00:00
|
|
|
clusters, err := g.clustersFromSnapshot(snap)
|
2021-02-26 22:23:15 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-07-09 22:04:51 +00:00
|
|
|
sort.Slice(clusters, func(i, j int) bool {
|
2021-02-26 22:23:15 +00:00
|
|
|
return clusters[i].(*envoy_cluster_v3.Cluster).Name < clusters[j].(*envoy_cluster_v3.Cluster).Name
|
2020-07-09 22:04:51 +00:00
|
|
|
})
|
2021-02-26 22:23:15 +00:00
|
|
|
|
2020-07-09 22:04:51 +00:00
|
|
|
r, err := createResponse(ClusterType, "00000001", "00000001", clusters)
|
2021-02-26 22:23:15 +00:00
|
|
|
require.NoError(t, err)
|
2019-04-29 16:27:57 +00:00
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
t.Run("current", func(t *testing.T) {
|
|
|
|
gotJSON := protoToJSON(t, r)
|
2019-04-29 16:27:57 +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("clusters", gName), envoyVersion, latestEnvoyVersion, gotJSON), gotJSON)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("v2-compat", func(t *testing.T) {
|
|
|
|
respV2, err := convertDiscoveryResponseToV2(r)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
gotJSON := protoToJSON(t, respV2)
|
|
|
|
|
|
|
|
gName := tt.name
|
|
|
|
if tt.overrideGoldenName != "" {
|
|
|
|
gName = tt.overrideGoldenName
|
|
|
|
}
|
|
|
|
|
|
|
|
gName += ".v2compat"
|
2019-03-22 19:37:14 +00:00
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
require.JSONEq(t, goldenEnvoy(t, filepath.Join("clusters", gName), envoyVersion, latestEnvoyVersion, gotJSON), gotJSON)
|
|
|
|
})
|
2020-07-09 22:04:51 +00:00
|
|
|
})
|
|
|
|
}
|
2019-03-22 19:37:14 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 16:27:57 +00:00
|
|
|
|
|
|
|
type customClusterJSONOptions struct {
|
2021-02-22 21:00:15 +00:00
|
|
|
Name string
|
|
|
|
TLSContext string
|
2019-04-29 16:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var customAppClusterJSONTpl = `{
|
2021-02-26 22:23:15 +00:00
|
|
|
"@type": "type.googleapis.com/envoy.config.cluster.v3.Cluster",
|
2019-04-29 16:27:57 +00:00
|
|
|
{{ if .TLSContext -}}
|
2021-02-22 21:00:15 +00:00
|
|
|
"transport_socket": {
|
|
|
|
"name": "tls",
|
|
|
|
"typed_config": {
|
2021-02-26 22:23:15 +00:00
|
|
|
"@type": "type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext",
|
2021-02-22 21:00:15 +00:00
|
|
|
{{ .TLSContext }}
|
|
|
|
}
|
|
|
|
},
|
2019-04-29 16:27:57 +00:00
|
|
|
{{- end }}
|
|
|
|
"name": "{{ .Name }}",
|
2019-08-22 20:11:56 +00:00
|
|
|
"connectTimeout": "15s",
|
2021-02-26 22:23:15 +00:00
|
|
|
"loadAssignment": {
|
|
|
|
"clusterName": "{{ .Name }}",
|
|
|
|
"endpoints": [
|
|
|
|
{
|
|
|
|
"lbEndpoints": [
|
|
|
|
{
|
|
|
|
"endpoint": {
|
|
|
|
"address": {
|
|
|
|
"socketAddress": {
|
|
|
|
"address": "127.0.0.1",
|
|
|
|
"portValue": 8080
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2019-04-29 16:27:57 +00:00
|
|
|
}
|
2021-02-26 22:23:15 +00:00
|
|
|
]
|
|
|
|
}
|
2019-04-29 16:27:57 +00:00
|
|
|
}`
|
|
|
|
|
|
|
|
var customAppClusterJSONTemplate = template.Must(template.New("").Parse(customAppClusterJSONTpl))
|
|
|
|
|
|
|
|
func customAppClusterJSON(t *testing.T, opts customClusterJSONOptions) string {
|
|
|
|
t.Helper()
|
|
|
|
var buf bytes.Buffer
|
|
|
|
err := customAppClusterJSONTemplate.Execute(&buf, opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return buf.String()
|
|
|
|
}
|
2020-04-16 21:00:48 +00:00
|
|
|
|
|
|
|
func setupTLSRootsAndLeaf(t *testing.T, snap *proxycfg.ConfigSnapshot) {
|
|
|
|
if snap.Leaf() != nil {
|
|
|
|
switch snap.Kind {
|
|
|
|
case structs.ServiceKindConnectProxy:
|
2021-02-24 20:04:31 +00:00
|
|
|
snap.ConnectProxy.Leaf.CertPEM = loadTestResource(t, "test-leaf-cert")
|
|
|
|
snap.ConnectProxy.Leaf.PrivateKeyPEM = loadTestResource(t, "test-leaf-key")
|
2020-04-16 21:00:48 +00:00
|
|
|
case structs.ServiceKindIngressGateway:
|
2021-02-24 20:04:31 +00:00
|
|
|
snap.IngressGateway.Leaf.CertPEM = loadTestResource(t, "test-leaf-cert")
|
|
|
|
snap.IngressGateway.Leaf.PrivateKeyPEM = loadTestResource(t, "test-leaf-key")
|
2020-04-16 21:00:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if snap.Roots != nil {
|
2021-02-24 20:04:31 +00:00
|
|
|
snap.Roots.Roots[0].RootCert = loadTestResource(t, "test-root-cert")
|
2020-04-16 21:00:48 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-02 21:13:50 +00:00
|
|
|
|
|
|
|
func TestEnvoyLBConfig_InjectToCluster(t *testing.T) {
|
|
|
|
var tests = []struct {
|
|
|
|
name string
|
2020-09-11 15:21:43 +00:00
|
|
|
lb *structs.LoadBalancer
|
2021-02-26 22:23:15 +00:00
|
|
|
expected *envoy_cluster_v3.Cluster
|
2020-09-02 21:13:50 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "skip empty",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: "",
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_cluster_v3.Cluster{},
|
2020-09-02 21:13:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "round robin",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: structs.LBPolicyRoundRobin,
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_cluster_v3.Cluster{LbPolicy: envoy_cluster_v3.Cluster_ROUND_ROBIN},
|
2020-09-02 21:13:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "random",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: structs.LBPolicyRandom,
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_cluster_v3.Cluster{LbPolicy: envoy_cluster_v3.Cluster_RANDOM},
|
2020-09-02 21:13:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "maglev",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: structs.LBPolicyMaglev,
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_cluster_v3.Cluster{LbPolicy: envoy_cluster_v3.Cluster_MAGLEV},
|
2020-09-02 21:13:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ring_hash",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: structs.LBPolicyRingHash,
|
|
|
|
RingHashConfig: &structs.RingHashConfig{
|
|
|
|
MinimumRingSize: 3,
|
|
|
|
MaximumRingSize: 7,
|
|
|
|
},
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_cluster_v3.Cluster{
|
|
|
|
LbPolicy: envoy_cluster_v3.Cluster_RING_HASH,
|
|
|
|
LbConfig: &envoy_cluster_v3.Cluster_RingHashLbConfig_{
|
|
|
|
RingHashLbConfig: &envoy_cluster_v3.Cluster_RingHashLbConfig{
|
2020-09-02 21:13:50 +00:00
|
|
|
MinimumRingSize: &wrappers.UInt64Value{Value: 3},
|
|
|
|
MaximumRingSize: &wrappers.UInt64Value{Value: 7},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "least_request",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: "least_request",
|
|
|
|
LeastRequestConfig: &structs.LeastRequestConfig{
|
|
|
|
ChoiceCount: 3,
|
|
|
|
},
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_cluster_v3.Cluster{
|
|
|
|
LbPolicy: envoy_cluster_v3.Cluster_LEAST_REQUEST,
|
|
|
|
LbConfig: &envoy_cluster_v3.Cluster_LeastRequestLbConfig_{
|
|
|
|
LeastRequestLbConfig: &envoy_cluster_v3.Cluster_LeastRequestLbConfig{
|
2020-09-02 21:13:50 +00:00
|
|
|
ChoiceCount: &wrappers.UInt32Value{Value: 3},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2021-02-26 22:23:15 +00:00
|
|
|
var c envoy_cluster_v3.Cluster
|
2020-09-02 21:13:50 +00:00
|
|
|
err := injectLBToCluster(tc.lb, &c)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-02-22 21:00:15 +00:00
|
|
|
require.Equal(t, tc.expected, &c)
|
2020-09-02 21:13:50 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|