diff --git a/consul/watcher.go b/consul/watcher.go index 665699d..39585f3 100644 --- a/consul/watcher.go +++ b/consul/watcher.go @@ -8,6 +8,7 @@ import ( "sync" "time" + "github.com/facebookgo/freeport" "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/command/connect/proxy" log "github.com/sirupsen/logrus" @@ -107,7 +108,14 @@ func (w *Watcher) Run() error { go w.watchLeaf() go w.watchService(proxyID, w.handleProxyChange) go w.watchService(w.service, func(first bool, srv *api.AgentService) { - w.downstream.TargetPort = srv.Port + srvport := srv.Port + if srvport == 0 { + srvport, err = freeport.Get() + if err != nil { + log.Errorf(err.Error()) + } + } + w.downstream.TargetPort = srvport if first { w.ready.Done() } diff --git a/haproxy/config.go b/haproxy/config.go index f62b8d2..4e69bf9 100644 --- a/haproxy/config.go +++ b/haproxy/config.go @@ -116,7 +116,7 @@ func newHaConfig(baseDir string, sd *lib.Shutdown) (*haConfig, error) { }() cfg.DataplanePass = createRandomString() - cfg.DataplaneUser = "hapeoxy" + cfg.DataplaneUser = "haproxy" err = tmpl.Execute(cfgFile, baseParams{ NbThread: runtime.GOMAXPROCS(0),