2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
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"
|
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"
|
2023-08-17 19:55:54 +00:00
|
|
|
"github.com/hashicorp/consul/agent/xds/proxystateconverter"
|
2023-08-17 18:43:21 +00:00
|
|
|
"github.com/hashicorp/consul/agent/xds/response"
|
2023-08-17 19:55:54 +00:00
|
|
|
"github.com/hashicorp/consul/agent/xds/testcommon"
|
|
|
|
"github.com/hashicorp/consul/agent/xdsv2"
|
2023-02-06 17:14:35 +00:00
|
|
|
"github.com/hashicorp/consul/envoyextensions/xdscommon"
|
2020-01-28 23:50:41 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
2023-08-17 19:55:54 +00:00
|
|
|
"github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/mitchellh/copystructure"
|
|
|
|
testinf "github.com/mitchellh/go-testing-interface"
|
|
|
|
"github.com/stretchr/testify/require"
|
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
|
2023-06-21 16:39:53 +00:00
|
|
|
locality *structs.Locality
|
2019-08-02 20:34:54 +00:00
|
|
|
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{
|
2023-08-17 18:43:21 +00:00
|
|
|
Address: response.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,
|
2023-08-17 18:43:21 +00:00
|
|
|
LoadBalancingWeight: response.MakeUint32Value(1),
|
2019-03-22 19:37:14 +00:00
|
|
|
},
|
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{
|
2023-08-17 18:43:21 +00:00
|
|
|
Address: response.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,
|
2023-08-17 18:43:21 +00:00
|
|
|
LoadBalancingWeight: response.MakeUint32Value(1),
|
2019-03-22 19:37:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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{
|
2023-08-17 18:43:21 +00:00
|
|
|
Address: response.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,
|
2023-08-17 18:43:21 +00:00
|
|
|
LoadBalancingWeight: response.MakeUint32Value(10),
|
2019-03-22 19:37:14 +00:00
|
|
|
},
|
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{
|
2023-08-17 18:43:21 +00:00
|
|
|
Address: response.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,
|
2023-08-17 18:43:21 +00:00
|
|
|
LoadBalancingWeight: response.MakeUint32Value(5),
|
2019-03-22 19:37:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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{
|
2023-08-17 18:43:21 +00:00
|
|
|
Address: response.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,
|
2023-08-17 18:43:21 +00:00
|
|
|
LoadBalancingWeight: response.MakeUint32Value(1),
|
2019-03-22 19:37:14 +00:00
|
|
|
},
|
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{
|
2023-08-17 18:43:21 +00:00
|
|
|
Address: response.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,
|
2023-08-17 18:43:21 +00:00
|
|
|
LoadBalancingWeight: response.MakeUint32Value(1),
|
2019-03-22 19:37:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2019-07-24 01:20:24 +00:00
|
|
|
got := makeLoadAssignment(
|
2023-08-10 18:00:44 +00:00
|
|
|
hclog.NewNullLogger(),
|
2023-06-21 16:39:53 +00:00
|
|
|
&proxycfg.ConfigSnapshot{ServiceLocality: tt.locality},
|
2019-07-24 01:20:24 +00:00
|
|
|
tt.clusterName,
|
2023-06-21 16:39:53 +00:00
|
|
|
nil,
|
2019-07-24 01:20:24 +00:00
|
|
|
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)
|
2023-06-21 16:39:53 +00:00
|
|
|
|
|
|
|
if tt.locality == nil {
|
|
|
|
got := makeLoadAssignment(
|
2023-08-10 18:00:44 +00:00
|
|
|
hclog.NewNullLogger(),
|
2023-06-21 16:39:53 +00:00
|
|
|
&proxycfg.ConfigSnapshot{ServiceLocality: &structs.Locality{Region: "us-west-1", Zone: "us-west-1a"}},
|
|
|
|
tt.clusterName,
|
|
|
|
nil,
|
|
|
|
tt.endpoints,
|
|
|
|
proxycfg.GatewayKey{Datacenter: "dc1"},
|
|
|
|
)
|
|
|
|
require.Equal(t, tt.want, got)
|
|
|
|
}
|
2019-03-22 19:37:14 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2023-03-22 18:56:18 +00:00
|
|
|
type endpointTestCase struct {
|
|
|
|
name string
|
|
|
|
create func(t testinf.T) *proxycfg.ConfigSnapshot
|
|
|
|
overrideGoldenName string
|
2023-08-17 19:55:54 +00:00
|
|
|
alsoRunTestForV2 bool
|
2023-03-22 18:56:18 +00:00
|
|
|
}
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2023-03-22 18:56:18 +00:00
|
|
|
func TestEndpointsFromSnapshot(t *testing.T) {
|
|
|
|
// TODO: we should move all of these to TestAllResourcesFromSnapshot
|
|
|
|
// eventually to test all of the xDS types at once with the same input,
|
|
|
|
// just as it would be triggered by our xDS server.
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("too slow for testing.Short")
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []endpointTestCase{
|
2019-08-05 18:30:35 +00:00
|
|
|
{
|
2023-03-22 18:56:18 +00:00
|
|
|
name: "mesh-gateway",
|
2022-03-07 17:47:14 +00:00
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotMeshGateway(t, "default", nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): mesh gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2019-08-05 18:30:35 +00:00
|
|
|
},
|
|
|
|
{
|
2023-03-22 18:56:18 +00:00
|
|
|
name: "mesh-gateway-using-federation-states",
|
2022-03-07 17:47:14 +00:00
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotMeshGateway(t, "federation-states", nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): mesh gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2019-08-05 18:30:35 +00:00
|
|
|
},
|
|
|
|
{
|
2023-03-22 18:56:18 +00:00
|
|
|
name: "mesh-gateway-newer-information-in-federation-states",
|
2022-03-07 17:47:14 +00:00
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotMeshGateway(t, "newer-info-in-federation-states", nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): mesh gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2019-08-05 18:30:35 +00:00
|
|
|
},
|
2023-07-21 21:48:25 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-using-federation-control-plane",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotMeshGateway(t, "mesh-gateway-federation", nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): mesh gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2023-07-21 21:48:25 +00:00
|
|
|
},
|
2020-05-26 08:57:22 +00:00
|
|
|
{
|
2023-03-22 18:56:18 +00:00
|
|
|
name: "mesh-gateway-older-information-in-federation-states",
|
2022-03-07 17:47:14 +00:00
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotMeshGateway(t, "older-info-in-federation-states", nil, nil)
|
2020-02-19 16:57:55 +00:00
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): mesh gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-02-19 16:57:55 +00:00
|
|
|
},
|
2020-04-16 21:00:48 +00:00
|
|
|
{
|
2023-03-22 18:56:18 +00:00
|
|
|
name: "mesh-gateway-no-services",
|
2022-03-07 17:47:14 +00:00
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotMeshGateway(t, "no-services", nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): mesh gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-16 21:00:48 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "mesh-gateway-service-subsets",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotMeshGateway(t, "service-subsets2", nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): mesh gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-16 21:00:48 +00:00
|
|
|
},
|
2020-04-14 21:30:00 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "mesh-gateway-default-service-subset",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotMeshGateway(t, "default-service-subsets2", nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): mesh gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-gateway",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"default", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
2022-10-25 17:55:44 +00:00
|
|
|
{
|
|
|
|
name: "ingress-gateway-nil-config-entry",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway_NilConfigEntry(t)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2022-10-25 17:55:44 +00:00
|
|
|
},
|
2020-04-14 21:30:00 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-gateway-no-services",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, false, "tcp",
|
|
|
|
"default", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-chain",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"simple", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-chain-external-sni",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"external-sni", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-chain-and-failover",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
2022-08-30 15:46:34 +00:00
|
|
|
{
|
|
|
|
name: "ingress-with-chain-and-failover-to-cluster-peer",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover-to-cluster-peer", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2022-08-30 15:46:34 +00:00
|
|
|
},
|
2020-04-14 21:30:00 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-tcp-chain-failover-through-remote-gateway",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover-through-remote-gateway", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-tcp-chain-failover-through-remote-gateway-triggered",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover-through-remote-gateway-triggered", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-tcp-chain-double-failover-through-remote-gateway",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover-through-double-remote-gateway", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-tcp-chain-double-failover-through-remote-gateway-triggered",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover-through-double-remote-gateway-triggered", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-tcp-chain-failover-through-local-gateway",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover-through-local-gateway", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-tcp-chain-failover-through-local-gateway-triggered",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover-through-local-gateway-triggered", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-tcp-chain-double-failover-through-local-gateway",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover-through-double-local-gateway", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
2020-04-13 16:33:01 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-tcp-chain-double-failover-through-local-gateway-triggered",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "tcp",
|
|
|
|
"failover-through-double-local-gateway-triggered", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-13 16:33:01 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-splitter-with-resolver-redirect",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "http",
|
|
|
|
"splitter-with-resolver-redirect-multidc", nil, nil, nil)
|
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-13 16:33:01 +00:00
|
|
|
},
|
2020-04-14 14:59:23 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "terminating-gateway",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotTerminatingGateway(t, true, nil, nil)
|
2020-04-14 14:59:23 +00:00
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): terminating gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 14:59:23 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "terminating-gateway-no-services",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotTerminatingGateway(t, false, nil, nil)
|
2020-04-14 14:59:23 +00:00
|
|
|
},
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): terminating gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-14 14:59:23 +00:00
|
|
|
},
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
name: "terminating-gateway-service-subsets",
|
|
|
|
create: proxycfg.TestConfigSnapshotTerminatingGatewayServiceSubsets,
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): terminating gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "terminating-gateway-default-service-subset",
|
|
|
|
create: proxycfg.TestConfigSnapshotTerminatingGatewayDefaultServiceSubset,
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): terminating gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2020-04-21 21:06:23 +00:00
|
|
|
{
|
|
|
|
name: "ingress-multiple-listeners-duplicate-service",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngress_MultipleListenersDuplicateService,
|
2023-08-17 19:55:54 +00:00
|
|
|
// TODO(proxystate): ingress gateway will come at a later time
|
|
|
|
alsoRunTestForV2: false,
|
2020-04-21 21:06:23 +00:00
|
|
|
},
|
2019-06-18 00:52:01 +00:00
|
|
|
}
|
|
|
|
|
2023-02-06 17:14:35 +00:00
|
|
|
latestEnvoyVersion := xdscommon.EnvoyVersions[0]
|
|
|
|
for _, envoyVersion := range xdscommon.EnvoyVersions {
|
2023-02-03 06:18:10 +00:00
|
|
|
sf, err := xdscommon.DetermineSupportedProxyFeaturesFromString(envoyVersion)
|
2020-07-31 20:52:49 +00:00
|
|
|
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!
|
2023-02-03 06:18:10 +00:00
|
|
|
testcommon.SetupTLSRootsAndLeaf(t, snap)
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2020-07-09 22:04:51 +00:00
|
|
|
// Need server just for logger dependency
|
2023-02-03 06:18:10 +00:00
|
|
|
g := NewResourceGenerator(testutil.Logger(t), nil, false)
|
2021-04-29 18:54:05 +00:00
|
|
|
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
|
|
|
})
|
2023-08-17 18:43:21 +00:00
|
|
|
r, err := response.CreateResponse(xdscommon.EndpointType, "00000001", "00000001", endpoints)
|
2021-02-26 22:23:15 +00:00
|
|
|
require.NoError(t, err)
|
2019-06-18 00:52:01 +00:00
|
|
|
|
2023-08-17 19:55:54 +00:00
|
|
|
t.Run("current-xdsv1", func(t *testing.T) {
|
2021-02-26 22:23:15 +00:00
|
|
|
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)
|
|
|
|
})
|
2023-08-17 19:55:54 +00:00
|
|
|
|
|
|
|
if tt.alsoRunTestForV2 {
|
|
|
|
generator := xdsv2.NewResourceGenerator(testutil.Logger(t))
|
|
|
|
|
|
|
|
converter := proxystateconverter.NewConverter(testutil.Logger(t), &mockCfgFetcher{addressLan: "10.10.10.10"})
|
|
|
|
proxyState, err := converter.ProxyStateFromSnapshot(snap)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
res, err := generator.AllResourcesFromIR(proxyState)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
endpoints = res[xdscommon.EndpointType]
|
|
|
|
// The order of listeners returned via LDS isn't relevant, so it's safe
|
|
|
|
// to sort these for the purposes of test comparisons.
|
|
|
|
sort.Slice(endpoints, func(i, j int) bool {
|
|
|
|
return endpoints[i].(*envoy_endpoint_v3.ClusterLoadAssignment).ClusterName < endpoints[j].(*envoy_endpoint_v3.ClusterLoadAssignment).ClusterName
|
|
|
|
})
|
|
|
|
|
|
|
|
r, err := response.CreateResponse(xdscommon.EndpointType, "00000001", "00000001", endpoints)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("current-xdsv2", func(t *testing.T) {
|
|
|
|
gotJSON := protoToJSON(t, r)
|
|
|
|
|
|
|
|
gName := tt.name
|
|
|
|
if tt.overrideGoldenName != "" {
|
|
|
|
gName = tt.overrideGoldenName
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedJSON := goldenEnvoy(t, filepath.Join("endpoints", gName), envoyVersion, latestEnvoyVersion, gotJSON)
|
|
|
|
require.JSONEq(t, expectedJSON, gotJSON)
|
|
|
|
})
|
|
|
|
}
|
2020-07-09 22:04:51 +00:00
|
|
|
})
|
|
|
|
}
|
2019-06-18 00:52:01 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|