mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Support disabling TCP checks for connect sidecar services
This commit is contained in:
@@ -105,22 +105,27 @@ func connectSidecarRegistration(serviceId string, css *structs.ConsulSidecarServ
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// if the service has a TCP check that's failing, we need an alias to
|
||||
// ensure service discovery excludes this sidecar from queries
|
||||
// (ex. in the case of Connect upstreams)
|
||||
checks := api.AgentServiceChecks{{
|
||||
Name: "Connect Sidecar Aliasing " + serviceId,
|
||||
AliasService: serviceId,
|
||||
}}
|
||||
if !css.DisableDefaultTCPCheck {
|
||||
checks = append(checks, &api.AgentServiceCheck{
|
||||
Name: "Connect Sidecar Listening",
|
||||
TCP: net.JoinHostPort(cMapping.HostIP, strconv.Itoa(cMapping.Value)),
|
||||
Interval: "10s",
|
||||
})
|
||||
}
|
||||
|
||||
return &api.AgentServiceRegistration{
|
||||
Tags: helper.CopySliceString(css.Tags),
|
||||
Port: cMapping.Value,
|
||||
Address: cMapping.HostIP,
|
||||
Proxy: proxy,
|
||||
Checks: api.AgentServiceChecks{
|
||||
{
|
||||
Name: "Connect Sidecar Listening",
|
||||
TCP: net.JoinHostPort(cMapping.HostIP, strconv.Itoa(cMapping.Value)),
|
||||
Interval: "10s",
|
||||
},
|
||||
{
|
||||
Name: "Connect Sidecar Aliasing " + serviceId,
|
||||
AliasService: serviceId,
|
||||
},
|
||||
},
|
||||
Checks: checks,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -67,11 +67,40 @@ func TestConnect_newConnect(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Checks: api.AgentServiceChecks{
|
||||
{
|
||||
Name: "Connect Sidecar Aliasing redis-service-id",
|
||||
AliasService: "redis-service-id",
|
||||
},
|
||||
{
|
||||
Name: "Connect Sidecar Listening",
|
||||
TCP: "192.168.30.1:3000",
|
||||
Interval: "10s",
|
||||
},
|
||||
},
|
||||
}, asr.SidecarService)
|
||||
})
|
||||
|
||||
t.Run("with sidecar without TCP checks", func(t *testing.T) {
|
||||
asr, err := newConnect("redis-service-id", "redis", &structs.ConsulConnect{
|
||||
Native: false,
|
||||
SidecarService: &structs.ConsulSidecarService{
|
||||
Tags: []string{"foo", "bar"},
|
||||
Port: "connect-proxy-redis",
|
||||
DisableDefaultTCPCheck: true,
|
||||
},
|
||||
}, testConnectNetwork, testConnectPorts)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, &api.AgentServiceRegistration{
|
||||
Tags: []string{"foo", "bar"},
|
||||
Port: 3000,
|
||||
Address: "192.168.30.1",
|
||||
Proxy: &api.AgentServiceConnectProxyConfig{
|
||||
Config: map[string]interface{}{
|
||||
"bind_address": "0.0.0.0",
|
||||
"bind_port": 3000,
|
||||
},
|
||||
},
|
||||
Checks: api.AgentServiceChecks{
|
||||
{
|
||||
Name: "Connect Sidecar Aliasing redis-service-id",
|
||||
AliasService: "redis-service-id",
|
||||
@@ -128,15 +157,15 @@ func TestConnect_connectSidecarRegistration(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Checks: api.AgentServiceChecks{
|
||||
{
|
||||
Name: "Connect Sidecar Aliasing redis-service-id",
|
||||
AliasService: "redis-service-id",
|
||||
},
|
||||
{
|
||||
Name: "Connect Sidecar Listening",
|
||||
TCP: "192.168.30.1:3000",
|
||||
Interval: "10s",
|
||||
},
|
||||
{
|
||||
Name: "Connect Sidecar Aliasing redis-service-id",
|
||||
AliasService: "redis-service-id",
|
||||
},
|
||||
},
|
||||
}, proxy)
|
||||
})
|
||||
|
||||
@@ -1499,9 +1499,10 @@ func apiConnectSidecarServiceToStructs(in *api.ConsulSidecarService) *structs.Co
|
||||
return nil
|
||||
}
|
||||
return &structs.ConsulSidecarService{
|
||||
Port: in.Port,
|
||||
Tags: helper.CopySliceString(in.Tags),
|
||||
Proxy: apiConnectSidecarServiceProxyToStructs(in.Proxy),
|
||||
Port: in.Port,
|
||||
Tags: helper.CopySliceString(in.Tags),
|
||||
Proxy: apiConnectSidecarServiceProxyToStructs(in.Proxy),
|
||||
DisableDefaultTCPCheck: in.DisableDefaultTCPCheck,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2035,8 +2035,9 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
|
||||
Connect: &api.ConsulConnect{
|
||||
Native: false,
|
||||
SidecarService: &api.ConsulSidecarService{
|
||||
Tags: []string{"f", "g"},
|
||||
Port: "9000",
|
||||
Tags: []string{"f", "g"},
|
||||
Port: "9000",
|
||||
DisableDefaultTCPCheck: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2414,8 +2415,9 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
|
||||
Connect: &structs.ConsulConnect{
|
||||
Native: false,
|
||||
SidecarService: &structs.ConsulSidecarService{
|
||||
Tags: []string{"f", "g"},
|
||||
Port: "9000",
|
||||
Tags: []string{"f", "g"},
|
||||
Port: "9000",
|
||||
DisableDefaultTCPCheck: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user