Skip to content

Commit fcbfa57

Browse files
authored
Merge pull request #8 from Nitro/relistan/modernize-some-more
Clean up, stop vendoring, import haproxy module
2 parents 3b42681 + 261b95a commit fcbfa57

1,023 files changed

Lines changed: 1353 additions & 343035 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: go
22
go:
3-
- 1.12.x
3+
- 1.16.x
44

55
sudo: required
66

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55

66
"github.com/BurntSushi/toml"
7-
"github.com/Nitro/sidecar/haproxy"
7+
"github.com/Nitro/haproxy-api/haproxy"
88
"github.com/kelseyhightower/envconfig"
99
log "github.com/sirupsen/logrus"
1010
)

go.mod

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,42 @@ go 1.12
44

55
require (
66
github.com/BurntSushi/toml v0.3.1
7-
github.com/Microsoft/go-winio v0.4.12 // indirect
7+
github.com/Microsoft/hcsshim v0.8.16 // indirect
88
github.com/Nitro/memberlist v0.0.0-20170522194404-cfac2b5cf519 // indirect
9-
github.com/Nitro/sidecar v1.3.1
10-
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
11-
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
12-
github.com/armon/go-metrics v0.0.0-20171002182731-9a4b6e10bed6 // indirect
9+
github.com/Nitro/sidecar v2.1.0+incompatible
10+
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 // indirect
11+
github.com/armon/go-metrics v0.3.6 // indirect
12+
github.com/containerd/continuity v0.0.0-20210315143101-93e15499afd5 // indirect
1313
github.com/docker/distribution v2.7.1+incompatible // indirect
14-
github.com/fsouza/go-dockerclient v1.3.6 // indirect
15-
github.com/gogo/protobuf v1.2.1 // indirect
16-
github.com/golang/protobuf v1.3.1 // indirect
14+
github.com/docker/docker v20.10.6+incompatible // indirect
15+
github.com/fsouza/go-dockerclient v1.7.2 // indirect
16+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
1717
github.com/gopherjs/gopherjs v0.0.0-20190328170749-bb2674552d8f // indirect
1818
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f // indirect
1919
github.com/gorilla/handlers v1.2.1
20-
github.com/gorilla/mux v1.7.0
21-
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect
22-
github.com/hashicorp/go-immutable-radix v0.0.0-20170725221215-8aac27015308 // indirect
23-
github.com/hashicorp/go-msgpack v0.0.0-20150518234257-fa3f63826f7c // indirect
24-
github.com/hashicorp/go-multierror v0.0.0-20170622060955-83588e72410a // indirect
25-
github.com/hashicorp/go-sockaddr v0.0.0-20170627023441-41949a141473 // indirect
26-
github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad // indirect
20+
github.com/gorilla/mux v1.8.0
21+
github.com/hashicorp/errwrap v1.1.0 // indirect
22+
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
23+
github.com/hashicorp/go-msgpack v1.1.5 // indirect
24+
github.com/hashicorp/go-multierror v1.1.1 // indirect
25+
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
26+
github.com/hashicorp/golang-lru v0.5.4 // indirect
27+
github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd // indirect
2728
github.com/jtolds/gls v4.20.0+incompatible // indirect
28-
github.com/kelseyhightower/envconfig v1.3.0
29-
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
30-
github.com/miekg/dns v0.0.0-20171019064225-822ae18e7187 // indirect
29+
github.com/kelseyhightower/envconfig v1.4.0
30+
github.com/miekg/dns v1.1.41 // indirect
3131
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
3232
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
33-
github.com/pquerna/ffjson v0.0.0-20171002144729-d49c2bc1aa13 // indirect
34-
github.com/relistan/go-director v0.0.0-20161014141051-9273dae8c839
33+
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 // indirect
34+
github.com/relistan/go-director v0.0.0-20200406104025-dbbf5d95248d
3535
github.com/relistan/rubberneck v1.0.1
3636
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
37-
github.com/sirupsen/logrus v1.4.1
37+
github.com/sirupsen/logrus v1.8.1
3838
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 // indirect
39-
github.com/smartystreets/goconvey v0.0.0-20170602164621-9e8dc3f972df
40-
google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107 // indirect
41-
google.golang.org/grpc v1.19.1 // indirect
42-
gopkg.in/alecthomas/kingpin.v2 v2.2.5
39+
github.com/smartystreets/goconvey v1.6.4
40+
go.opencensus.io v0.23.0 // indirect
41+
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1 // indirect
42+
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 // indirect
43+
gopkg.in/alecthomas/kingpin.v2 v2.2.6
44+
gopkg.in/relistan/rubberneck.v1 v1.1.0 // indirect
4345
)

go.sum

Lines changed: 893 additions & 1 deletion
Large diffs are not rendered by default.

vendor/github.com/Nitro/sidecar/haproxy/haproxy.go renamed to haproxy/haproxy.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type HAproxy struct {
4343

4444
// Constructs a properly configured HAProxy and returns a pointer to it
4545
func New(configFile string, pidFile string) *HAproxy {
46-
reloadCmd := "haproxy -f " + configFile + " -p " + pidFile + " `[[ -f " + pidFile + " ]] && echo \"-sf $(cat " + pidFile + ")\"]]`"
46+
reloadCmd := "haproxy -f " + configFile + " -p " + pidFile + " `[[ -f " + pidFile + " ]] && echo \"-sf $(cat " + pidFile + ")\"`"
4747
verifyCmd := "haproxy -c -f " + configFile
4848

4949
proxy := HAproxy{
@@ -184,7 +184,10 @@ func (h *HAproxy) WriteConfig(state *catalog.ServicesState, output io.Writer) er
184184
}
185185

186186
// This is the potentially slowest bit, do it outside the critical section
187-
io.Copy(output, buf)
187+
_, err = io.Copy(output, buf)
188+
if err != nil {
189+
return fmt.Errorf("Error writing template '%s': %s", h.Template, err.Error())
190+
}
188191

189192
return nil
190193
}
@@ -210,15 +213,15 @@ func (h *HAproxy) swallowSignals() {
210213
}
211214
}()
212215

213-
signal.Notify(sigChan, syscall.SIGSTOP, syscall.SIGTSTP, syscall.SIGTTIN, syscall.SIGTTOU)
216+
signal.Notify(sigChan, syscall.SIGTSTP, syscall.SIGTTIN, syscall.SIGTTOU)
214217
}
215218

216219
// ResetSignals unhooks our signal handler from the signals the sub-commands
217220
// initiate. This is potentially destructive if other places in the program have
218-
// hooked to the same signals! Affected signals are SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU.
221+
// hooked to the same signals! Affected signals are SIGTSTP, SIGTTIN, SIGTTOU.
219222
func (h *HAproxy) ResetSignals() {
220223
h.sigLock.Lock()
221-
signal.Reset(syscall.SIGSTOP, syscall.SIGTSTP, syscall.SIGTTIN, syscall.SIGTTOU)
224+
signal.Reset(syscall.SIGTSTP, syscall.SIGTTIN, syscall.SIGTTOU)
222225
select {
223226
case h.sigStopChan <- struct{}{}: // nothing
224227
default:
@@ -286,7 +289,10 @@ func (h *HAproxy) Watch(state *catalog.ServicesState) {
286289
}
287290
}
288291

289-
state.RemoveListener(h.Name())
292+
err := state.RemoveListener(h.Name())
293+
if err != nil {
294+
log.Warnf("Failed to remove HAProxy listener: %s", err)
295+
}
290296
}
291297

292298
// Write out the the HAproxy config and reload the service.
@@ -331,7 +337,12 @@ func getModes(state *catalog.ServicesState) map[string]string {
331337
modeMap := make(map[string]string)
332338
state.EachService(
333339
func(hostname *string, serviceId *string, svc *service.Service) {
334-
modeMap[svc.Name] = svc.ProxyMode
340+
mode := svc.ProxyMode
341+
// Treat websockets like HTTP
342+
if mode == "ws" {
343+
mode = "http"
344+
}
345+
modeMap[svc.Name] = mode
335346
},
336347
)
337348
return modeMap

0 commit comments

Comments
 (0)