2015-11-01 16:35:01 +01:00
|
|
|
package provider
|
|
|
|
|
2015-11-13 11:50:32 +01:00
|
|
|
import (
|
2016-07-13 17:18:55 +02:00
|
|
|
"fmt"
|
2016-04-13 20:36:23 +02:00
|
|
|
"github.com/containous/traefik/safe"
|
2016-02-24 16:43:39 +01:00
|
|
|
"github.com/containous/traefik/types"
|
2015-11-13 11:50:32 +01:00
|
|
|
"github.com/docker/libkv/store"
|
|
|
|
"github.com/docker/libkv/store/consul"
|
|
|
|
)
|
2015-09-21 18:05:56 +02:00
|
|
|
|
2016-08-16 19:13:18 +02:00
|
|
|
var _ Provider = (*Consul)(nil)
|
|
|
|
|
2015-11-01 19:29:47 +01:00
|
|
|
// Consul holds configurations of the Consul provider.
|
2015-11-02 19:48:34 +01:00
|
|
|
type Consul struct {
|
2016-06-24 09:58:42 +02:00
|
|
|
Kv `mapstructure:",squash"`
|
2015-09-21 18:05:56 +02:00
|
|
|
}
|
|
|
|
|
2015-11-01 19:29:47 +01:00
|
|
|
// Provide allows the provider to provide configurations to traefik
|
|
|
|
// using the given configuration channel.
|
2016-05-31 09:54:42 +02:00
|
|
|
func (provider *Consul) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints []types.Constraint) error {
|
2016-07-13 17:18:55 +02:00
|
|
|
store, err := provider.CreateStore()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to Connect to KV store: %v", err)
|
|
|
|
}
|
|
|
|
provider.kvclient = store
|
|
|
|
return provider.provide(configurationChan, pool, constraints)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateStore creates the KV store
|
|
|
|
func (provider *Consul) CreateStore() (store.Store, error) {
|
2016-01-13 22:46:44 +01:00
|
|
|
provider.storeType = store.CONSUL
|
2015-11-13 11:50:32 +01:00
|
|
|
consul.Register()
|
2016-07-13 17:18:55 +02:00
|
|
|
return provider.createStore()
|
2015-09-21 18:05:56 +02:00
|
|
|
}
|