1
0
Fork 0

Update libkv dependency

This commit is contained in:
NicoMen 2017-11-17 17:22:03 +01:00 committed by Traefiker
parent cdab6b1796
commit 66e489addb
237 changed files with 62817 additions and 16116 deletions

View file

@ -3,12 +3,14 @@ package etcd
import (
"fmt"
"github.com/containous/traefik/log"
"github.com/containous/traefik/provider"
"github.com/containous/traefik/provider/kv"
"github.com/containous/traefik/safe"
"github.com/containous/traefik/types"
"github.com/docker/libkv/store"
"github.com/docker/libkv/store/etcd"
"github.com/docker/libkv/store/etcd/v2"
"github.com/docker/libkv/store/etcd/v3"
)
var _ provider.Provider = (*Provider)(nil)
@ -16,6 +18,7 @@ var _ provider.Provider = (*Provider)(nil)
// Provider holds configurations of the provider.
type Provider struct {
kv.Provider `mapstructure:",squash" export:"true"`
UseAPIV3 bool `description:"Use ETCD API V3" export:"true"`
}
// Provide allows the etcd provider to Provide configurations to traefik
@ -31,7 +34,14 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
// CreateStore creates the KV store
func (p *Provider) CreateStore() (store.Store, error) {
p.SetStoreType(store.ETCD)
etcd.Register()
if p.UseAPIV3 {
etcdv3.Register()
p.SetStoreType(store.ETCDV3)
} else {
// TODO: Deprecated
log.Warn("The ETCD API V2 is deprecated. Please use API V3 instead")
etcd.Register()
p.SetStoreType(store.ETCD)
}
return p.Provider.CreateStore()
}

View file

@ -65,7 +65,7 @@ func (p *Provider) SetKVClient(kvClient store.Store) {
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{}), nil)
if err != nil {
return fmt.Errorf("Failed to KV WatchTree: %v", err)
}
@ -102,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(p.Prefix + "/qmslkjdfmqlskdjfmqlksjazçueznbvbwzlkajzebvkwjdcqmlsfj"); err != nil {
if _, err := p.kvclient.Exists(p.Prefix+"/qmslkjdfmqlskdjfmqlksjazçueznbvbwzlkajzebvkwjdcqmlsfj", nil); err != nil {
return fmt.Errorf("Failed to test KV store connection: %v", err)
}
if p.Watch {
@ -165,7 +165,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, nil)
if err != nil {
log.Debugf("Cannot get keys %s %s ", joinedKeys, err)
return nil
@ -182,7 +182,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, nil); err != nil {
if err != store.ErrKeyNotFound {
log.Errorf("Failed to retrieve value for key %s: %s", key, err)
}
@ -194,7 +194,10 @@ 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, "/"))
if p.storeType == store.ETCD {
joinedKeys = strings.TrimPrefix(joinedKeys, "/")
}
keyPair, err := p.kvclient.Get(joinedKeys, nil)
if err != nil {
log.Debugf("Cannot get key %s %s, setting default %s", joinedKeys, err, defaultValue)
return defaultValue
@ -207,7 +210,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, nil)
if err != nil {
log.Debugf("Cannot get key %s %s, setting default empty", joinedKeys, err)
return []string{}
@ -225,7 +228,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, nil)
value := ""
if err == nil && keyPair != nil && keyPair.Value != nil {

View file

@ -33,7 +33,7 @@ func (s *Mock) Put(key string, value []byte, opts *store.WriteOptions) error {
return errors.New("Put not supported")
}
func (s *Mock) Get(key string) (*store.KVPair, error) {
func (s *Mock) Get(key string, options *store.ReadOptions) (*store.KVPair, error) {
if err := s.Error.Get; err != nil {
return nil, err
}
@ -50,7 +50,7 @@ func (s *Mock) Delete(key string) error {
}
// Exists mock
func (s *Mock) Exists(key string) (bool, error) {
func (s *Mock) Exists(key string, options *store.ReadOptions) (bool, error) {
if err := s.Error.Get; err != nil {
return false, err
}
@ -63,12 +63,12 @@ func (s *Mock) Exists(key string) (bool, error) {
}
// Watch mock
func (s *Mock) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error) {
func (s *Mock) Watch(key string, stopCh <-chan struct{}, options *store.ReadOptions) (<-chan *store.KVPair, error) {
return nil, errors.New("Watch not supported")
}
// WatchTree mock
func (s *Mock) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) {
func (s *Mock) WatchTree(prefix string, stopCh <-chan struct{}, options *store.ReadOptions) (<-chan []*store.KVPair, error) {
return s.WatchTreeMethod(), nil
}
@ -78,7 +78,7 @@ func (s *Mock) NewLock(key string, options *store.LockOptions) (store.Locker, er
}
// List mock
func (s *Mock) List(prefix string) ([]*store.KVPair, error) {
func (s *Mock) List(prefix string, options *store.ReadOptions) ([]*store.KVPair, error) {
if err := s.Error.List; err != nil {
return nil, err
}

View file

@ -383,7 +383,7 @@ func TestKVHasStickinessLabel(t *testing.T) {
desc: "with cookie name without stickiness=true",
KVPairs: []*store.KVPair{
{
Key: "loadbalancer/stickiness/cookiename",
Key: "/loadbalancer/stickiness/cookiename",
Value: []byte("foo"),
},
},
@ -393,7 +393,7 @@ func TestKVHasStickinessLabel(t *testing.T) {
desc: "stickiness=true",
KVPairs: []*store.KVPair{
{
Key: "loadbalancer/stickiness",
Key: "/loadbalancer/stickiness",
Value: []byte("true"),
},
},