Optional Consul service tags for nomad server and agent services (#5706)

Optional Consul service tags for nomad server and agent services
This commit is contained in:
Nick Ethier
2019-06-13 09:00:35 -04:00
committed by GitHub
3 changed files with 12 additions and 5 deletions

View File

@@ -577,7 +577,7 @@ func (a *Agent) setupServer() error {
httpServ := &structs.Service{
Name: a.config.Consul.ServerServiceName,
PortLabel: a.config.AdvertiseAddrs.HTTP,
Tags: []string{consul.ServiceTagHTTP},
Tags: append([]string{consul.ServiceTagHTTP}, a.config.Consul.Tags...),
}
const isServer = true
if check := a.agentHTTPCheck(isServer); check != nil {
@@ -586,7 +586,7 @@ func (a *Agent) setupServer() error {
rpcServ := &structs.Service{
Name: a.config.Consul.ServerServiceName,
PortLabel: a.config.AdvertiseAddrs.RPC,
Tags: []string{consul.ServiceTagRPC},
Tags: append([]string{consul.ServiceTagRPC}, a.config.Consul.Tags...),
Checks: []*structs.ServiceCheck{
{
Name: a.config.Consul.ServerRPCCheckName,
@@ -600,7 +600,7 @@ func (a *Agent) setupServer() error {
serfServ := &structs.Service{
Name: a.config.Consul.ServerServiceName,
PortLabel: a.config.AdvertiseAddrs.Serf,
Tags: []string{consul.ServiceTagSerf},
Tags: append([]string{consul.ServiceTagSerf}, a.config.Consul.Tags...),
Checks: []*structs.ServiceCheck{
{
Name: a.config.Consul.ServerSerfCheckName,
@@ -742,7 +742,7 @@ func (a *Agent) setupClient() error {
httpServ := &structs.Service{
Name: a.config.Consul.ClientServiceName,
PortLabel: a.config.AdvertiseAddrs.HTTP,
Tags: []string{consul.ServiceTagHTTP},
Tags: append([]string{consul.ServiceTagHTTP}, a.config.Consul.Tags...),
}
const isServer = false
if check := a.agentHTTPCheck(isServer); check != nil {

View File

@@ -43,6 +43,10 @@ type ConsulConfig struct {
// to register the client HTTP health check with Consul
ClientHTTPCheckName string `hcl:"client_http_check_name"`
// Tags are optional service tags that get registered with the service
// in Consul
Tags []string `hcl:"tags"`
// AutoAdvertise determines if this Nomad Agent will advertise its
// services via Consul. When true, Nomad Agent will register
// services with Consul.
@@ -136,6 +140,7 @@ func (a *ConsulConfig) Merge(b *ConsulConfig) *ConsulConfig {
if b.ClientHTTPCheckName != "" {
result.ClientHTTPCheckName = b.ClientHTTPCheckName
}
result.Tags = append(result.Tags, b.Tags...)
if b.AutoAdvertise != nil {
result.AutoAdvertise = helper.BoolToPtr(*b.AutoAdvertise)
}
@@ -233,7 +238,6 @@ func (c *ConsulConfig) ApiConfig() (*consul.Config, error) {
}
config.Transport.TLSClientConfig = tlsConfig
}
return config, nil
}

View File

@@ -108,6 +108,9 @@ configuring Nomad to talk to Consul via DNS such as consul.service.consul
- `ssl` `(bool: false)` - Specifies if the transport scheme should use HTTPS to
communicate with the Consul agent.
- `tags` `(array<string>: [])` - Specifies optional Consul tags to be
registered with the Nomad server and agent services.
- `token` `(string: "")` - Specifies the token used to provide a per-request ACL
token. This option overrides the Consul Agent's default token. If the token is
not set here or on the Consul agent, it will default to Consul's anonymous policy,