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-07-12 19:16:21 +00:00
|
|
|
package xds
|
|
|
|
|
|
|
|
import (
|
2020-07-09 22:04:51 +00:00
|
|
|
"path/filepath"
|
2019-07-12 19:16:21 +00:00
|
|
|
"sort"
|
|
|
|
"testing"
|
2020-04-16 23:24:11 +00:00
|
|
|
"time"
|
2019-07-12 19:16:21 +00:00
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
envoy_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
|
2020-12-23 17:50:28 +00:00
|
|
|
testinf "github.com/mitchellh/go-testing-interface"
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-06-15 19:58:28 +00:00
|
|
|
"google.golang.org/protobuf/types/known/durationpb"
|
2020-12-23 17:50:28 +00:00
|
|
|
|
2019-07-12 19:16:21 +00:00
|
|
|
"github.com/hashicorp/consul/agent/proxycfg"
|
2020-04-16 23:24:11 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2023-08-03 19:03:02 +00:00
|
|
|
"github.com/hashicorp/consul/agent/xds/testcommon"
|
2023-02-06 17:14:35 +00:00
|
|
|
"github.com/hashicorp/consul/envoyextensions/xdscommon"
|
2020-09-03 22:19:58 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
2019-07-12 19:16:21 +00:00
|
|
|
)
|
|
|
|
|
2023-03-22 18:56:18 +00:00
|
|
|
type routeTestCase struct {
|
|
|
|
name string
|
|
|
|
create func(t testinf.T) *proxycfg.ConfigSnapshot
|
|
|
|
overrideGoldenName string
|
|
|
|
}
|
2019-07-12 19:16:21 +00:00
|
|
|
|
2023-03-22 18:56:18 +00:00
|
|
|
func makeRouteDiscoChainTests(enterprise bool) []routeTestCase {
|
|
|
|
return []routeTestCase{
|
2019-07-12 19:16:21 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "connect-proxy-with-chain",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "simple", enterprise, nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
},
|
2019-08-19 17:19:44 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "connect-proxy-with-chain-external-sni",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "external-sni", enterprise, nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2019-08-19 17:19:44 +00:00
|
|
|
},
|
2023-08-03 19:03:02 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-splitter-overweight",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "splitter-overweight", enterprise, nil, nil)
|
|
|
|
},
|
|
|
|
},
|
2019-08-02 03:03:34 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "connect-proxy-with-chain-and-overrides",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "simple-with-overrides", enterprise, nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2019-08-02 03:03:34 +00:00
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "splitter-with-resolver-redirect",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "splitter-with-resolver-redirect-multidc", enterprise, nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "connect-proxy-with-chain-and-splitter",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "chain-and-splitter", enterprise, nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
},
|
2019-07-17 19:07:08 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "connect-proxy-with-grpc-router",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "grpc-router", enterprise, nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2019-07-17 19:07:08 +00:00
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "connect-proxy-with-chain-and-router",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "chain-and-router", enterprise, nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
},
|
2020-08-28 20:27:40 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "connect-proxy-lb-in-resolver",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "lb-resolver", enterprise, nil, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2020-08-28 20:27:40 +00:00
|
|
|
},
|
2023-08-03 19:03:02 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-route-to-lb-resolver",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "redirect-to-lb-node", enterprise, nil, nil)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-resolver-with-lb",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "resolver-with-lb", enterprise, nil, nil)
|
|
|
|
},
|
|
|
|
},
|
2023-03-22 18:56:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRoutesFromSnapshot(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 := []routeTestCase{
|
2019-07-12 19:16:21 +00:00
|
|
|
// TODO(rb): test match stanza skipped for grpc
|
2020-04-14 21:30:00 +00:00
|
|
|
// Start ingress gateway test cases
|
2022-10-25 17:55:44 +00:00
|
|
|
{
|
|
|
|
name: "ingress-config-entry-nil",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway_NilConfigEntry(t)
|
|
|
|
},
|
|
|
|
},
|
2020-04-14 21:30:00 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-defaults-no-chain",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, false, "tcp",
|
|
|
|
"default", nil, nil, nil)
|
|
|
|
},
|
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)
|
|
|
|
},
|
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)
|
|
|
|
},
|
2020-04-14 21:30:00 +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)
|
|
|
|
},
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-chain-and-splitter",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "http",
|
|
|
|
"chain-and-splitter", nil, nil, nil)
|
|
|
|
},
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-grpc-router",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "http",
|
|
|
|
"grpc-router", nil, nil, nil)
|
|
|
|
},
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-chain-and-router",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "http",
|
|
|
|
"chain-and-router", nil, nil, nil)
|
|
|
|
},
|
2020-04-14 21:30:00 +00:00
|
|
|
},
|
2020-08-28 20:27:40 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-lb-in-resolver",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGateway(t, true, "http",
|
|
|
|
"lb-resolver", nil, nil, nil)
|
|
|
|
},
|
2020-08-28 20:27:40 +00:00
|
|
|
},
|
2020-04-16 23:24:11 +00:00
|
|
|
{
|
|
|
|
name: "ingress-http-multiple-services",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngress_HTTPMultipleServices,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2022-05-18 21:55:59 +00:00
|
|
|
{
|
|
|
|
name: "ingress-grpc-multiple-services",
|
|
|
|
create: proxycfg.TestConfigSnapshotIngress_GRPCMultipleServices,
|
|
|
|
},
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
name: "ingress-with-chain-and-router-header-manip",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGatewayWithChain(t, "router-header-manip", nil, nil)
|
2021-07-13 12:53:59 +00:00
|
|
|
},
|
|
|
|
},
|
2021-08-24 14:25:22 +00:00
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-sds-listener-level",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGatewayWithChain(t, "sds-listener-level", nil, nil)
|
|
|
|
},
|
2021-08-24 14:25:22 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-sds-listener-level-wildcard",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGatewayWithChain(t, "sds-listener-level-wildcard", nil, nil)
|
|
|
|
},
|
2021-08-24 14:25:22 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-sds-service-level",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGatewayWithChain(t, "sds-service-level", nil, nil)
|
|
|
|
},
|
2021-08-24 14:25:22 +00:00
|
|
|
},
|
|
|
|
{
|
2022-03-07 17:47:14 +00:00
|
|
|
name: "ingress-with-sds-service-level-mixed-tls",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotIngressGatewayWithChain(t, "sds-service-level-mixed-tls", nil, nil)
|
|
|
|
},
|
2021-08-24 14:25:22 +00:00
|
|
|
},
|
2020-08-28 20:27:40 +00:00
|
|
|
{
|
|
|
|
name: "terminating-gateway-lb-config",
|
2022-03-07 17:47:14 +00:00
|
|
|
create: proxycfg.TestConfigSnapshotTerminatingGatewayLBConfig,
|
2020-08-28 20:27:40 +00:00
|
|
|
},
|
2019-07-12 19:16:21 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 18:56:18 +00:00
|
|
|
tests = append(tests, makeRouteDiscoChainTests(false)...)
|
|
|
|
|
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-07-12 19:16:21 +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-07-12 19:16:21 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
routes, err := g.routesFromSnapshot(snap)
|
2021-02-26 22:23:15 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-07-09 22:04:51 +00:00
|
|
|
sort.Slice(routes, func(i, j int) bool {
|
2021-02-26 22:23:15 +00:00
|
|
|
return routes[i].(*envoy_route_v3.RouteConfiguration).Name < routes[j].(*envoy_route_v3.RouteConfiguration).Name
|
2020-07-09 22:04:51 +00:00
|
|
|
})
|
2022-03-08 19:37:24 +00:00
|
|
|
r, err := createResponse(xdscommon.RouteType, "00000001", "00000001", routes)
|
2021-02-26 22:23:15 +00:00
|
|
|
require.NoError(t, err)
|
2019-07-12 19:16:21 +00:00
|
|
|
|
2021-02-26 22:23:15 +00:00
|
|
|
t.Run("current", func(t *testing.T) {
|
|
|
|
gotJSON := protoToJSON(t, r)
|
2019-07-12 19:16:21 +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("routes", gName), envoyVersion, latestEnvoyVersion, gotJSON), gotJSON)
|
|
|
|
})
|
2020-07-09 22:04:51 +00:00
|
|
|
})
|
|
|
|
}
|
2019-07-12 19:16:21 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 21:13:50 +00:00
|
|
|
|
|
|
|
func TestEnvoyLBConfig_InjectToRouteAction(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_route_v3.RouteAction
|
2020-09-02 21:13:50 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: "",
|
|
|
|
},
|
|
|
|
// we only modify route actions for hash-based LB policies
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_route_v3.RouteAction{},
|
2020-09-02 21:13:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "least request",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: structs.LBPolicyLeastRequest,
|
|
|
|
LeastRequestConfig: &structs.LeastRequestConfig{
|
|
|
|
ChoiceCount: 3,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// we only modify route actions for hash-based LB policies
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_route_v3.RouteAction{},
|
2020-09-02 21:13:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "headers",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: "ring_hash",
|
|
|
|
RingHashConfig: &structs.RingHashConfig{
|
|
|
|
MinimumRingSize: 3,
|
|
|
|
MaximumRingSize: 7,
|
|
|
|
},
|
|
|
|
HashPolicies: []structs.HashPolicy{
|
|
|
|
{
|
|
|
|
Field: structs.HashPolicyHeader,
|
|
|
|
FieldValue: "x-route-key",
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_route_v3.RouteAction{
|
|
|
|
HashPolicy: []*envoy_route_v3.RouteAction_HashPolicy{
|
2020-09-02 21:13:50 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Header_{
|
|
|
|
Header: &envoy_route_v3.RouteAction_HashPolicy_Header{
|
2020-09-02 21:13:50 +00:00
|
|
|
HeaderName: "x-route-key",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "cookies",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: structs.LBPolicyMaglev,
|
|
|
|
HashPolicies: []structs.HashPolicy{
|
|
|
|
{
|
|
|
|
Field: structs.HashPolicyCookie,
|
|
|
|
FieldValue: "red-velvet",
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Field: structs.HashPolicyCookie,
|
|
|
|
FieldValue: "oatmeal",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_route_v3.RouteAction{
|
|
|
|
HashPolicy: []*envoy_route_v3.RouteAction_HashPolicy{
|
2020-09-02 21:13:50 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Cookie_{
|
|
|
|
Cookie: &envoy_route_v3.RouteAction_HashPolicy_Cookie{
|
2020-09-02 21:13:50 +00:00
|
|
|
Name: "red-velvet",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Cookie_{
|
|
|
|
Cookie: &envoy_route_v3.RouteAction_HashPolicy_Cookie{
|
2020-09-02 21:13:50 +00:00
|
|
|
Name: "oatmeal",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-12 00:34:03 +00:00
|
|
|
{
|
|
|
|
name: "non-zero session ttl gets zeroed out",
|
|
|
|
lb: &structs.LoadBalancer{
|
|
|
|
Policy: structs.LBPolicyMaglev,
|
|
|
|
HashPolicies: []structs.HashPolicy{
|
|
|
|
{
|
|
|
|
Field: structs.HashPolicyCookie,
|
|
|
|
FieldValue: "oatmeal",
|
|
|
|
CookieConfig: &structs.CookieConfig{
|
|
|
|
TTL: 10 * time.Second,
|
|
|
|
Session: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_route_v3.RouteAction{
|
|
|
|
HashPolicy: []*envoy_route_v3.RouteAction_HashPolicy{
|
2020-09-12 00:34:03 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Cookie_{
|
|
|
|
Cookie: &envoy_route_v3.RouteAction_HashPolicy_Cookie{
|
2020-09-12 00:34:03 +00:00
|
|
|
Name: "oatmeal",
|
2022-05-25 01:44:54 +00:00
|
|
|
Ttl: durationpb.New(0 * time.Second),
|
2020-09-12 00:34:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "zero value ttl omitted if not session cookie",
|
|
|
|
lb: &structs.LoadBalancer{
|
|
|
|
Policy: structs.LBPolicyMaglev,
|
|
|
|
HashPolicies: []structs.HashPolicy{
|
|
|
|
{
|
|
|
|
Field: structs.HashPolicyCookie,
|
|
|
|
FieldValue: "oatmeal",
|
|
|
|
CookieConfig: &structs.CookieConfig{
|
|
|
|
Path: "/oven",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_route_v3.RouteAction{
|
|
|
|
HashPolicy: []*envoy_route_v3.RouteAction_HashPolicy{
|
2020-09-12 00:34:03 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Cookie_{
|
|
|
|
Cookie: &envoy_route_v3.RouteAction_HashPolicy_Cookie{
|
2020-09-12 00:34:03 +00:00
|
|
|
Name: "oatmeal",
|
|
|
|
Path: "/oven",
|
|
|
|
Ttl: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-02 21:13:50 +00:00
|
|
|
{
|
|
|
|
name: "source addr",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: structs.LBPolicyMaglev,
|
|
|
|
HashPolicies: []structs.HashPolicy{
|
|
|
|
{
|
|
|
|
SourceIP: true,
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_route_v3.RouteAction{
|
|
|
|
HashPolicy: []*envoy_route_v3.RouteAction_HashPolicy{
|
2020-09-02 21:13:50 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_ConnectionProperties_{
|
|
|
|
ConnectionProperties: &envoy_route_v3.RouteAction_HashPolicy_ConnectionProperties{
|
2020-09-02 21:13:50 +00:00
|
|
|
SourceIp: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "kitchen sink",
|
2020-09-11 15:21:43 +00:00
|
|
|
lb: &structs.LoadBalancer{
|
2020-09-02 21:13:50 +00:00
|
|
|
Policy: structs.LBPolicyMaglev,
|
|
|
|
HashPolicies: []structs.HashPolicy{
|
|
|
|
{
|
|
|
|
SourceIP: true,
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Field: structs.HashPolicyCookie,
|
|
|
|
FieldValue: "oatmeal",
|
|
|
|
CookieConfig: &structs.CookieConfig{
|
|
|
|
TTL: 10 * time.Second,
|
|
|
|
Path: "/oven",
|
|
|
|
},
|
|
|
|
},
|
2020-09-12 00:34:03 +00:00
|
|
|
{
|
|
|
|
Field: structs.HashPolicyCookie,
|
|
|
|
FieldValue: "chocolate-chip",
|
|
|
|
CookieConfig: &structs.CookieConfig{
|
|
|
|
Session: true,
|
|
|
|
Path: "/oven",
|
|
|
|
},
|
|
|
|
},
|
2020-09-02 21:13:50 +00:00
|
|
|
{
|
|
|
|
Field: structs.HashPolicyHeader,
|
|
|
|
FieldValue: "special-header",
|
|
|
|
Terminal: true,
|
|
|
|
},
|
2023-08-03 19:03:02 +00:00
|
|
|
{
|
|
|
|
Field: structs.HashPolicyQueryParam,
|
|
|
|
FieldValue: "my-pretty-param",
|
|
|
|
Terminal: true,
|
|
|
|
},
|
2020-09-02 21:13:50 +00:00
|
|
|
},
|
|
|
|
},
|
2021-02-26 22:23:15 +00:00
|
|
|
expected: &envoy_route_v3.RouteAction{
|
|
|
|
HashPolicy: []*envoy_route_v3.RouteAction_HashPolicy{
|
2020-09-02 21:13:50 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_ConnectionProperties_{
|
|
|
|
ConnectionProperties: &envoy_route_v3.RouteAction_HashPolicy_ConnectionProperties{
|
2020-09-02 21:13:50 +00:00
|
|
|
SourceIp: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Cookie_{
|
|
|
|
Cookie: &envoy_route_v3.RouteAction_HashPolicy_Cookie{
|
2020-09-02 21:13:50 +00:00
|
|
|
Name: "oatmeal",
|
2022-05-25 01:44:54 +00:00
|
|
|
Ttl: durationpb.New(10 * time.Second),
|
2020-09-02 21:13:50 +00:00
|
|
|
Path: "/oven",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-12 00:34:03 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Cookie_{
|
|
|
|
Cookie: &envoy_route_v3.RouteAction_HashPolicy_Cookie{
|
2020-09-12 00:34:03 +00:00
|
|
|
Name: "chocolate-chip",
|
2022-05-25 01:44:54 +00:00
|
|
|
Ttl: durationpb.New(0 * time.Second),
|
2020-09-12 00:34:03 +00:00
|
|
|
Path: "/oven",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-02 21:13:50 +00:00
|
|
|
{
|
2021-02-26 22:23:15 +00:00
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Header_{
|
|
|
|
Header: &envoy_route_v3.RouteAction_HashPolicy_Header{
|
2020-09-02 21:13:50 +00:00
|
|
|
HeaderName: "special-header",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Terminal: true,
|
|
|
|
},
|
2023-08-03 19:03:02 +00:00
|
|
|
{
|
|
|
|
PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_QueryParameter_{
|
|
|
|
QueryParameter: &envoy_route_v3.RouteAction_HashPolicy_QueryParameter{
|
|
|
|
Name: "my-pretty-param",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Terminal: true,
|
|
|
|
},
|
2020-09-02 21:13:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2021-02-26 22:23:15 +00:00
|
|
|
var ra envoy_route_v3.RouteAction
|
2020-09-02 21:13:50 +00:00
|
|
|
err := injectLBToRouteAction(tc.lb, &ra)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-02-22 21:00:15 +00:00
|
|
|
require.Equal(t, tc.expected, &ra)
|
2020-09-02 21:13:50 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|