Helper func to connect to etcd

This commit is contained in:
Soam Vasani
2016-09-20 21:58:53 -07:00
parent 16a75c8887
commit fee2fb1d70
+15
View File
@@ -19,6 +19,7 @@ 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"
@@ -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" {