Merge pull request #1588 from containous/fix-exported-fields-providers

Fix exported fields providers
This commit is contained in:
Emile Vauge 2017-05-11 22:58:00 +02:00 committed by GitHub
commit ffe1104851
8 changed files with 49 additions and 39 deletions

View file

@ -25,13 +25,13 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
if err != nil {
return fmt.Errorf("Failed to Connect to KV store: %v", err)
}
p.Kvclient = store
p.SetKVClient(store)
return p.Provider.Provide(configurationChan, pool, constraints)
}
// CreateStore creates the KV store
func (p *Provider) CreateStore() (store.Store, error) {
p.StoreType = store.BOLTDB
p.SetStoreType(store.BOLTDB)
boltdb.Register()
return p.Provider.CreateStore()
}

View file

@ -25,13 +25,13 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
if err != nil {
return fmt.Errorf("Failed to Connect to KV store: %v", err)
}
p.Kvclient = store
p.SetKVClient(store)
return p.Provider.Provide(configurationChan, pool, constraints)
}
// CreateStore creates the KV store
func (p *Provider) CreateStore() (store.Store, error) {
p.StoreType = store.CONSUL
p.SetStoreType(store.CONSUL)
consul.Register()
return p.Provider.CreateStore()
}

View file

@ -25,13 +25,13 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
if err != nil {
return fmt.Errorf("Failed to Connect to KV store: %v", err)
}
p.Kvclient = store
p.SetKVClient(store)
return p.Provider.Provide(configurationChan, pool, constraints)
}
// CreateStore creates the KV store
func (p *Provider) CreateStore() (store.Store, error) {
p.StoreType = store.ETCD
p.SetStoreType(store.ETCD)
etcd.Register()
return p.Provider.CreateStore()
}

View file

@ -19,8 +19,8 @@ import (
// Provider holds configuration of the Provider provider.
type Provider struct {
provider.BaseProvider `mapstructure:",squash"`
Endpoint string
Delay string
Endpoint string `description:"Eureka server endpoint"`
Delay string `description:"Override default configuration time between refresh"`
}
// Provide allows the eureka provider to provide configurations to traefik

View file

@ -26,8 +26,8 @@ type Provider struct {
TLS *provider.ClientTLS `description:"Enable TLS support"`
Username string `description:"KV Username"`
Password string `description:"KV Password"`
StoreType store.Backend
Kvclient store.Store
storeType store.Backend
kvclient store.Store
}
// CreateStore create the K/V store
@ -47,15 +47,25 @@ func (p *Provider) CreateStore() (store.Store, error) {
}
}
return libkv.NewStore(
p.StoreType,
p.storeType,
strings.Split(p.Endpoint, ","),
storeConfig,
)
}
// SetStoreType storeType setter
func (p *Provider) SetStoreType(storeType store.Backend) {
p.storeType = storeType
}
// SetKVClient kvclient setter
func (p *Provider) SetKVClient(kvClient store.Store) {
p.kvclient = kvClient
}
func (p *Provider) watchKv(configurationChan chan<- types.ConfigMessage, prefix string, stop chan bool) error {
operation := func() error {
events, err := p.Kvclient.WatchTree(p.Prefix, make(chan struct{}))
events, err := p.kvclient.WatchTree(p.Prefix, make(chan struct{}))
if err != nil {
return fmt.Errorf("Failed to KV WatchTree: %v", err)
}
@ -70,7 +80,7 @@ func (p *Provider) watchKv(configurationChan chan<- types.ConfigMessage, prefix
configuration := p.loadConfig()
if configuration != nil {
configurationChan <- types.ConfigMessage{
ProviderName: string(p.StoreType),
ProviderName: string(p.storeType),
Configuration: configuration,
}
}
@ -92,7 +102,7 @@ func (p *Provider) watchKv(configurationChan chan<- types.ConfigMessage, prefix
func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints types.Constraints) error {
p.Constraints = append(p.Constraints, constraints...)
operation := func() error {
if _, err := p.Kvclient.Exists("qmslkjdfmqlskdjfmqlksjazçueznbvbwzlkajzebvkwjdcqmlsfj"); err != nil {
if _, err := p.kvclient.Exists("qmslkjdfmqlskdjfmqlksjazçueznbvbwzlkajzebvkwjdcqmlsfj"); err != nil {
return fmt.Errorf("Failed to test KV store connection: %v", err)
}
if p.Watch {
@ -105,7 +115,7 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
}
configuration := p.loadConfig()
configurationChan <- types.ConfigMessage{
ProviderName: string(p.StoreType),
ProviderName: string(p.storeType),
Configuration: configuration,
}
return nil
@ -152,7 +162,7 @@ func (p *Provider) loadConfig() *types.Configuration {
func (p *Provider) list(keys ...string) []string {
joinedKeys := strings.Join(keys, "")
keysPairs, err := p.Kvclient.List(joinedKeys)
keysPairs, err := p.kvclient.List(joinedKeys)
if err != nil {
log.Debugf("Cannot get keys %s %s ", joinedKeys, err)
return nil
@ -169,7 +179,7 @@ func (p *Provider) listServers(backend string) []string {
serverNames := p.list(backend, "/servers/")
return fun.Filter(func(serverName string) bool {
key := fmt.Sprint(serverName, "/url")
if _, err := p.Kvclient.Get(key); err != nil {
if _, err := p.kvclient.Get(key); err != nil {
if err != store.ErrKeyNotFound {
log.Errorf("Failed to retrieve value for key %s: %s", key, err)
}
@ -181,7 +191,7 @@ func (p *Provider) listServers(backend string) []string {
func (p *Provider) get(defaultValue string, keys ...string) string {
joinedKeys := strings.Join(keys, "")
keyPair, err := p.Kvclient.Get(strings.TrimPrefix(joinedKeys, "/"))
keyPair, err := p.kvclient.Get(strings.TrimPrefix(joinedKeys, "/"))
if err != nil {
log.Debugf("Cannot get key %s %s, setting default %s", joinedKeys, err, defaultValue)
return defaultValue
@ -194,7 +204,7 @@ func (p *Provider) get(defaultValue string, keys ...string) string {
func (p *Provider) splitGet(keys ...string) []string {
joinedKeys := strings.Join(keys, "")
keyPair, err := p.Kvclient.Get(joinedKeys)
keyPair, err := p.kvclient.Get(joinedKeys)
if err != nil {
log.Debugf("Cannot get key %s %s, setting default empty", joinedKeys, err)
return []string{}
@ -212,7 +222,7 @@ func (p *Provider) last(key string) string {
func (p *Provider) checkConstraints(keys ...string) bool {
joinedKeys := strings.Join(keys, "")
keyPair, err := p.Kvclient.Get(joinedKeys)
keyPair, err := p.kvclient.Get(joinedKeys)
value := ""
if err == nil && keyPair != nil && keyPair.Value != nil {

View file

@ -20,21 +20,21 @@ func TestKvList(t *testing.T) {
}{
{
provider: &Provider{
Kvclient: &Mock{},
kvclient: &Mock{},
},
keys: []string{},
expected: []string{},
},
{
provider: &Provider{
Kvclient: &Mock{},
kvclient: &Mock{},
},
keys: []string{"traefik"},
expected: []string{},
},
{
provider: &Provider{
Kvclient: &Mock{
kvclient: &Mock{
KVPairs: []*store.KVPair{
{
Key: "foo",
@ -48,7 +48,7 @@ func TestKvList(t *testing.T) {
},
{
provider: &Provider{
Kvclient: &Mock{
kvclient: &Mock{
KVPairs: []*store.KVPair{
{
Key: "foo",
@ -62,7 +62,7 @@ func TestKvList(t *testing.T) {
},
{
provider: &Provider{
Kvclient: &Mock{
kvclient: &Mock{
KVPairs: []*store.KVPair{
{
Key: "foo/baz/1",
@ -95,7 +95,7 @@ func TestKvList(t *testing.T) {
// Error case
provider := &Provider{
Kvclient: &Mock{
kvclient: &Mock{
Error: KvError{
List: store.ErrKeyNotFound,
},
@ -115,21 +115,21 @@ func TestKvGet(t *testing.T) {
}{
{
provider: &Provider{
Kvclient: &Mock{},
kvclient: &Mock{},
},
keys: []string{},
expected: "",
},
{
provider: &Provider{
Kvclient: &Mock{},
kvclient: &Mock{},
},
keys: []string{"traefik"},
expected: "",
},
{
provider: &Provider{
Kvclient: &Mock{
kvclient: &Mock{
KVPairs: []*store.KVPair{
{
Key: "foo",
@ -143,7 +143,7 @@ func TestKvGet(t *testing.T) {
},
{
provider: &Provider{
Kvclient: &Mock{
kvclient: &Mock{
KVPairs: []*store.KVPair{
{
Key: "foo",
@ -157,7 +157,7 @@ func TestKvGet(t *testing.T) {
},
{
provider: &Provider{
Kvclient: &Mock{
kvclient: &Mock{
KVPairs: []*store.KVPair{
{
Key: "foo/baz/1",
@ -188,7 +188,7 @@ func TestKvGet(t *testing.T) {
// Error case
provider := &Provider{
Kvclient: &Mock{
kvclient: &Mock{
Error: KvError{
Get: store.ErrKeyNotFound,
},
@ -249,7 +249,7 @@ func TestKvWatchTree(t *testing.T) {
returnedChans := make(chan chan []*store.KVPair)
provider := &KvMock{
Provider{
Kvclient: &Mock{
kvclient: &Mock{
WatchTreeMethod: func() <-chan []*store.KVPair {
c := make(chan []*store.KVPair, 10)
returnedChans <- c
@ -378,7 +378,7 @@ func (s *Mock) Close() {
func TestKVLoadConfig(t *testing.T) {
provider := &Provider{
Prefix: "traefik",
Kvclient: &Mock{
kvclient: &Mock{
KVPairs: []*store.KVPair{
{
Key: "traefik/frontends/frontend.with.dot",

View file

@ -45,14 +45,14 @@ type Provider struct {
DialerTimeout flaeg.Duration `description:"Set a non-default connection timeout for Marathon"`
KeepAlive flaeg.Duration `description:"Set a non-default TCP Keep Alive time in seconds"`
ForceTaskHostname bool `description:"Force to use the task's hostname."`
Basic *Basic
Basic *Basic `description:"Enable basic authentication"`
marathonClient marathon.Marathon
}
// Basic holds basic authentication specific configurations
type Basic struct {
HTTPBasicAuthUser string
HTTPBasicPassword string
HTTPBasicAuthUser string `description:"Basic authentication User"`
HTTPBasicPassword string `description:"Basic authentication Password"`
}
type lightMarathonClient interface {

View file

@ -25,13 +25,13 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
if err != nil {
return fmt.Errorf("Failed to Connect to KV store: %v", err)
}
p.Kvclient = store
p.SetKVClient(store)
return p.Provider.Provide(configurationChan, pool, constraints)
}
// CreateStore creates the KV store
func (p *Provider) CreateStore() (store.Store, error) {
p.StoreType = store.ZK
p.SetStoreType(store.ZK)
zookeeper.Register()
return p.Provider.CreateStore()
}