Helper func to connect to etcd
This commit is contained in:
@@ -19,7 +19,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/coreos/etcd/client"
|
"github.com/coreos/etcd/client"
|
||||||
"github.com/satori/go.uuid"
|
"github.com/satori/go.uuid"
|
||||||
@@ -38,6 +39,20 @@ func makeResourceStore(fs *fileStore, ks client.KeysAPI, s serializer) *resource
|
|||||||
return &resourceStore{fileStore: fs, KeysAPI: ks, serializer: s}
|
return &resourceStore{fileStore: fs, KeysAPI: ks, serializer: s}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEtcdKeyAPI(etcdUrls []string) client.KeysAPI {
|
||||||
|
cfg := client.Config{
|
||||||
|
Endpoints: etcdUrls,
|
||||||
|
Transport: client.DefaultTransport,
|
||||||
|
// set timeout per request to fail fast when the target endpoint is unavailable
|
||||||
|
HeaderTimeoutPerRequest: time.Second,
|
||||||
|
}
|
||||||
|
c, err := client.New(cfg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to connect to etcd: %v", err)
|
||||||
|
}
|
||||||
|
return client.NewKeysAPI(c)
|
||||||
|
}
|
||||||
|
|
||||||
func getTypeName(r resource) (string, error) {
|
func getTypeName(r resource) (string, error) {
|
||||||
typ := reflect.TypeOf(r)
|
typ := reflect.TypeOf(r)
|
||||||
if typ.Kind().String() == "ptr" {
|
if typ.Kind().String() == "ptr" {
|
||||||
|
|||||||
Reference in New Issue
Block a user