Marathon provider listener

This commit is contained in:
emile 2015-09-09 23:09:16 +02:00
parent 9a840d1904
commit 3dd168b465
3 changed files with 19 additions and 4 deletions

View file

@ -52,7 +52,7 @@ func (provider *DockerProvider) Provide(configurationChan chan <- *Configuration
go func() { go func() {
for { for {
event := <-dockerEvents event := <-dockerEvents
log.Println("Event receveived", event) log.Println("Docker event receveived", event)
configuration := provider.loadDockerConfig() configuration := provider.loadDockerConfig()
if (configuration != nil) { if (configuration != nil) {
configurationChan <- configuration configurationChan <- configuration

View file

@ -40,11 +40,28 @@ var MarathonFuncMap = template.FuncMap{
func (provider *MarathonProvider) Provide(configurationChan chan <- *Configuration) { func (provider *MarathonProvider) Provide(configurationChan chan <- *Configuration) {
config := marathon.NewDefaultConfig() config := marathon.NewDefaultConfig()
config.URL = provider.Endpoint config.URL = provider.Endpoint
config.EventsInterface = "docker0"
if client, err := marathon.NewClient(config); err != nil { if client, err := marathon.NewClient(config); err != nil {
log.Println("Failed to create a client for marathon, error: %s", err) log.Println("Failed to create a client for marathon, error: %s", err)
return return
} else { } else {
provider.marathonClient = client provider.marathonClient = client
update := make(marathon.EventsChannel,5)
if err := client.AddEventsListener(update, marathon.EVENTS_APPLICATIONS); err != nil {
log.Println("Failed to register for subscriptions, %s", err)
} else {
go func() {
for {
event := <-update
log.Println("Marathon event receveived", event)
configuration := provider.loadMarathonConfig()
if (configuration != nil) {
configurationChan <- configuration
}
}
}()
}
configuration := provider.loadMarathonConfig() configuration := provider.loadMarathonConfig()
configurationChan <- configuration configurationChan <- configuration
} }
@ -94,7 +111,5 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
return nil return nil
} }
log.Println(buffer.String())
return configuration return configuration
} }

View file

@ -5,7 +5,7 @@
[routes]{{range .Applications}} [routes]{{range .Applications}}
[routes.route{{.ID | replace "/" "-"}}] [routes.route{{.ID | replace "/" "-"}}]
backend = ".backend{{.ID | replace "/" "-"}}" backend = "backend{{.ID | replace "/" "-"}}"
[routes.route-{{getHost .}}.rules.rule-host-{{getHost .}}] [routes.route-{{getHost .}}.rules.rule-host-{{getHost .}}]
category = "Host" category = "Host"
value = "{{getHost .}}.{{$.Domain}}" value = "{{getHost .}}.{{$.Domain}}"