From b9c3fc6a8734b39dbdffb375dfc977d7e414f143 Mon Sep 17 00:00:00 2001 From: ahusic Date: Thu, 26 Aug 2021 17:08:44 +0200 Subject: [PATCH 1/2] MINOR: downstream-service: enable usage of Consul service definition without port being specified According to the Consul documentation (https://www.consul.io/docs/discovery/services) port is not mandatory in service definition. This use case is helpfull when downstream service is run by e.g. cron jobs where port are not needed(specified). --- consul/watcher.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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() } From de2fa7587087175f78412821c2c61a918979f134 Mon Sep 17 00:00:00 2001 From: ahusic Date: Thu, 26 Aug 2021 17:14:14 +0200 Subject: [PATCH 2/2] MINOR: typo fixed --- haproxy/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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),