add backoff to marathon provider
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
23d3c512c2
commit
36338b4928
4 changed files with 48 additions and 33 deletions
|
@ -6,7 +6,7 @@ zk:
|
||||||
ZK_ID: 1
|
ZK_ID: 1
|
||||||
|
|
||||||
master:
|
master:
|
||||||
image: mesosphere/mesos-master:0.26.0-0.2.145.ubuntu1404
|
image: mesosphere/mesos-master:0.28.1-2.0.20.ubuntu1404
|
||||||
net: host
|
net: host
|
||||||
environment:
|
environment:
|
||||||
MESOS_ZK: zk://127.0.0.1:2181/mesos
|
MESOS_ZK: zk://127.0.0.1:2181/mesos
|
||||||
|
@ -17,7 +17,7 @@ master:
|
||||||
MESOS_WORK_DIR: /var/lib/mesos
|
MESOS_WORK_DIR: /var/lib/mesos
|
||||||
|
|
||||||
slave:
|
slave:
|
||||||
image: mesosphere/mesos-slave:0.26.0-0.2.145.ubuntu1404
|
image: mesosphere/mesos-slave:0.28.1-2.0.20.ubuntu1404
|
||||||
net: host
|
net: host
|
||||||
pid: host
|
pid: host
|
||||||
privileged: true
|
privileged: true
|
||||||
|
@ -34,10 +34,19 @@ slave:
|
||||||
- /lib/x86_64-linux-gnu/libsystemd-journal.so.0:/lib/x86_64-linux-gnu/libsystemd-journal.so.0
|
- /lib/x86_64-linux-gnu/libsystemd-journal.so.0:/lib/x86_64-linux-gnu/libsystemd-journal.so.0
|
||||||
|
|
||||||
marathon:
|
marathon:
|
||||||
image: mesosphere/marathon:v0.13.0
|
image: mesosphere/marathon:v1.1.1
|
||||||
net: host
|
net: host
|
||||||
environment:
|
environment:
|
||||||
MARATHON_MASTER: zk://127.0.0.1:2181/mesos
|
MARATHON_MASTER: zk://127.0.0.1:2181/mesos
|
||||||
MARATHON_ZK: zk://127.0.0.1:2181/marathon
|
MARATHON_ZK: zk://127.0.0.1:2181/marathon
|
||||||
MARATHON_HOSTNAME: 127.0.0.1
|
MARATHON_HOSTNAME: 127.0.0.1
|
||||||
command: --event_subscriber http_callback
|
command: --event_subscriber http_callback
|
||||||
|
|
||||||
|
traefik:
|
||||||
|
image: traefik
|
||||||
|
command: -c /dev/null --web --logLevel=DEBUG --marathon --marathon.domain marathon.localhost --marathon.endpoint http://172.17.0.1:8080 --marathon.watch
|
||||||
|
ports:
|
||||||
|
- "8000:80"
|
||||||
|
- "8081:8080"
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
@ -1,12 +1,11 @@
|
||||||
traefik:
|
traefik:
|
||||||
image: traefik
|
image: traefik
|
||||||
command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
|
command: -c /dev/null --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
- /dev/null:/traefik.toml
|
|
||||||
|
|
||||||
whoami1:
|
whoami1:
|
||||||
image: emilevauge/whoami
|
image: emilevauge/whoami
|
||||||
|
|
|
@ -26,6 +26,6 @@
|
||||||
"labels": {
|
"labels": {
|
||||||
"traefik.weight": "1",
|
"traefik.weight": "1",
|
||||||
"traefik.protocole": "http",
|
"traefik.protocole": "http",
|
||||||
"traefik.frontend.rule" : "Headers:Host,test.localhost"
|
"traefik.frontend.rule" : "Host:test.marathon.localhost"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,12 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"github.com/BurntSushi/ty/fun"
|
"github.com/BurntSushi/ty/fun"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/cenkalti/backoff"
|
||||||
"github.com/containous/traefik/safe"
|
"github.com/containous/traefik/safe"
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
"github.com/gambol99/go-marathon"
|
"github.com/gambol99/go-marathon"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Marathon holds configuration of the Marathon provider.
|
// Marathon holds configuration of the Marathon provider.
|
||||||
|
@ -41,6 +43,7 @@ type lightMarathonClient interface {
|
||||||
// Provide allows the provider to provide configurations to traefik
|
// Provide allows the provider to provide configurations to traefik
|
||||||
// using the given configuration channel.
|
// using the given configuration channel.
|
||||||
func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error {
|
func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error {
|
||||||
|
operation := func() error {
|
||||||
config := marathon.NewDefaultConfig()
|
config := marathon.NewDefaultConfig()
|
||||||
config.URL = provider.Endpoint
|
config.URL = provider.Endpoint
|
||||||
config.EventsTransport = marathon.EventsTransportSSE
|
config.EventsTransport = marathon.EventsTransportSSE
|
||||||
|
@ -63,7 +66,8 @@ func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage,
|
||||||
if provider.Watch {
|
if provider.Watch {
|
||||||
if err := client.AddEventsListener(update, marathon.EVENTS_APPLICATIONS); err != nil {
|
if err := client.AddEventsListener(update, marathon.EVENTS_APPLICATIONS); err != nil {
|
||||||
log.Errorf("Failed to register for events, %s", err)
|
log.Errorf("Failed to register for events, %s", err)
|
||||||
} else {
|
return err
|
||||||
|
}
|
||||||
pool.Go(func(stop chan bool) {
|
pool.Go(func(stop chan bool) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -82,12 +86,15 @@ func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration := provider.loadMarathonConfig()
|
notify := func(err error, time time.Duration) {
|
||||||
configurationChan <- types.ConfigMessage{
|
log.Errorf("Marathon connection error %+v, retrying in %s", err, time)
|
||||||
ProviderName: "marathon",
|
}
|
||||||
Configuration: configuration,
|
err := backoff.RetryNotify(operation, backoff.NewExponentialBackOff(), notify)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Cannot connect to Marathon server %+v", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue