From 718fc7a79d7d8f0cf21f4e2991105c7011fa8428 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Tue, 2 Jan 2018 10:14:03 +0100 Subject: [PATCH 1/4] Fix bug report command --- cmd/traefik/bug.go | 8 ++++---- cmd/traefik/bug_test.go | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cmd/traefik/bug.go b/cmd/traefik/bug.go index 27d99d389..2c7551853 100644 --- a/cmd/traefik/bug.go +++ b/cmd/traefik/bug.go @@ -84,7 +84,7 @@ Add more configuration information here. ) // newBugCmd builds a new Bug command -func newBugCmd(traefikConfiguration interface{}, traefikPointersConfiguration interface{}) *flaeg.Command { +func newBugCmd(traefikConfiguration *TraefikConfiguration, traefikPointersConfiguration *TraefikConfiguration) *flaeg.Command { //version Command init return &flaeg.Command{ @@ -99,7 +99,7 @@ func newBugCmd(traefikConfiguration interface{}, traefikPointersConfiguration in } } -func runBugCmd(traefikConfiguration interface{}) func() error { +func runBugCmd(traefikConfiguration *TraefikConfiguration) func() error { return func() error { body, err := createBugReport(traefikConfiguration) @@ -113,7 +113,7 @@ func runBugCmd(traefikConfiguration interface{}) func() error { } } -func createBugReport(traefikConfiguration interface{}) (string, error) { +func createBugReport(traefikConfiguration *TraefikConfiguration) (string, error) { var version bytes.Buffer if err := getVersionPrint(&version); err != nil { return "", err @@ -124,7 +124,7 @@ func createBugReport(traefikConfiguration interface{}) (string, error) { return "", err } - config, err := anonymize.Do(&traefikConfiguration, true) + config, err := anonymize.Do(traefikConfiguration, true) if err != nil { return "", err } diff --git a/cmd/traefik/bug_test.go b/cmd/traefik/bug_test.go index efe191bcc..60c068283 100644 --- a/cmd/traefik/bug_test.go +++ b/cmd/traefik/bug_test.go @@ -6,16 +6,27 @@ import ( "github.com/containous/traefik/cmd/traefik/anonymize" "github.com/containous/traefik/configuration" "github.com/containous/traefik/provider/file" + "github.com/containous/traefik/types" "github.com/stretchr/testify/assert" ) func Test_createBugReport(t *testing.T) { - traefikConfiguration := TraefikConfiguration{ + traefikConfiguration := &TraefikConfiguration{ ConfigFile: "FOO", GlobalConfiguration: configuration.GlobalConfiguration{ EntryPoints: configuration.EntryPoints{ "goo": &configuration.EntryPoint{ Address: "hoo.bar", + Auth: &types.Auth{ + Basic: &types.Basic{ + UsersFile: "foo Basic UsersFile", + Users: types.Users{"foo Basic Users 1", "foo Basic Users 2", "foo Basic Users 3"}, + }, + Digest: &types.Digest{ + UsersFile: "foo Digest UsersFile", + Users: types.Users{"foo Digest Users 1", "foo Digest Users 2", "foo Digest Users 3"}, + }, + }, }, }, File: &file.Provider{ @@ -27,6 +38,11 @@ func Test_createBugReport(t *testing.T) { report, err := createBugReport(traefikConfiguration) assert.NoError(t, err, report) + + // exported anonymous configuration + assert.NotContains(t, "web Basic Users ", report) + assert.NotContains(t, "foo Digest Users ", report) + assert.NotContains(t, "hoo.bar", report) } func Test_anonymize_traefikConfiguration(t *testing.T) { From e8e8b41eed79d06e250a996ef69924c50e256a99 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 Jan 2018 10:52:03 +0100 Subject: [PATCH 2/4] Normalize serviceName added to the service backend names --- provider/consul/consul_catalog_test.go | 16 ++++++++-------- provider/docker/docker.go | 4 ++-- provider/docker/service_test.go | 10 ++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/provider/consul/consul_catalog_test.go b/provider/consul/consul_catalog_test.go index 3e6899f80..06d3a8495 100644 --- a/provider/consul/consul_catalog_test.go +++ b/provider/consul/consul_catalog_test.go @@ -12,14 +12,6 @@ import ( ) func TestConsulCatalogGetFrontendRule(t *testing.T) { - provider := &CatalogProvider{ - Domain: "localhost", - Prefix: "traefik", - FrontEndRule: "Host:{{.ServiceName}}.{{.Domain}}", - frontEndRuleTemplate: template.New("consul catalog frontend rule"), - } - provider.setupFrontEndTemplate() - testCases := []struct { desc string service serviceUpdate @@ -71,6 +63,14 @@ func TestConsulCatalogGetFrontendRule(t *testing.T) { t.Run(test.desc, func(t *testing.T) { t.Parallel() + provider := &CatalogProvider{ + Domain: "localhost", + Prefix: "traefik", + FrontEndRule: "Host:{{.ServiceName}}.{{.Domain}}", + frontEndRuleTemplate: template.New("consul catalog frontend rule"), + } + provider.setupFrontEndTemplate() + actual := provider.getFrontendRule(test.service) assert.Equal(t, test.expected, actual) }) diff --git a/provider/docker/docker.go b/provider/docker/docker.go index 34a60a2f3..fb6a86aee 100644 --- a/provider/docker/docker.go +++ b/provider/docker/docker.go @@ -433,9 +433,9 @@ func (p *Provider) getServicePriority(container dockerData, serviceName string) // Extract backend from labels for a given service and a given docker container func (p *Provider) getServiceBackend(container dockerData, serviceName string) string { if value, ok := getContainerServiceLabel(container, serviceName, "frontend.backend"); ok { - return container.ServiceName + "-" + value + return provider.Normalize(container.ServiceName + "-" + value) } - return strings.TrimPrefix(container.ServiceName, "/") + "-" + p.getBackend(container) + "-" + provider.Normalize(serviceName) + return provider.Normalize(container.ServiceName + "-" + p.getBackend(container) + "-" + serviceName) } // Extract rule from labels for a given service and a given docker container diff --git a/provider/docker/service_test.go b/provider/docker/service_test.go index 08febf216..c4659b01b 100644 --- a/provider/docker/service_test.go +++ b/provider/docker/service_test.go @@ -173,12 +173,22 @@ func TestDockerGetServiceBackend(t *testing.T) { container: containerJSON(name("foo")), expected: "foo-foo-myservice", }, + { + container: containerJSON(name("foo.bar")), + expected: "foo-bar-foo-bar-myservice", + }, { container: containerJSON(labels(map[string]string{ types.LabelBackend: "another-backend", })), expected: "fake-another-backend-myservice", }, + { + container: containerJSON(labels(map[string]string{ + types.LabelBackend: "another.backend", + })), + expected: "fake-another-backend-myservice", + }, { container: containerJSON(labels(map[string]string{ "traefik.myservice.frontend.backend": "custom-backend", From 52f16e11a8e7eef2aeba85d08302027e7514a594 Mon Sep 17 00:00:00 2001 From: SALLEYRON Julien Date: Tue, 2 Jan 2018 12:30:05 +0100 Subject: [PATCH 3/4] Use gorilla readMessage and writeMessage instead of just an io.Copy --- glide.lock | 2 +- vendor/github.com/vulcand/oxy/forward/fwd.go | 31 ++++++++++++------- .../github.com/vulcand/oxy/utils/netutils.go | 2 +- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/glide.lock b/glide.lock index 4a095a11c..3b5cfe7cd 100644 --- a/glide.lock +++ b/glide.lock @@ -481,7 +481,7 @@ imports: - name: github.com/urfave/negroni version: 490e6a555d47ca891a89a150d0c1ef3922dfffe9 - name: github.com/vulcand/oxy - version: 7e9763c4dc71b9758379da3581e6495c145caaab + version: bf0e6bab094f7b909a8d94ba9d7b74aaf7cc3025 repo: https://github.com/containous/oxy.git vcs: git subpackages: diff --git a/vendor/github.com/vulcand/oxy/forward/fwd.go b/vendor/github.com/vulcand/oxy/forward/fwd.go index e6aba940a..6ec424246 100644 --- a/vendor/github.com/vulcand/oxy/forward/fwd.go +++ b/vendor/github.com/vulcand/oxy/forward/fwd.go @@ -315,22 +315,29 @@ func (f *websocketForwarder) serveHTTP(w http.ResponseWriter, req *http.Request, defer targetConn.Close() errc := make(chan error, 2) - replicate := func(dst io.Writer, src io.Reader) { - _, err := io.Copy(dst, src) + + replicateWebsocketConn := func(dst, src *websocket.Conn, dstName, srcName string) { + var err error + for { + msgType, msg, err := src.ReadMessage() + if err != nil { + ctx.log.Errorf("vulcand/oxy/forward/websocket: Error when copying from %s to %s using ReadMessage: %v", srcName, dstName, err) + break + } + err = dst.WriteMessage(msgType, msg) + if err != nil { + ctx.log.Errorf("vulcand/oxy/forward/websocket: Error when copying from %s to %s using WriteMessage: %v", srcName, dstName, err) + break + } else { + ctx.log.Infof("vulcand/oxy/forward/websocket: Copying from %s to %s completed without error.", srcName, dstName) + } + } errc <- err } - go replicate(targetConn.UnderlyingConn(), underlyingConn.UnderlyingConn()) + go replicateWebsocketConn(underlyingConn, targetConn, "client", "backend") + go replicateWebsocketConn(targetConn, underlyingConn, "backend", "client") - // Try to read the first message - t, msg, err := targetConn.ReadMessage() - if err != nil { - ctx.log.Errorf("Couldn't read first message : %v", err) - } else { - underlyingConn.WriteMessage(t, msg) - } - - go replicate(underlyingConn.UnderlyingConn(), targetConn.UnderlyingConn()) <-errc } diff --git a/vendor/github.com/vulcand/oxy/utils/netutils.go b/vendor/github.com/vulcand/oxy/utils/netutils.go index 236ffdd34..6ae10395b 100644 --- a/vendor/github.com/vulcand/oxy/utils/netutils.go +++ b/vendor/github.com/vulcand/oxy/utils/netutils.go @@ -132,7 +132,7 @@ func RemoveHeaders(headers http.Header, names ...string) { } // Parse the MIME media type value of a header. -func GetHeaderMediaType(headers http.Header, name string) (string, error) { +func GetHeaderMediaType(headers http.Header, name string) (string, error) { mediatype, _, err := mime.ParseMediaType(headers.Get(name)) return mediatype, err } From 741c739ef1df614594cf1f9ecae1d71d336f0900 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 Jan 2018 12:54:03 +0100 Subject: [PATCH 4/4] Prepare release v1.4.6 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43a549f6a..12b7b5188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## [v1.4.6](https://github.com/containous/traefik/tree/v1.4.6) (2018-01-02) +[All Commits](https://github.com/containous/traefik/compare/v1.4.5...v1.4.6) + +**Bug fixes:** +- **[docker]** Normalize serviceName added to the service backend names ([#2631](https://github.com/containous/traefik/pull/2631) by [mmatur](https://github.com/mmatur)) +- **[websocket]** Use gorilla readMessage and writeMessage instead of just an io.Copy ([#2640](https://github.com/containous/traefik/pull/2640) by [Juliens](https://github.com/Juliens)) +- Fix bug report command ([#2638](https://github.com/containous/traefik/pull/2638) by [ldez](https://github.com/ldez)) + ## [v1.4.5](https://github.com/containous/traefik/tree/v1.4.5) (2017-12-05) [All Commits](https://github.com/containous/traefik/compare/v1.4.4...v1.4.5)