mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 18:05:42 +03:00
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:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user