Code review corrections
This commit is contained in:
parent
aaeb7cdffd
commit
d390f86de2
3 changed files with 28 additions and 16 deletions
20
docker.go
20
docker.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/BurntSushi/ty/fun"
|
"github.com/BurntSushi/ty/fun"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
@ -137,10 +138,8 @@ func (provider *DockerProvider) loadDockerConfig(dockerClient *docker.Client) *C
|
||||||
log.Debugf("Filtering disabled container %s", container.Name)
|
log.Debugf("Filtering disabled container %s", container.Name)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
_, errRule := provider.getLabel(container, "traefik.frontend.rule")
|
|
||||||
_, errValue := provider.getLabel(container, "traefik.frontend.value")
|
|
||||||
|
|
||||||
if errRule != nil && errValue == nil || errRule == nil && errValue != nil {
|
if _, err := provider.getLabels(container, []string{"traefik.frontend.rule", "traefik.frontend.value"}); err != nil {
|
||||||
log.Debugf("Filtering bad labeled container %s", container.Name)
|
log.Debugf("Filtering bad labeled container %s", container.Name)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -196,7 +195,8 @@ func (provider *DockerProvider) loadDockerConfig(dockerClient *docker.Client) *C
|
||||||
|
|
||||||
func (provider *DockerProvider) getFrontendName(container docker.Container) string {
|
func (provider *DockerProvider) getFrontendName(container docker.Container) string {
|
||||||
// Replace '.' with '-' in quoted keys because of this issue https://github.com/BurntSushi/toml/issues/78
|
// Replace '.' with '-' in quoted keys because of this issue https://github.com/BurntSushi/toml/issues/78
|
||||||
return strings.Replace(provider.GetFrontendRule(container)+"-"+provider.GetFrontendValue(container), ".", "-", -1)
|
frontendName := fmt.Sprintf("%s-%s", provider.GetFrontendRule(container), provider.GetFrontendValue(container))
|
||||||
|
return strings.Replace(frontendName, ".", "-", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *DockerProvider) getEscapedName(name string) string {
|
func (provider *DockerProvider) getEscapedName(name string) string {
|
||||||
|
@ -212,6 +212,18 @@ func (provider *DockerProvider) getLabel(container docker.Container, label strin
|
||||||
return "", errors.New("Label not found:" + label)
|
return "", errors.New("Label not found:" + label)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (provider *DockerProvider) getLabels(container docker.Container, labels []string) (map[string]string, error) {
|
||||||
|
foundLabels := map[string]string{}
|
||||||
|
for _, label := range labels {
|
||||||
|
if foundLabel, err := provider.getLabel(container, label); err != nil {
|
||||||
|
return nil, errors.New("Label not found: " + label)
|
||||||
|
} else {
|
||||||
|
foundLabels[label] = foundLabel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return foundLabels, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (provider *DockerProvider) GetFrontendValue(container docker.Container) string {
|
func (provider *DockerProvider) GetFrontendValue(container docker.Container) string {
|
||||||
if label, err := provider.getLabel(container, "traefik.frontend.value"); err == nil {
|
if label, err := provider.getLabel(container, "traefik.frontend.value"); err == nil {
|
||||||
return label
|
return label
|
||||||
|
|
22
marathon.go
22
marathon.go
|
@ -64,12 +64,12 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
|
||||||
return ""
|
return ""
|
||||||
},
|
},
|
||||||
"getWeight": func(task marathon.Task, applications []marathon.Application) string {
|
"getWeight": func(task marathon.Task, applications []marathon.Application) string {
|
||||||
application := getApplication(task, applications)
|
application, errApp := getApplication(task, applications)
|
||||||
if application == nil {
|
if errApp != nil {
|
||||||
log.Errorf("Unable to get marathon application from task %s", task.AppID)
|
log.Errorf("Unable to get marathon application from task %s", task.AppID)
|
||||||
return "0"
|
return "0"
|
||||||
}
|
}
|
||||||
if label, err := provider.getLabel(*application, "traefik.weight"); err == nil {
|
if label, err := provider.getLabel(application, "traefik.weight"); err == nil {
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
return "0"
|
return "0"
|
||||||
|
@ -84,12 +84,12 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
|
||||||
return strings.Replace(s3, s1, s2, -1)
|
return strings.Replace(s3, s1, s2, -1)
|
||||||
},
|
},
|
||||||
"getProtocol": func(task marathon.Task, applications []marathon.Application) string {
|
"getProtocol": func(task marathon.Task, applications []marathon.Application) string {
|
||||||
application := getApplication(task, applications)
|
application, errApp := getApplication(task, applications)
|
||||||
if application == nil {
|
if errApp != nil {
|
||||||
log.Errorf("Unable to get marathon application from task %s", task.AppID)
|
log.Errorf("Unable to get marathon application from task %s", task.AppID)
|
||||||
return "http"
|
return "http"
|
||||||
}
|
}
|
||||||
if label, err := provider.getLabel(*application, "traefik.protocol"); err == nil {
|
if label, err := provider.getLabel(application, "traefik.protocol"); err == nil {
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
return "http"
|
return "http"
|
||||||
|
@ -117,8 +117,8 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
|
||||||
log.Debug("Filtering marathon task without port", task.AppID)
|
log.Debug("Filtering marathon task without port", task.AppID)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
application := getApplication(task, applications.Apps)
|
application, errApp := getApplication(task, applications.Apps)
|
||||||
if application == nil {
|
if errApp != nil {
|
||||||
log.Errorf("Unable to get marathon application from task %s", task.AppID)
|
log.Errorf("Unable to get marathon application from task %s", task.AppID)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -193,13 +193,13 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
|
||||||
return configuration
|
return configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
func getApplication(task marathon.Task, apps []marathon.Application) *marathon.Application {
|
func getApplication(task marathon.Task, apps []marathon.Application) (marathon.Application, error) {
|
||||||
for _, application := range apps {
|
for _, application := range apps {
|
||||||
if application.ID == task.AppID {
|
if application.ID == task.AppID {
|
||||||
return &application
|
return application, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return marathon.Application{}, errors.New("Application not found: " + task.AppID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *MarathonProvider) getLabel(application marathon.Application, label string) (string, error) {
|
func (provider *MarathonProvider) getLabel(application marathon.Application, label string) (string, error) {
|
||||||
|
|
|
@ -133,7 +133,7 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
connBackend, resp, err := dialer.Dial(backendURL.String(), nil)
|
connBackend, resp, err := dialer.Dial(backendURL.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Websocketproxy: couldn't dial to remote backend url %s, %s, %+v", backendURL.String(), err, resp)
|
log.Errorf("Websocketproxy: couldn't dial to remote backend url %s, %s, %+v", backendURL.String(), err, resp)
|
||||||
http.NotFound(rw, req)
|
http.Error(rw, "Remote backend unreachable", http.StatusBadGateway)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer connBackend.Close()
|
defer connBackend.Close()
|
||||||
|
|
Loading…
Reference in a new issue