Skip to content

Commit

Permalink
config: let registry.consul.register.addr default to ui.addr
Browse files Browse the repository at this point in the history
Always set registry.consul.register.addr to the value of ui.addr if the
flag hasn't been specified.

Signed-off-by: Peter Schultz <peter.schultz@classmarkets.com>
  • Loading branch information
pschultz committed May 16, 2019
1 parent 86dde1c commit ba590ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c
f.StringVar(&cfg.Registry.Consul.TLS.CAPath, "registry.consul.tls.capath", defaultConfig.Registry.Consul.TLS.CAPath, "path to consul CA directory")
f.BoolVar(&cfg.Registry.Consul.TLS.InsecureSkipVerify, "registry.consul.tls.insecureskipverify", defaultConfig.Registry.Consul.TLS.InsecureSkipVerify, "is tls check enabled")
f.BoolVar(&cfg.Registry.Consul.Register, "registry.consul.register.enabled", defaultConfig.Registry.Consul.Register, "register fabio in consul")
f.StringVar(&cfg.Registry.Consul.ServiceAddr, "registry.consul.register.addr", defaultConfig.Registry.Consul.ServiceAddr, "service registration address")
f.StringVar(&cfg.Registry.Consul.ServiceAddr, "registry.consul.register.addr", "<ui.addr>", "service registration address")
f.StringVar(&cfg.Registry.Consul.ServiceName, "registry.consul.register.name", defaultConfig.Registry.Consul.ServiceName, "service registration name")
f.StringSliceVar(&cfg.Registry.Consul.ServiceTags, "registry.consul.register.tags", defaultConfig.Registry.Consul.ServiceTags, "service registration tags")
f.StringSliceVar(&cfg.Registry.Consul.ServiceStatus, "registry.consul.service.status", defaultConfig.Registry.Consul.ServiceStatus, "valid service status values")
Expand Down Expand Up @@ -272,6 +272,11 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c
}
}

// Unless registry.consul.register.addr has been set explicitly it should
// be the same as ui.addr. See issue 657.
if !f.IsSet("registry.consul.register.addr") {
cfg.Registry.Consul.ServiceAddr = cfg.UI.Listen.Addr
}
if cfg.Registry.Consul.ServiceAddr != "" {
if cfg.Registry.Consul.ServiceAddr, err = gs.Parse(cfg.Registry.Consul.ServiceAddr); err != nil {
return nil, fmt.Errorf("failed to consul service address: %s", err)
Expand Down
2 changes: 2 additions & 0 deletions config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ func TestLoad(t *testing.T) {
cfg: func(cfg *Config) *Config {
cfg.UI.Listen.Addr = "1.2.3.4:5555"
cfg.UI.Listen.Proto = "http"
cfg.Registry.Consul.ServiceAddr = "1.2.3.4:5555"
return cfg
},
},
Expand All @@ -886,6 +887,7 @@ func TestLoad(t *testing.T) {
cfg.UI.Listen.CertSource.Type = "file"
cfg.UI.Listen.CertSource.CertPath = "value"
cfg.Registry.Consul.CheckScheme = "https"
cfg.Registry.Consul.ServiceAddr = ":9998"
return cfg
},
},
Expand Down

0 comments on commit ba590ea

Please sign in to comment.