Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new config to override service host with consul advertise ip #692

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ type Consul struct {
ChecksRequired string
ServiceMonitors int
TLS ConsulTlS
UseConsulServiceAddr bool
}

type Custom struct {
Expand Down
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var defaultConfig = &Config{
CheckScheme: "http",
CheckDeregisterCriticalServiceAfter: "90m",
ChecksRequired: "one",
UseConsulServiceAddr: false,
},
Custom: Custom{
Host: "",
Expand Down
1 change: 1 addition & 0 deletions config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c
f.StringVar(&cfg.Registry.Consul.KVPath, "registry.consul.kvpath", defaultConfig.Registry.Consul.KVPath, "consul KV path for manual overrides")
f.StringVar(&cfg.Registry.Consul.NoRouteHTMLPath, "registry.consul.noroutehtmlpath", defaultConfig.Registry.Consul.NoRouteHTMLPath, "consul KV path for HTML returned when no route is found")
f.StringVar(&cfg.Registry.Consul.TagPrefix, "registry.consul.tagprefix", defaultConfig.Registry.Consul.TagPrefix, "prefix for consul tags")
f.BoolVar(&cfg.Registry.Consul.UseConsulServiceAddr, "registry.consul.useconsulserviceaddr", defaultConfig.Registry.Consul.UseConsulServiceAddr, "Use consul address instead of service address")
f.StringVar(&cfg.Registry.Consul.TLS.KeyFile, "registry.consul.tls.keyfile", defaultConfig.Registry.Consul.TLS.KeyFile, "path to consul key file")
f.StringVar(&cfg.Registry.Consul.TLS.CertFile, "registry.consul.tls.certfile", defaultConfig.Registry.Consul.TLS.CertFile, "path to consul cert file")
f.StringVar(&cfg.Registry.Consul.TLS.CAFile, "registry.consul.tls.cafile", defaultConfig.Registry.Consul.TLS.CAFile, "path to consul CA file")
Expand Down
11 changes: 11 additions & 0 deletions fabio.properties
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,17 @@
# registry.consul.tagprefix = urlprefix-


# registry.consul.useconsulserviceaddr configures the behaivour for overriding the address
#
# Nomad in combination with Consul often register a service with an internal IP
# Nomad doesn't not respect currently to register services with the advertisement IP
# With this setting all services host ip will be ignored and the consul advertise IP
# will be registered.
#
# The default is
# registry.consul.useconsulserviceaddr = false


# registry.consul.register.enabled configures whether fabio registers itself in consul.
#
# Fabio will register itself in consul only if this value is set to "true" which
Expand Down
4 changes: 3 additions & 1 deletion registry/consul/routecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type routecmd struct {
prefix string

env map[string]string

useConsulAddress bool
}

func (r routecmd) build() []string {
Expand All @@ -40,7 +42,7 @@ func (r routecmd) build() []string {
name, addr, port := r.svc.ServiceName, r.svc.ServiceAddress, r.svc.ServicePort

// use consul node address if service address is not set
if addr == "" {
if r.useConsulAddress || addr == "" {
addr = r.svc.Address
}

Expand Down
1 change: 1 addition & 0 deletions registry/consul/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (w *ServiceMonitor) serviceConfig(name string, passing map[string]bool) (co
svc: svc,
env: env,
prefix: w.config.TagPrefix,
useConsulAddress: w.config.UseConsulServiceAddr,
}
cmds := r.build()

Expand Down