|
|
|
@ -2567,30 +2567,6 @@ func TestAgent_reloadWatchesHTTPS(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
a := NewTestAgent(t.Name(), `
|
|
|
|
|
node_name = "node1"
|
|
|
|
|
|
|
|
|
|
connect {
|
|
|
|
|
proxy_defaults {
|
|
|
|
|
exec_mode = "script"
|
|
|
|
|
daemon_command = ["foo", "bar"]
|
|
|
|
|
script_command = ["bar", "foo"]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ports {
|
|
|
|
|
proxy_min_port = 20000
|
|
|
|
|
proxy_max_port = 20000
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
defer a.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Register a target service we can use
|
|
|
|
|
reg := &structs.NodeService{
|
|
|
|
|
Service: "web",
|
|
|
|
|
Port: 8080,
|
|
|
|
|
}
|
|
|
|
|
require.NoError(t, a.AddService(reg, nil, false, ""))
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
desc string
|
|
|
|
@ -2621,6 +2597,9 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
},
|
|
|
|
|
// Proxy will inherit agent's 0.0.0.0 bind address but we can't check that
|
|
|
|
|
// so we should default to localhost in that case.
|
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
@ -2634,6 +2613,7 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
Command: []string{"consul", "connect", "proxy"},
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
},
|
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
@ -2647,6 +2627,7 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
Command: []string{"foo", "bar"},
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
},
|
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
@ -2660,6 +2641,7 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
Command: []string{"bar", "foo"},
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
},
|
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
@ -2677,7 +2659,6 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
wantTCPCheck: "127.10.10.10:1234",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// This test is necessary since JSON and HCL both will parse
|
|
|
|
|
// numbers as a float64.
|
|
|
|
@ -2695,12 +2676,83 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
wantTCPCheck: "127.10.10.10:1234",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
desc: "managed proxy with overridden but unspecified ipv6 bind address",
|
|
|
|
|
proxy: &structs.ConnectManagedProxy{
|
|
|
|
|
ExecMode: structs.ProxyExecModeDaemon,
|
|
|
|
|
Command: []string{"consul", "connect", "proxy"},
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
"bind_address": "[::]",
|
|
|
|
|
},
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
},
|
|
|
|
|
wantTCPCheck: "127.0.0.1:20000",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
desc: "managed proxy with overridden check address",
|
|
|
|
|
proxy: &structs.ConnectManagedProxy{
|
|
|
|
|
ExecMode: structs.ProxyExecModeDaemon,
|
|
|
|
|
Command: []string{"consul", "connect", "proxy"},
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
"tcp_check_address": "127.20.20.20",
|
|
|
|
|
},
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
},
|
|
|
|
|
wantTCPCheck: "127.20.20.20:20000",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
desc: "managed proxy with disabled check",
|
|
|
|
|
proxy: &structs.ConnectManagedProxy{
|
|
|
|
|
ExecMode: structs.ProxyExecModeDaemon,
|
|
|
|
|
Command: []string{"consul", "connect", "proxy"},
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
"disable_tcp_check": true,
|
|
|
|
|
},
|
|
|
|
|
TargetServiceID: "web",
|
|
|
|
|
},
|
|
|
|
|
wantTCPCheck: "",
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.desc, func(t *testing.T) {
|
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
|
|
a := NewTestAgent(t.Name(), `
|
|
|
|
|
node_name = "node1"
|
|
|
|
|
|
|
|
|
|
# Explicit test because proxies inheriting this value must have a health
|
|
|
|
|
# check on a different IP.
|
|
|
|
|
bind_addr = "0.0.0.0"
|
|
|
|
|
|
|
|
|
|
connect {
|
|
|
|
|
proxy_defaults {
|
|
|
|
|
exec_mode = "script"
|
|
|
|
|
daemon_command = ["foo", "bar"]
|
|
|
|
|
script_command = ["bar", "foo"]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ports {
|
|
|
|
|
proxy_min_port = 20000
|
|
|
|
|
proxy_max_port = 20000
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
defer a.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Register a target service we can use
|
|
|
|
|
reg := &structs.NodeService{
|
|
|
|
|
Service: "web",
|
|
|
|
|
Port: 8080,
|
|
|
|
|
}
|
|
|
|
|
require.NoError(a.AddService(reg, nil, false, ""))
|
|
|
|
|
|
|
|
|
|
err := a.AddProxy(tt.proxy, false, "")
|
|
|
|
|
if tt.wantErr {
|
|
|
|
|
require.Error(err)
|
|
|
|
@ -2719,6 +2771,9 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Ensure a TCP check was created for the service.
|
|
|
|
|
gotCheck := a.State.Check("service:web-proxy")
|
|
|
|
|
if tt.wantTCPCheck == "" {
|
|
|
|
|
require.Nil(gotCheck)
|
|
|
|
|
} else {
|
|
|
|
|
require.NotNil(gotCheck)
|
|
|
|
|
require.Equal("Connect Proxy Listening", gotCheck.Name)
|
|
|
|
|
|
|
|
|
@ -2730,12 +2785,9 @@ func TestAgent_AddProxy(t *testing.T) {
|
|
|
|
|
// We'll do the same for now.
|
|
|
|
|
gotTCP, ok := a.checkTCPs["service:web-proxy"]
|
|
|
|
|
require.True(ok)
|
|
|
|
|
wantTCPCheck := tt.wantTCPCheck
|
|
|
|
|
if wantTCPCheck == "" {
|
|
|
|
|
wantTCPCheck = "127.0.0.1:20000"
|
|
|
|
|
}
|
|
|
|
|
require.Equal(wantTCPCheck, gotTCP.TCP)
|
|
|
|
|
require.Equal(tt.wantTCPCheck, gotTCP.TCP)
|
|
|
|
|
require.Equal(10*time.Second, gotTCP.Interval)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|