Unexport Kvclient & StoreType from kv Provider
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
3a4ec19817
commit
aa4ed088bb
6 changed files with 44 additions and 34 deletions
|
@ -25,13 +25,13 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to Connect to KV store: %v", err)
|
return fmt.Errorf("Failed to Connect to KV store: %v", err)
|
||||||
}
|
}
|
||||||
p.Kvclient = store
|
p.SetKVClient(store)
|
||||||
return p.Provider.Provide(configurationChan, pool, constraints)
|
return p.Provider.Provide(configurationChan, pool, constraints)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateStore creates the KV store
|
// CreateStore creates the KV store
|
||||||
func (p *Provider) CreateStore() (store.Store, error) {
|
func (p *Provider) CreateStore() (store.Store, error) {
|
||||||
p.StoreType = store.BOLTDB
|
p.SetStoreType(store.BOLTDB)
|
||||||
boltdb.Register()
|
boltdb.Register()
|
||||||
return p.Provider.CreateStore()
|
return p.Provider.CreateStore()
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,13 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to Connect to KV store: %v", err)
|
return fmt.Errorf("Failed to Connect to KV store: %v", err)
|
||||||
}
|
}
|
||||||
p.Kvclient = store
|
p.SetKVClient(store)
|
||||||
return p.Provider.Provide(configurationChan, pool, constraints)
|
return p.Provider.Provide(configurationChan, pool, constraints)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateStore creates the KV store
|
// CreateStore creates the KV store
|
||||||
func (p *Provider) CreateStore() (store.Store, error) {
|
func (p *Provider) CreateStore() (store.Store, error) {
|
||||||
p.StoreType = store.CONSUL
|
p.SetStoreType(store.CONSUL)
|
||||||
consul.Register()
|
consul.Register()
|
||||||
return p.Provider.CreateStore()
|
return p.Provider.CreateStore()
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,13 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to Connect to KV store: %v", err)
|
return fmt.Errorf("Failed to Connect to KV store: %v", err)
|
||||||
}
|
}
|
||||||
p.Kvclient = store
|
p.SetKVClient(store)
|
||||||
return p.Provider.Provide(configurationChan, pool, constraints)
|
return p.Provider.Provide(configurationChan, pool, constraints)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateStore creates the KV store
|
// CreateStore creates the KV store
|
||||||
func (p *Provider) CreateStore() (store.Store, error) {
|
func (p *Provider) CreateStore() (store.Store, error) {
|
||||||
p.StoreType = store.ETCD
|
p.SetStoreType(store.ETCD)
|
||||||
etcd.Register()
|
etcd.Register()
|
||||||
return p.Provider.CreateStore()
|
return p.Provider.CreateStore()
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@ type Provider struct {
|
||||||
TLS *provider.ClientTLS `description:"Enable TLS support"`
|
TLS *provider.ClientTLS `description:"Enable TLS support"`
|
||||||
Username string `description:"KV Username"`
|
Username string `description:"KV Username"`
|
||||||
Password string `description:"KV Password"`
|
Password string `description:"KV Password"`
|
||||||
StoreType store.Backend
|
storeType store.Backend
|
||||||
Kvclient store.Store
|
kvclient store.Store
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateStore create the K/V store
|
// CreateStore create the K/V store
|
||||||
|
@ -47,15 +47,25 @@ func (p *Provider) CreateStore() (store.Store, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return libkv.NewStore(
|
return libkv.NewStore(
|
||||||
p.StoreType,
|
p.storeType,
|
||||||
strings.Split(p.Endpoint, ","),
|
strings.Split(p.Endpoint, ","),
|
||||||
storeConfig,
|
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 {
|
func (p *Provider) watchKv(configurationChan chan<- types.ConfigMessage, prefix string, stop chan bool) error {
|
||||||
operation := func() 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 {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to KV WatchTree: %v", err)
|
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()
|
configuration := p.loadConfig()
|
||||||
if configuration != nil {
|
if configuration != nil {
|
||||||
configurationChan <- types.ConfigMessage{
|
configurationChan <- types.ConfigMessage{
|
||||||
ProviderName: string(p.StoreType),
|
ProviderName: string(p.storeType),
|
||||||
Configuration: configuration,
|
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 {
|
func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints types.Constraints) error {
|
||||||
p.Constraints = append(p.Constraints, constraints...)
|
p.Constraints = append(p.Constraints, constraints...)
|
||||||
operation := func() error {
|
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)
|
return fmt.Errorf("Failed to test KV store connection: %v", err)
|
||||||
}
|
}
|
||||||
if p.Watch {
|
if p.Watch {
|
||||||
|
@ -105,7 +115,7 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
|
||||||
}
|
}
|
||||||
configuration := p.loadConfig()
|
configuration := p.loadConfig()
|
||||||
configurationChan <- types.ConfigMessage{
|
configurationChan <- types.ConfigMessage{
|
||||||
ProviderName: string(p.StoreType),
|
ProviderName: string(p.storeType),
|
||||||
Configuration: configuration,
|
Configuration: configuration,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -152,7 +162,7 @@ func (p *Provider) loadConfig() *types.Configuration {
|
||||||
|
|
||||||
func (p *Provider) list(keys ...string) []string {
|
func (p *Provider) list(keys ...string) []string {
|
||||||
joinedKeys := strings.Join(keys, "")
|
joinedKeys := strings.Join(keys, "")
|
||||||
keysPairs, err := p.Kvclient.List(joinedKeys)
|
keysPairs, err := p.kvclient.List(joinedKeys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Cannot get keys %s %s ", joinedKeys, err)
|
log.Debugf("Cannot get keys %s %s ", joinedKeys, err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -169,7 +179,7 @@ func (p *Provider) listServers(backend string) []string {
|
||||||
serverNames := p.list(backend, "/servers/")
|
serverNames := p.list(backend, "/servers/")
|
||||||
return fun.Filter(func(serverName string) bool {
|
return fun.Filter(func(serverName string) bool {
|
||||||
key := fmt.Sprint(serverName, "/url")
|
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 {
|
if err != store.ErrKeyNotFound {
|
||||||
log.Errorf("Failed to retrieve value for key %s: %s", key, err)
|
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 {
|
func (p *Provider) get(defaultValue string, keys ...string) string {
|
||||||
joinedKeys := strings.Join(keys, "")
|
joinedKeys := strings.Join(keys, "")
|
||||||
keyPair, err := p.Kvclient.Get(strings.TrimPrefix(joinedKeys, "/"))
|
keyPair, err := p.kvclient.Get(strings.TrimPrefix(joinedKeys, "/"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Cannot get key %s %s, setting default %s", joinedKeys, err, defaultValue)
|
log.Debugf("Cannot get key %s %s, setting default %s", joinedKeys, err, defaultValue)
|
||||||
return defaultValue
|
return defaultValue
|
||||||
|
@ -194,7 +204,7 @@ func (p *Provider) get(defaultValue string, keys ...string) string {
|
||||||
|
|
||||||
func (p *Provider) splitGet(keys ...string) []string {
|
func (p *Provider) splitGet(keys ...string) []string {
|
||||||
joinedKeys := strings.Join(keys, "")
|
joinedKeys := strings.Join(keys, "")
|
||||||
keyPair, err := p.Kvclient.Get(joinedKeys)
|
keyPair, err := p.kvclient.Get(joinedKeys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Cannot get key %s %s, setting default empty", joinedKeys, err)
|
log.Debugf("Cannot get key %s %s, setting default empty", joinedKeys, err)
|
||||||
return []string{}
|
return []string{}
|
||||||
|
@ -212,7 +222,7 @@ func (p *Provider) last(key string) string {
|
||||||
|
|
||||||
func (p *Provider) checkConstraints(keys ...string) bool {
|
func (p *Provider) checkConstraints(keys ...string) bool {
|
||||||
joinedKeys := strings.Join(keys, "")
|
joinedKeys := strings.Join(keys, "")
|
||||||
keyPair, err := p.Kvclient.Get(joinedKeys)
|
keyPair, err := p.kvclient.Get(joinedKeys)
|
||||||
|
|
||||||
value := ""
|
value := ""
|
||||||
if err == nil && keyPair != nil && keyPair.Value != nil {
|
if err == nil && keyPair != nil && keyPair.Value != nil {
|
||||||
|
|
|
@ -20,21 +20,21 @@ func TestKvList(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{},
|
kvclient: &Mock{},
|
||||||
},
|
},
|
||||||
keys: []string{},
|
keys: []string{},
|
||||||
expected: []string{},
|
expected: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{},
|
kvclient: &Mock{},
|
||||||
},
|
},
|
||||||
keys: []string{"traefik"},
|
keys: []string{"traefik"},
|
||||||
expected: []string{},
|
expected: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
KVPairs: []*store.KVPair{
|
KVPairs: []*store.KVPair{
|
||||||
{
|
{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
|
@ -48,7 +48,7 @@ func TestKvList(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
KVPairs: []*store.KVPair{
|
KVPairs: []*store.KVPair{
|
||||||
{
|
{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
|
@ -62,7 +62,7 @@ func TestKvList(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
KVPairs: []*store.KVPair{
|
KVPairs: []*store.KVPair{
|
||||||
{
|
{
|
||||||
Key: "foo/baz/1",
|
Key: "foo/baz/1",
|
||||||
|
@ -95,7 +95,7 @@ func TestKvList(t *testing.T) {
|
||||||
|
|
||||||
// Error case
|
// Error case
|
||||||
provider := &Provider{
|
provider := &Provider{
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
Error: KvError{
|
Error: KvError{
|
||||||
List: store.ErrKeyNotFound,
|
List: store.ErrKeyNotFound,
|
||||||
},
|
},
|
||||||
|
@ -115,21 +115,21 @@ func TestKvGet(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{},
|
kvclient: &Mock{},
|
||||||
},
|
},
|
||||||
keys: []string{},
|
keys: []string{},
|
||||||
expected: "",
|
expected: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{},
|
kvclient: &Mock{},
|
||||||
},
|
},
|
||||||
keys: []string{"traefik"},
|
keys: []string{"traefik"},
|
||||||
expected: "",
|
expected: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
KVPairs: []*store.KVPair{
|
KVPairs: []*store.KVPair{
|
||||||
{
|
{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
|
@ -143,7 +143,7 @@ func TestKvGet(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
KVPairs: []*store.KVPair{
|
KVPairs: []*store.KVPair{
|
||||||
{
|
{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
|
@ -157,7 +157,7 @@ func TestKvGet(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: &Provider{
|
provider: &Provider{
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
KVPairs: []*store.KVPair{
|
KVPairs: []*store.KVPair{
|
||||||
{
|
{
|
||||||
Key: "foo/baz/1",
|
Key: "foo/baz/1",
|
||||||
|
@ -188,7 +188,7 @@ func TestKvGet(t *testing.T) {
|
||||||
|
|
||||||
// Error case
|
// Error case
|
||||||
provider := &Provider{
|
provider := &Provider{
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
Error: KvError{
|
Error: KvError{
|
||||||
Get: store.ErrKeyNotFound,
|
Get: store.ErrKeyNotFound,
|
||||||
},
|
},
|
||||||
|
@ -249,7 +249,7 @@ func TestKvWatchTree(t *testing.T) {
|
||||||
returnedChans := make(chan chan []*store.KVPair)
|
returnedChans := make(chan chan []*store.KVPair)
|
||||||
provider := &KvMock{
|
provider := &KvMock{
|
||||||
Provider{
|
Provider{
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
WatchTreeMethod: func() <-chan []*store.KVPair {
|
WatchTreeMethod: func() <-chan []*store.KVPair {
|
||||||
c := make(chan []*store.KVPair, 10)
|
c := make(chan []*store.KVPair, 10)
|
||||||
returnedChans <- c
|
returnedChans <- c
|
||||||
|
@ -378,7 +378,7 @@ func (s *Mock) Close() {
|
||||||
func TestKVLoadConfig(t *testing.T) {
|
func TestKVLoadConfig(t *testing.T) {
|
||||||
provider := &Provider{
|
provider := &Provider{
|
||||||
Prefix: "traefik",
|
Prefix: "traefik",
|
||||||
Kvclient: &Mock{
|
kvclient: &Mock{
|
||||||
KVPairs: []*store.KVPair{
|
KVPairs: []*store.KVPair{
|
||||||
{
|
{
|
||||||
Key: "traefik/frontends/frontend.with.dot",
|
Key: "traefik/frontends/frontend.with.dot",
|
||||||
|
|
|
@ -25,13 +25,13 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to Connect to KV store: %v", err)
|
return fmt.Errorf("Failed to Connect to KV store: %v", err)
|
||||||
}
|
}
|
||||||
p.Kvclient = store
|
p.SetKVClient(store)
|
||||||
return p.Provider.Provide(configurationChan, pool, constraints)
|
return p.Provider.Provide(configurationChan, pool, constraints)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateStore creates the KV store
|
// CreateStore creates the KV store
|
||||||
func (p *Provider) CreateStore() (store.Store, error) {
|
func (p *Provider) CreateStore() (store.Store, error) {
|
||||||
p.StoreType = store.ZK
|
p.SetStoreType(store.ZK)
|
||||||
zookeeper.Register()
|
zookeeper.Register()
|
||||||
return p.Provider.CreateStore()
|
return p.Provider.CreateStore()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue