Private EtcdHelper
This commit is contained in:
@@ -37,7 +37,7 @@ type REST struct {
|
||||
var controllerPrefix = "/controllers"
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against replication controllers.
|
||||
func NewREST(h tools.EtcdHelper) *REST {
|
||||
func NewREST(s tools.StorageInterface) *REST {
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.ReplicationController{} },
|
||||
|
||||
@@ -69,7 +69,7 @@ func NewREST(h tools.EtcdHelper) *REST {
|
||||
// Used to validate controller updates
|
||||
UpdateStrategy: controller.Strategy,
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
|
||||
return &REST{store}
|
||||
|
@@ -40,17 +40,17 @@ const (
|
||||
FAIL
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
// newStorage creates a REST storage backed by etcd helpers
|
||||
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
storage := NewREST(h)
|
||||
fakeEtcdClient, s := newEtcdStorage(t)
|
||||
storage := NewREST(s)
|
||||
return storage, fakeEtcdClient
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@ type REST struct {
|
||||
}
|
||||
|
||||
// NewStorage returns a RESTStorage object that will work against endpoints.
|
||||
func NewStorage(h tools.EtcdHelper) *REST {
|
||||
func NewStorage(s tools.StorageInterface) *REST {
|
||||
prefix := "/services/endpoints"
|
||||
return &REST{
|
||||
&etcdgeneric.Etcd{
|
||||
@@ -56,7 +56,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
|
||||
CreateStrategy: endpoint.Strategy,
|
||||
UpdateStrategy: endpoint.Strategy,
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -32,16 +32,16 @@ import (
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
storage := NewStorage(h)
|
||||
fakeEtcdClient, s := newEtcdStorage(t)
|
||||
storage := NewStorage(s)
|
||||
return storage, fakeEtcdClient
|
||||
}
|
||||
|
||||
|
@@ -44,17 +44,17 @@ const (
|
||||
// Registry implements BindingRegistry, ControllerRegistry, EndpointRegistry,
|
||||
// MinionRegistry, PodRegistry and ServiceRegistry, backed by etcd.
|
||||
type Registry struct {
|
||||
tools.EtcdHelper
|
||||
tools.StorageInterface
|
||||
pods pod.Registry
|
||||
endpoints endpoint.Registry
|
||||
}
|
||||
|
||||
// NewRegistry creates an etcd registry.
|
||||
func NewRegistry(helper tools.EtcdHelper, pods pod.Registry, endpoints endpoint.Registry) *Registry {
|
||||
func NewRegistry(storage tools.StorageInterface, pods pod.Registry, endpoints endpoint.Registry) *Registry {
|
||||
registry := &Registry{
|
||||
EtcdHelper: helper,
|
||||
pods: pods,
|
||||
endpoints: endpoints,
|
||||
StorageInterface: storage,
|
||||
pods: pods,
|
||||
endpoints: endpoints,
|
||||
}
|
||||
return registry
|
||||
}
|
||||
|
@@ -38,16 +38,16 @@ import (
|
||||
)
|
||||
|
||||
func NewTestEtcdRegistry(client tools.EtcdClient) *Registry {
|
||||
helper := tools.NewEtcdHelper(client, latest.Codec, etcdtest.PathPrefix())
|
||||
registry := NewRegistry(helper, nil, nil)
|
||||
storage := tools.NewEtcdStorage(client, latest.Codec, etcdtest.PathPrefix())
|
||||
registry := NewRegistry(storage, nil, nil)
|
||||
return registry
|
||||
}
|
||||
|
||||
func NewTestEtcdRegistryWithPods(client tools.EtcdClient) *Registry {
|
||||
helper := tools.NewEtcdHelper(client, latest.Codec, etcdtest.PathPrefix())
|
||||
podStorage := podetcd.NewStorage(helper, nil)
|
||||
endpointStorage := endpointetcd.NewStorage(helper)
|
||||
registry := NewRegistry(helper, pod.NewRegistry(podStorage.Pod), endpoint.NewRegistry(endpointStorage))
|
||||
etcdStorage := tools.NewEtcdStorage(client, latest.Codec, etcdtest.PathPrefix())
|
||||
podStorage := podetcd.NewStorage(etcdStorage, nil)
|
||||
endpointStorage := endpointetcd.NewStorage(etcdStorage)
|
||||
registry := NewRegistry(etcdStorage, pod.NewRegistry(podStorage.Pod), endpoint.NewRegistry(endpointStorage))
|
||||
return registry
|
||||
}
|
||||
|
||||
|
@@ -30,8 +30,8 @@ type registry struct {
|
||||
}
|
||||
|
||||
// NewEtcdRegistry returns a registry which will store Events in the given
|
||||
// EtcdHelper. ttl is the time that Events will be retained by the system.
|
||||
func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
|
||||
// EtcdStorage. ttl is the time that Events will be retained by the system.
|
||||
func NewEtcdRegistry(s tools.StorageInterface, ttl uint64) generic.Registry {
|
||||
prefix := "/events"
|
||||
return registry{
|
||||
Etcd: &etcdgeneric.Etcd{
|
||||
@@ -47,7 +47,7 @@ func NewEtcdRegistry(h tools.EtcdHelper, ttl uint64) generic.Registry {
|
||||
TTLFunc: func(runtime.Object, uint64, bool) (uint64, error) {
|
||||
return ttl, nil
|
||||
},
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -39,8 +39,8 @@ func NewTestEventEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, generic.Regi
|
||||
f := tools.NewFakeEtcdClient(t)
|
||||
f.TestIndex = true
|
||||
|
||||
h := tools.NewEtcdHelper(f, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return f, NewEtcdRegistry(h, testTTL)
|
||||
s := tools.NewEtcdStorage(f, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return f, NewEtcdRegistry(s, testTTL)
|
||||
}
|
||||
|
||||
func TestEventCreate(t *testing.T) {
|
||||
|
@@ -103,7 +103,7 @@ type Etcd struct {
|
||||
ReturnDeletedObject bool
|
||||
|
||||
// Used for all etcd access functions
|
||||
Helper tools.EtcdHelper
|
||||
Storage tools.StorageInterface
|
||||
}
|
||||
|
||||
// NamespaceKeyRootFunc is the default function for constructing etcd paths to resource directories enforcing namespace rules.
|
||||
@@ -157,14 +157,14 @@ func (e *Etcd) ListPredicate(ctx api.Context, m generic.Matcher) (runtime.Object
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = e.Helper.ExtractObjToList(key, list)
|
||||
err = e.Storage.ExtractObjToList(key, list)
|
||||
trace.Step("Object extracted")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
trace.Step("About to list directory")
|
||||
err := e.Helper.ExtractToList(e.KeyRootFunc(ctx), list)
|
||||
err := e.Storage.ExtractToList(e.KeyRootFunc(ctx), list)
|
||||
trace.Step("List extracted")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -190,7 +190,7 @@ func (e *Etcd) CreateWithName(ctx api.Context, name string, obj runtime.Object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = e.Helper.CreateObj(key, obj, nil, ttl)
|
||||
err = e.Storage.CreateObj(key, obj, nil, ttl)
|
||||
err = etcderr.InterpretCreateError(err, e.EndpointName, name)
|
||||
if err == nil && e.Decorator != nil {
|
||||
err = e.Decorator(obj)
|
||||
@@ -219,7 +219,7 @@ func (e *Etcd) Create(ctx api.Context, obj runtime.Object) (runtime.Object, erro
|
||||
}
|
||||
trace.Step("About to create object")
|
||||
out := e.NewFunc()
|
||||
if err := e.Helper.CreateObj(key, obj, out, ttl); err != nil {
|
||||
if err := e.Storage.CreateObj(key, obj, out, ttl); err != nil {
|
||||
err = etcderr.InterpretCreateError(err, e.EndpointName, name)
|
||||
err = rest.CheckGeneratedNameError(e.CreateStrategy, err, obj)
|
||||
return nil, err
|
||||
@@ -249,7 +249,7 @@ func (e *Etcd) UpdateWithName(ctx api.Context, name string, obj runtime.Object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = e.Helper.SetObj(key, obj, nil, ttl)
|
||||
err = e.Storage.SetObj(key, obj, nil, ttl)
|
||||
err = etcderr.InterpretUpdateError(err, e.EndpointName, name)
|
||||
if err == nil && e.Decorator != nil {
|
||||
err = e.Decorator(obj)
|
||||
@@ -274,7 +274,7 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
|
||||
// If AllowUnconditionalUpdate() is true and the object specified by the user does not have a resource version,
|
||||
// then we populate it with the latest version.
|
||||
// Else, we check that the version specified by the user matches the version of latest etcd object.
|
||||
resourceVersion, err := e.Helper.Versioner.ObjectResourceVersion(obj)
|
||||
resourceVersion, err := e.Storage.Versioner().ObjectResourceVersion(obj)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -282,8 +282,8 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
|
||||
// TODO: expose TTL
|
||||
creating := false
|
||||
out := e.NewFunc()
|
||||
err = e.Helper.GuaranteedUpdate(key, out, true, func(existing runtime.Object, res tools.ResponseMeta) (runtime.Object, *uint64, error) {
|
||||
version, err := e.Helper.Versioner.ObjectResourceVersion(existing)
|
||||
err = e.Storage.GuaranteedUpdate(key, out, true, func(existing runtime.Object, res tools.ResponseMeta) (runtime.Object, *uint64, error) {
|
||||
version, err := e.Storage.Versioner().ObjectResourceVersion(existing)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -305,13 +305,13 @@ func (e *Etcd) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool
|
||||
creating = false
|
||||
if doUnconditionalUpdate {
|
||||
// Update the object's resource version to match the latest etcd object's resource version.
|
||||
err = e.Helper.Versioner.UpdateObject(obj, res.Expiration, res.ResourceVersion)
|
||||
err = e.Storage.Versioner().UpdateObject(obj, res.Expiration, res.ResourceVersion)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
} else {
|
||||
// Check if the object's resource version matches the latest resource version.
|
||||
newVersion, err := e.Helper.Versioner.ObjectResourceVersion(obj)
|
||||
newVersion, err := e.Storage.Versioner().ObjectResourceVersion(obj)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -372,7 +372,7 @@ func (e *Etcd) Get(ctx api.Context, name string) (runtime.Object, error) {
|
||||
return nil, err
|
||||
}
|
||||
trace.Step("About to read object")
|
||||
if err := e.Helper.ExtractObj(key, obj, false); err != nil {
|
||||
if err := e.Storage.ExtractObj(key, obj, false); err != nil {
|
||||
return nil, etcderr.InterpretGetError(err, e.EndpointName, name)
|
||||
}
|
||||
trace.Step("Object read")
|
||||
@@ -395,7 +395,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
|
||||
trace := util.NewTrace("Delete " + reflect.TypeOf(obj).String())
|
||||
defer trace.LogIfLong(time.Second)
|
||||
trace.Step("About to read object")
|
||||
if err := e.Helper.ExtractObj(key, obj, false); err != nil {
|
||||
if err := e.Storage.ExtractObj(key, obj, false); err != nil {
|
||||
return nil, etcderr.InterpretDeleteError(err, e.EndpointName, name)
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
|
||||
if graceful && *options.GracePeriodSeconds != 0 {
|
||||
trace.Step("Graceful deletion")
|
||||
out := e.NewFunc()
|
||||
if err := e.Helper.SetObj(key, obj, out, uint64(*options.GracePeriodSeconds)); err != nil {
|
||||
if err := e.Storage.SetObj(key, obj, out, uint64(*options.GracePeriodSeconds)); err != nil {
|
||||
return nil, etcderr.InterpretUpdateError(err, e.EndpointName, name)
|
||||
}
|
||||
return e.finalizeDelete(out, true)
|
||||
@@ -422,7 +422,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions)
|
||||
// delete immediately, or no graceful deletion supported
|
||||
out := e.NewFunc()
|
||||
trace.Step("About to delete object")
|
||||
if err := e.Helper.DeleteObj(key, out); err != nil {
|
||||
if err := e.Storage.DeleteObj(key, out); err != nil {
|
||||
return nil, etcderr.InterpretDeleteError(err, e.EndpointName, name)
|
||||
}
|
||||
return e.finalizeDelete(out, true)
|
||||
@@ -480,10 +480,10 @@ func (e *Etcd) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersio
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.Helper.Watch(key, version, filterFunc)
|
||||
return e.Storage.Watch(key, version, filterFunc)
|
||||
}
|
||||
|
||||
return e.Helper.WatchList(e.KeyRootFunc(ctx), version, filterFunc)
|
||||
return e.Storage.WatchList(e.KeyRootFunc(ctx), version, filterFunc)
|
||||
}
|
||||
|
||||
// calculateTTL is a helper for retrieving the updated TTL for an object or returning an error
|
||||
|
@@ -69,7 +69,7 @@ func hasCreated(t *testing.T, pod *api.Pod) func(runtime.Object) bool {
|
||||
func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
|
||||
f := tools.NewFakeEtcdClient(t)
|
||||
f.TestIndex = true
|
||||
h := tools.NewEtcdHelper(f, testapi.Codec(), etcdtest.PathPrefix())
|
||||
s := tools.NewEtcdStorage(f, testapi.Codec(), etcdtest.PathPrefix())
|
||||
strategy := &testRESTStrategy{api.Scheme, api.SimpleNameGenerator, true, false, true}
|
||||
podPrefix := "/pods"
|
||||
return f, &Etcd{
|
||||
@@ -85,7 +85,7 @@ func NewTestGenericEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, *Etcd) {
|
||||
return path.Join(podPrefix, id), nil
|
||||
},
|
||||
ObjectNameFunc: func(obj runtime.Object) (string, error) { return obj.(*api.Pod).Name, nil },
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -141,7 +141,7 @@ type Registry interface {
|
||||
// provided that 'm' works with the concrete type of list. d is an optional
|
||||
// decorator for the returned functions. Only matching items are decorated.
|
||||
func FilterList(list runtime.Object, m Matcher, d DecoratorFunc) (filtered runtime.Object, err error) {
|
||||
// TODO: push a matcher down into tools.EtcdHelper to avoid all this
|
||||
// TODO: push a matcher down into tools.etcdHelper to avoid all this
|
||||
// nonsense. This is a lot of unnecessary copies.
|
||||
items, err := runtime.ExtractList(list)
|
||||
if err != nil {
|
||||
|
@@ -29,8 +29,8 @@ type registry struct {
|
||||
*etcdgeneric.Etcd
|
||||
}
|
||||
|
||||
// NewEtcdRegistry returns a registry which will store LimitRange in the given helper
|
||||
func NewEtcdRegistry(h tools.EtcdHelper) generic.Registry {
|
||||
// NewEtcdRegistry returns a registry which will store LimitRange in the given storage
|
||||
func NewEtcdRegistry(s tools.StorageInterface) generic.Registry {
|
||||
prefix := "/limitranges"
|
||||
return registry{
|
||||
Etcd: &etcdgeneric.Etcd{
|
||||
@@ -43,7 +43,7 @@ func NewEtcdRegistry(h tools.EtcdHelper) generic.Registry {
|
||||
KeyFunc: func(ctx api.Context, id string) (string, error) {
|
||||
return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
|
||||
},
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -37,8 +37,8 @@ import (
|
||||
func NewTestLimitRangeEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, generic.Registry) {
|
||||
f := tools.NewFakeEtcdClient(t)
|
||||
f.TestIndex = true
|
||||
h := tools.NewEtcdHelper(f, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return f, NewEtcdRegistry(h)
|
||||
s := tools.NewEtcdStorage(f, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return f, NewEtcdRegistry(s)
|
||||
}
|
||||
|
||||
func TestLimitRangeCreate(t *testing.T) {
|
||||
|
@@ -49,7 +49,7 @@ func (r *StatusREST) Update(ctx api.Context, obj runtime.Object) (runtime.Object
|
||||
}
|
||||
|
||||
// NewStorage returns a RESTStorage object that will work against nodes.
|
||||
func NewStorage(h tools.EtcdHelper, connection client.ConnectionInfoGetter) (*REST, *StatusREST) {
|
||||
func NewStorage(s tools.StorageInterface, connection client.ConnectionInfoGetter) (*REST, *StatusREST) {
|
||||
prefix := "/minions"
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.Node{} },
|
||||
@@ -69,7 +69,7 @@ func NewStorage(h tools.EtcdHelper, connection client.ConnectionInfoGetter) (*RE
|
||||
CreateStrategy: minion.Strategy,
|
||||
UpdateStrategy: minion.Strategy,
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
|
||||
statusStore := *store
|
||||
|
@@ -47,16 +47,16 @@ func (fakeConnectionInfoGetter) GetConnectionInfo(host string) (string, uint, ht
|
||||
return "http", 12345, nil, nil
|
||||
}
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
storage, _ := NewStorage(h, fakeConnectionInfoGetter{})
|
||||
fakeEtcdClient, s := newEtcdStorage(t)
|
||||
storage, _ := NewStorage(s, fakeConnectionInfoGetter{})
|
||||
return storage, fakeEtcdClient
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,7 @@ type FinalizeREST struct {
|
||||
}
|
||||
|
||||
// NewStorage returns a RESTStorage object that will work against namespaces
|
||||
func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST, *FinalizeREST) {
|
||||
func NewStorage(s tools.StorageInterface) (*REST, *StatusREST, *FinalizeREST) {
|
||||
prefix := "/namespaces"
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.Namespace{} },
|
||||
@@ -67,7 +67,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST, *FinalizeREST) {
|
||||
return namespace.MatchNamespace(label, field)
|
||||
},
|
||||
EndpointName: "namespaces",
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
store.CreateStrategy = namespace.Strategy
|
||||
store.UpdateStrategy = namespace.Strategy
|
||||
|
@@ -33,17 +33,17 @@ import (
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
storage, _, _ := NewStorage(h)
|
||||
return storage, fakeEtcdClient, h
|
||||
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient, s := newEtcdStorage(t)
|
||||
storage, _, _ := NewStorage(s)
|
||||
return storage, fakeEtcdClient, s
|
||||
}
|
||||
|
||||
func validNewNamespace() *api.Namespace {
|
||||
@@ -69,8 +69,8 @@ func TestStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage, _, _ := NewStorage(etcdStorage)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError).ClusterScope()
|
||||
namespace := validNewNamespace()
|
||||
namespace.ObjectMeta = api.ObjectMeta{GenerateName: "foo"}
|
||||
@@ -94,8 +94,8 @@ func expectNamespace(t *testing.T, out runtime.Object) (*api.Namespace, bool) {
|
||||
}
|
||||
|
||||
func TestCreateSetsFields(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage, _, _ := NewStorage(etcdStorage)
|
||||
namespace := validNewNamespace()
|
||||
_, err := storage.Create(api.NewContext(), namespace)
|
||||
if err != fakeEtcdClient.Err {
|
||||
@@ -108,7 +108,7 @@ func TestCreateSetsFields(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected key error: %v", err)
|
||||
}
|
||||
if err := helper.ExtractObj(key, actual, false); err != nil {
|
||||
if err := etcdStorage.ExtractObj(key, actual, false); err != nil {
|
||||
t.Fatalf("unexpected extraction error: %v", err)
|
||||
}
|
||||
if actual.Name != namespace.Name {
|
||||
@@ -123,7 +123,7 @@ func TestCreateSetsFields(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListEmptyNamespaceList(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.ChangeIndex = 1
|
||||
key := etcdtest.AddPrefix("/namespaces")
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
@@ -131,7 +131,7 @@ func TestListEmptyNamespaceList(t *testing.T) {
|
||||
E: fakeEtcdClient.NewError(tools.EtcdErrorCodeNotFound),
|
||||
}
|
||||
|
||||
storage, _, _ := NewStorage(helper)
|
||||
storage, _, _ := NewStorage(etcdStorage)
|
||||
namespaces, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
@@ -145,7 +145,7 @@ func TestListEmptyNamespaceList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListNamespaceList(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
key := etcdtest.AddPrefix("/namespaces")
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
@@ -165,7 +165,7 @@ func TestListNamespaceList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewStorage(helper)
|
||||
storage, _, _ := NewStorage(etcdStorage)
|
||||
namespacesObj, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
|
||||
namespaces := namespacesObj.(*api.NamespaceList)
|
||||
if err != nil {
|
||||
@@ -184,7 +184,7 @@ func TestListNamespaceList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListNamespaceListSelection(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
key := etcdtest.AddPrefix("/namespaces")
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
@@ -213,7 +213,7 @@ func TestListNamespaceListSelection(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewStorage(helper)
|
||||
storage, _, _ := NewStorage(etcdStorage)
|
||||
ctx := api.NewContext()
|
||||
table := []struct {
|
||||
label, field string
|
||||
@@ -261,8 +261,8 @@ func TestListNamespaceListSelection(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNamespaceDecode(t *testing.T) {
|
||||
_, helper := newHelper(t)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
_, etcdStorage := newEtcdStorage(t)
|
||||
storage, _, _ := NewStorage(etcdStorage)
|
||||
expected := validNewNamespace()
|
||||
expected.Status.Phase = api.NamespaceActive
|
||||
expected.Spec.Finalizers = []api.FinalizerName{api.FinalizerKubernetes}
|
||||
@@ -311,9 +311,9 @@ func TestGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteNamespace(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.ChangeIndex = 1
|
||||
storage, _, _ := NewStorage(helper)
|
||||
storage, _, _ := NewStorage(etcdStorage)
|
||||
ctx := api.NewContext()
|
||||
key, err := storage.Etcd.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
@@ -340,7 +340,7 @@ func TestDeleteNamespace(t *testing.T) {
|
||||
|
||||
func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
|
||||
now := util.Now()
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.ChangeIndex = 1
|
||||
key := etcdtest.AddPrefix("/namespaces/foo")
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
@@ -361,7 +361,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewStorage(helper)
|
||||
storage, _, _ := NewStorage(etcdStorage)
|
||||
_, err := storage.Delete(api.NewContext(), "foo", nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error: %v", err)
|
||||
@@ -370,7 +370,7 @@ func TestDeleteNamespaceWithIncompleteFinalizers(t *testing.T) {
|
||||
|
||||
func TestDeleteNamespaceWithCompleteFinalizers(t *testing.T) {
|
||||
now := util.Now()
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.ChangeIndex = 1
|
||||
key := etcdtest.AddPrefix("/namespaces/foo")
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
@@ -391,7 +391,7 @@ func TestDeleteNamespaceWithCompleteFinalizers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewStorage(helper)
|
||||
storage, _, _ := NewStorage(etcdStorage)
|
||||
_, err := storage.Delete(api.NewContext(), "foo", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
@@ -35,7 +35,7 @@ type REST struct {
|
||||
}
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against PersistentVolume objects.
|
||||
func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
||||
func NewStorage(s tools.StorageInterface) (*REST, *StatusREST) {
|
||||
prefix := "/persistentvolumes"
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.PersistentVolume{} },
|
||||
@@ -54,7 +54,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
||||
},
|
||||
EndpointName: "persistentvolume",
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
|
||||
store.CreateStrategy = persistentvolume.Strategy
|
||||
|
@@ -38,12 +38,12 @@ type testRegistry struct {
|
||||
*registrytest.GenericRegistry
|
||||
}
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
storage, statusStorage := NewStorage(helper)
|
||||
return storage, statusStorage, fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
storage, statusStorage := NewStorage(etcdStorage)
|
||||
return storage, statusStorage, fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func validNewPersistentVolume(name string) *api.PersistentVolume {
|
||||
@@ -320,7 +320,7 @@ func TestDeletePersistentVolumes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEtcdUpdateStatus(t *testing.T) {
|
||||
storage, statusStorage, fakeClient, helper := newStorage(t)
|
||||
storage, statusStorage, fakeClient, etcdStorage := newStorage(t)
|
||||
ctx := api.NewContext()
|
||||
fakeClient.TestIndex = true
|
||||
|
||||
@@ -350,7 +350,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
|
||||
}
|
||||
var pvOut api.PersistentVolume
|
||||
key, _ = storage.KeyFunc(ctx, "foo")
|
||||
if err := helper.ExtractObj(key, &pvOut, false); err != nil {
|
||||
if err := etcdStorage.ExtractObj(key, &pvOut, false); err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
if !api.Semantic.DeepEqual(expected, pvOut) {
|
||||
|
@@ -33,7 +33,7 @@ type REST struct {
|
||||
}
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against PersistentVolumeClaim objects.
|
||||
func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
||||
func NewStorage(s tools.StorageInterface) (*REST, *StatusREST) {
|
||||
prefix := "/persistentvolumeclaims"
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.PersistentVolumeClaim{} },
|
||||
@@ -52,7 +52,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
||||
},
|
||||
EndpointName: "persistentvolumeclaims",
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
|
||||
store.CreateStrategy = persistentvolumeclaim.Strategy
|
||||
|
@@ -38,12 +38,12 @@ type testRegistry struct {
|
||||
*registrytest.GenericRegistry
|
||||
}
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
storage, statusStorage := NewStorage(helper)
|
||||
return storage, statusStorage, fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
storage, statusStorage := NewStorage(etcdStorage)
|
||||
return storage, statusStorage, fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func validNewPersistentVolumeClaim(name, ns string) *api.PersistentVolumeClaim {
|
||||
@@ -318,7 +318,7 @@ func TestDeletePersistentVolumeClaims(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEtcdUpdateStatus(t *testing.T) {
|
||||
storage, statusStorage, fakeClient, helper := newStorage(t)
|
||||
storage, statusStorage, fakeClient, etcdStorage := newStorage(t)
|
||||
ctx := api.NewDefaultContext()
|
||||
fakeClient.TestIndex = true
|
||||
|
||||
@@ -357,7 +357,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
|
||||
}
|
||||
var pvcOut api.PersistentVolumeClaim
|
||||
key, _ = storage.KeyFunc(ctx, "foo")
|
||||
if err := helper.ExtractObj(key, &pvcOut, false); err != nil {
|
||||
if err := etcdStorage.ExtractObj(key, &pvcOut, false); err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
if !api.Semantic.DeepEqual(expected, pvcOut) {
|
||||
|
@@ -55,7 +55,7 @@ type REST struct {
|
||||
}
|
||||
|
||||
// NewStorage returns a RESTStorage object that will work against pods.
|
||||
func NewStorage(h tools.EtcdHelper, k client.ConnectionInfoGetter) PodStorage {
|
||||
func NewStorage(s tools.StorageInterface, k client.ConnectionInfoGetter) PodStorage {
|
||||
prefix := "/pods"
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.Pod{} },
|
||||
@@ -74,7 +74,7 @@ func NewStorage(h tools.EtcdHelper, k client.ConnectionInfoGetter) PodStorage {
|
||||
},
|
||||
EndpointName: "pods",
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
statusStore := *store
|
||||
|
||||
@@ -142,7 +142,7 @@ func (r *BindingREST) setPodHostAndAnnotations(ctx api.Context, podID, oldMachin
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = r.store.Helper.GuaranteedUpdate(podKey, &api.Pod{}, false, tools.SimpleUpdate(func(obj runtime.Object) (runtime.Object, error) {
|
||||
err = r.store.Storage.GuaranteedUpdate(podKey, &api.Pod{}, false, tools.SimpleUpdate(func(obj runtime.Object) (runtime.Object, error) {
|
||||
pod, ok := obj.(*api.Pod)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected object: %#v", obj)
|
||||
|
@@ -40,17 +40,17 @@ import (
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *BindingREST, *StatusREST, *tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
storage := NewStorage(h, nil)
|
||||
return storage.Pod, storage.Binding, storage.Status, fakeEtcdClient, h
|
||||
func newStorage(t *testing.T) (*REST, *BindingREST, *StatusREST, *tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil)
|
||||
return storage.Pod, storage.Binding, storage.Status, fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func validNewPod() *api.Pod {
|
||||
@@ -91,8 +91,8 @@ func TestStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
pod := validNewPod()
|
||||
pod.ObjectMeta = api.ObjectMeta{}
|
||||
@@ -109,8 +109,8 @@ func TestCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
ctx := api.NewDefaultContext()
|
||||
key, _ := storage.Etcd.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
@@ -147,9 +147,9 @@ func expectPod(t *testing.T, out runtime.Object) (*api.Pod, bool) {
|
||||
}
|
||||
|
||||
func TestCreateRegistryError(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
|
||||
pod := validNewPod()
|
||||
_, err := storage.Create(api.NewDefaultContext(), pod)
|
||||
@@ -159,8 +159,8 @@ func TestCreateRegistryError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateSetsFields(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
pod := validNewPod()
|
||||
_, err := storage.Create(api.NewDefaultContext(), pod)
|
||||
if err != fakeEtcdClient.Err {
|
||||
@@ -169,7 +169,7 @@ func TestCreateSetsFields(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
key, _ := storage.Etcd.KeyFunc(ctx, "foo")
|
||||
actual := &api.Pod{}
|
||||
if err := helper.ExtractObj(key, actual, false); err != nil {
|
||||
if err := etcdStorage.ExtractObj(key, actual, false); err != nil {
|
||||
t.Fatalf("unexpected extraction error: %v", err)
|
||||
}
|
||||
if actual.Name != pod.Name {
|
||||
@@ -181,9 +181,9 @@ func TestCreateSetsFields(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListError(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
pods, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
|
||||
if err != fakeEtcdClient.Err {
|
||||
t.Fatalf("Expected %#v, Got %#v", fakeEtcdClient.Err, err)
|
||||
@@ -194,10 +194,10 @@ func TestListError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListEmptyPodList(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.ChangeIndex = 1
|
||||
ctx := api.NewContext()
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
key := storage.Etcd.KeyRootFunc(ctx)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
|
||||
@@ -219,9 +219,9 @@ func TestListEmptyPodList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListPodList(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
ctx := api.NewDefaultContext()
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
key := storage.Etcd.KeyRootFunc(ctx)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
@@ -264,9 +264,9 @@ func TestListPodList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListPodListSelection(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
ctx := api.NewDefaultContext()
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
rootKey := etcdtest.AddPrefix("pods/default")
|
||||
key := etcdtest.AddPrefix("pods/default/zot")
|
||||
fakeEtcdClient.Data[rootKey] = tools.EtcdResponseWithError{
|
||||
@@ -368,7 +368,8 @@ func TestListPodListSelection(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPodDecode(t *testing.T) {
|
||||
storage := NewStorage(tools.EtcdHelper{}, nil).Pod
|
||||
_, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
expected := validNewPod()
|
||||
body, err := latest.Codec.Encode(expected)
|
||||
if err != nil {
|
||||
@@ -390,7 +391,7 @@ func TestGet(t *testing.T) {
|
||||
expect.Status.Phase = api.PodRunning
|
||||
expect.Spec.NodeName = "machine"
|
||||
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
key := etcdtest.AddPrefix("/pods/test/foo")
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
R: &etcd.Response{
|
||||
@@ -399,7 +400,7 @@ func TestGet(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
|
||||
obj, err := storage.Get(api.WithNamespace(api.NewContext(), "test"), "foo")
|
||||
pod := obj.(*api.Pod)
|
||||
@@ -414,9 +415,9 @@ func TestGet(t *testing.T) {
|
||||
|
||||
// TODO: remove, this is covered by RESTTest.TestCreate
|
||||
func TestPodStorageValidatesCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
|
||||
pod := validNewPod()
|
||||
pod.Labels = map[string]string{
|
||||
@@ -433,8 +434,8 @@ func TestPodStorageValidatesCreate(t *testing.T) {
|
||||
|
||||
// TODO: remove, this is covered by RESTTest.TestCreate
|
||||
func TestCreatePod(t *testing.T) {
|
||||
_, helper := newHelper(t)
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
_, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
ctx := api.NewDefaultContext()
|
||||
key, _ := storage.Etcd.KeyFunc(ctx, "foo")
|
||||
|
||||
@@ -447,7 +448,7 @@ func TestCreatePod(t *testing.T) {
|
||||
t.Fatalf("unexpected object: %#v", obj)
|
||||
}
|
||||
actual := &api.Pod{}
|
||||
if err := helper.ExtractObj(key, actual, false); err != nil {
|
||||
if err := etcdStorage.ExtractObj(key, actual, false); err != nil {
|
||||
t.Fatalf("unexpected extraction error: %v", err)
|
||||
}
|
||||
if !api.HasObjectMetaSystemFieldValues(&actual.ObjectMeta) {
|
||||
@@ -457,8 +458,8 @@ func TestCreatePod(t *testing.T) {
|
||||
|
||||
// TODO: remove, this is covered by RESTTest.TestCreate
|
||||
func TestCreateWithConflictingNamespace(t *testing.T) {
|
||||
_, helper := newHelper(t)
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
_, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
|
||||
pod := validNewPod()
|
||||
pod.Namespace = "not-default"
|
||||
@@ -475,8 +476,8 @@ func TestCreateWithConflictingNamespace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateWithConflictingNamespace(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
ctx := api.NewDefaultContext()
|
||||
key, _ := storage.Etcd.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
@@ -600,8 +601,8 @@ func TestResourceLocation(t *testing.T) {
|
||||
|
||||
ctx := api.NewDefaultContext()
|
||||
for _, tc := range testCases {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
key, _ := storage.Etcd.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
@@ -631,9 +632,9 @@ func TestResourceLocation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeletePod(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.ChangeIndex = 1
|
||||
storage := NewStorage(helper, nil).Pod
|
||||
storage := NewStorage(etcdStorage, nil).Pod
|
||||
ctx := api.NewDefaultContext()
|
||||
key, _ := storage.Etcd.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
@@ -1158,7 +1159,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEtcdUpdateStatus(t *testing.T) {
|
||||
registry, _, status, fakeClient, helper := newStorage(t)
|
||||
registry, _, status, fakeClient, etcdStorage := newStorage(t)
|
||||
ctx := api.NewDefaultContext()
|
||||
fakeClient.TestIndex = true
|
||||
|
||||
@@ -1221,7 +1222,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
|
||||
}
|
||||
var podOut api.Pod
|
||||
key, _ = registry.KeyFunc(ctx, "foo")
|
||||
if err := helper.ExtractObj(key, &podOut, false); err != nil {
|
||||
if err := etcdStorage.ExtractObj(key, &podOut, false); err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
if !api.Semantic.DeepEqual(expected, podOut) {
|
||||
|
@@ -33,7 +33,7 @@ type REST struct {
|
||||
}
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against pod templates.
|
||||
func NewREST(h tools.EtcdHelper) *REST {
|
||||
func NewREST(s tools.StorageInterface) *REST {
|
||||
prefix := "/podtemplates"
|
||||
store := etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.PodTemplate{} },
|
||||
@@ -56,7 +56,7 @@ func NewREST(h tools.EtcdHelper) *REST {
|
||||
UpdateStrategy: podtemplate.Strategy,
|
||||
ReturnDeletedObject: true,
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
|
||||
return &REST{store}
|
||||
|
@@ -26,11 +26,11 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func validNewPodTemplate(name string) *api.PodTemplate {
|
||||
@@ -61,8 +61,8 @@ func validNewPodTemplate(name string) *api.PodTemplate {
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewREST(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewREST(etcdStorage)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
pod := validNewPodTemplate("foo")
|
||||
pod.ObjectMeta = api.ObjectMeta{}
|
||||
@@ -77,8 +77,8 @@ func TestCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewREST(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewREST(etcdStorage)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
key, err := storage.KeyFunc(test.TestContext(), "foo")
|
||||
if err != nil {
|
||||
|
@@ -33,7 +33,7 @@ type REST struct {
|
||||
}
|
||||
|
||||
// NewStorage returns a RESTStorage object that will work against ResourceQuota objects.
|
||||
func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
||||
func NewStorage(s tools.StorageInterface) (*REST, *StatusREST) {
|
||||
prefix := "/resourcequotas"
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.ResourceQuota{} },
|
||||
@@ -52,7 +52,7 @@ func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
||||
},
|
||||
EndpointName: "resourcequotas",
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
|
||||
store.CreateStrategy = resourcequota.Strategy
|
||||
|
@@ -38,15 +38,15 @@ import (
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, latest.Codec, etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient, h := newEtcdStorage(t)
|
||||
storage, statusStorage := NewStorage(h)
|
||||
return storage, statusStorage, fakeEtcdClient, h
|
||||
}
|
||||
@@ -85,8 +85,8 @@ func TestStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _ := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
resourcequota := validNewResourceQuota()
|
||||
resourcequota.ObjectMeta = api.ObjectMeta{}
|
||||
@@ -110,9 +110,9 @@ func expectResourceQuota(t *testing.T, out runtime.Object) (*api.ResourceQuota,
|
||||
}
|
||||
|
||||
func TestCreateRegistryError(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage, _ := NewStorage(helper)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
|
||||
resourcequota := validNewResourceQuota()
|
||||
_, err := storage.Create(api.NewDefaultContext(), resourcequota)
|
||||
@@ -122,8 +122,8 @@ func TestCreateRegistryError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateSetsFields(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _ := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
ctx := api.NewDefaultContext()
|
||||
resourcequota := validNewResourceQuota()
|
||||
_, err := storage.Create(api.NewDefaultContext(), resourcequota)
|
||||
@@ -133,7 +133,7 @@ func TestCreateSetsFields(t *testing.T) {
|
||||
|
||||
actual := &api.ResourceQuota{}
|
||||
key, _ := storage.Etcd.KeyFunc(ctx, "foo")
|
||||
if err := helper.ExtractObj(key, actual, false); err != nil {
|
||||
if err := etcdStorage.ExtractObj(key, actual, false); err != nil {
|
||||
t.Fatalf("unexpected extraction error: %v", err)
|
||||
}
|
||||
if actual.Name != resourcequota.Name {
|
||||
@@ -145,9 +145,9 @@ func TestCreateSetsFields(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListError(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage, _ := NewStorage(helper)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
resourcequotas, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
|
||||
if err != fakeEtcdClient.Err {
|
||||
t.Fatalf("Expected %#v, Got %#v", fakeEtcdClient.Err, err)
|
||||
@@ -158,9 +158,9 @@ func TestListError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListEmptyResourceQuotaList(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.ChangeIndex = 1
|
||||
storage, _ := NewStorage(helper)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
ctx := api.NewContext()
|
||||
key := storage.Etcd.KeyRootFunc(ctx)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
@@ -184,8 +184,8 @@ func TestListEmptyResourceQuotaList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListResourceQuotaList(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _ := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
ctx := api.NewDefaultContext()
|
||||
key := storage.Etcd.KeyRootFunc(ctx)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
@@ -225,8 +225,8 @@ func TestListResourceQuotaList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListResourceQuotaListSelection(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _ := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
ctx := api.NewDefaultContext()
|
||||
key := storage.Etcd.KeyRootFunc(ctx)
|
||||
key = etcdtest.AddPrefix(key)
|
||||
@@ -294,7 +294,8 @@ func TestListResourceQuotaListSelection(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResourceQuotaDecode(t *testing.T) {
|
||||
storage, _ := NewStorage(tools.EtcdHelper{})
|
||||
_, etcdStorage := newEtcdStorage(t)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
expected := validNewResourceQuota()
|
||||
body, err := latest.Codec.Encode(expected)
|
||||
if err != nil {
|
||||
@@ -313,8 +314,8 @@ func TestResourceQuotaDecode(t *testing.T) {
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
expect := validNewResourceQuota()
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _ := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
key := "/resourcequotas/test/foo"
|
||||
key = etcdtest.AddPrefix(key)
|
||||
fakeEtcdClient.Data[key] = tools.EtcdResponseWithError{
|
||||
@@ -336,9 +337,9 @@ func TestGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteResourceQuota(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
fakeEtcdClient.ChangeIndex = 1
|
||||
storage, _ := NewStorage(helper)
|
||||
storage, _ := NewStorage(etcdStorage)
|
||||
ctx := api.NewDefaultContext()
|
||||
key, _ := storage.Etcd.KeyFunc(ctx, "foo")
|
||||
key = etcdtest.AddPrefix(key)
|
||||
@@ -470,7 +471,7 @@ func TestEtcdCreateAlreadyExisting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEtcdUpdateStatus(t *testing.T) {
|
||||
registry, status, fakeClient, helper := newStorage(t)
|
||||
registry, status, fakeClient, etcdStorage := newStorage(t)
|
||||
ctx := api.NewDefaultContext()
|
||||
fakeClient.TestIndex = true
|
||||
|
||||
@@ -516,7 +517,7 @@ func TestEtcdUpdateStatus(t *testing.T) {
|
||||
}
|
||||
var resourcequotaOut api.ResourceQuota
|
||||
key, _ = registry.KeyFunc(ctx, "foo")
|
||||
if err := helper.ExtractObj(key, &resourcequotaOut, false); err != nil {
|
||||
if err := etcdStorage.ExtractObj(key, &resourcequotaOut, false); err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
if !api.Semantic.DeepEqual(expected, resourcequotaOut) {
|
||||
|
@@ -32,9 +32,8 @@ type REST struct {
|
||||
*etcdgeneric.Etcd
|
||||
}
|
||||
|
||||
// NewStorage returns a registry which will store Secret in the given helper
|
||||
func NewStorage(h tools.EtcdHelper) *REST {
|
||||
|
||||
// NewStorage returns a registry which will store Secret in the given etcdStorage
|
||||
func NewStorage(s tools.StorageInterface) *REST {
|
||||
prefix := "/secrets"
|
||||
|
||||
store := &etcdgeneric.Etcd{
|
||||
@@ -54,7 +53,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
|
||||
},
|
||||
EndpointName: "secrets",
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
|
||||
store.CreateStrategy = secret.Strategy
|
||||
|
@@ -26,11 +26,11 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func validNewSecret(name string) *api.Secret {
|
||||
@@ -46,8 +46,8 @@ func validNewSecret(name string) *api.Secret {
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
secret := validNewSecret("foo")
|
||||
secret.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
|
||||
@@ -68,8 +68,8 @@ func TestCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
key, err := storage.KeyFunc(test.TestContext(), "foo")
|
||||
if err != nil {
|
||||
|
@@ -41,9 +41,9 @@ var (
|
||||
type Etcd struct {
|
||||
lock sync.Mutex
|
||||
|
||||
alloc allocator.Snapshottable
|
||||
helper tools.EtcdHelper
|
||||
last string
|
||||
alloc allocator.Snapshottable
|
||||
storage tools.StorageInterface
|
||||
last string
|
||||
|
||||
baseKey string
|
||||
kind string
|
||||
@@ -55,10 +55,10 @@ var _ service.RangeRegistry = &Etcd{}
|
||||
|
||||
// NewEtcd returns an allocator that is backed by Etcd and can manage
|
||||
// persisting the snapshot state of allocation after each allocation is made.
|
||||
func NewEtcd(alloc allocator.Snapshottable, baseKey string, kind string, helper tools.EtcdHelper) *Etcd {
|
||||
func NewEtcd(alloc allocator.Snapshottable, baseKey string, kind string, storage tools.StorageInterface) *Etcd {
|
||||
return &Etcd{
|
||||
alloc: alloc,
|
||||
helper: helper,
|
||||
storage: storage,
|
||||
baseKey: baseKey,
|
||||
kind: kind,
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (e *Etcd) Release(item int) error {
|
||||
|
||||
// tryUpdate performs a read-update to persist the latest snapshot state of allocation.
|
||||
func (e *Etcd) tryUpdate(fn func() error) error {
|
||||
err := e.helper.GuaranteedUpdate(e.baseKey, &api.RangeAllocation{}, true,
|
||||
err := e.storage.GuaranteedUpdate(e.baseKey, &api.RangeAllocation{}, true,
|
||||
tools.SimpleUpdate(func(input runtime.Object) (output runtime.Object, err error) {
|
||||
existing := input.(*api.RangeAllocation)
|
||||
if len(existing.ResourceVersion) == 0 {
|
||||
@@ -170,7 +170,7 @@ func (e *Etcd) Refresh() (*api.RangeAllocation, error) {
|
||||
defer e.lock.Unlock()
|
||||
|
||||
existing := &api.RangeAllocation{}
|
||||
if err := e.helper.ExtractObj(e.baseKey, existing, false); err != nil {
|
||||
if err := e.storage.ExtractObj(e.baseKey, existing, false); err != nil {
|
||||
if tools.IsEtcdNotFound(err) {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func (e *Etcd) Refresh() (*api.RangeAllocation, error) {
|
||||
// etcd. If the key does not exist, the object will have an empty ResourceVersion.
|
||||
func (e *Etcd) Get() (*api.RangeAllocation, error) {
|
||||
existing := &api.RangeAllocation{}
|
||||
if err := e.helper.ExtractObj(e.baseKey, existing, true); err != nil {
|
||||
if err := e.storage.ExtractObj(e.baseKey, existing, true); err != nil {
|
||||
return nil, etcderr.InterpretGetError(err, e.kind, "")
|
||||
}
|
||||
return existing, nil
|
||||
@@ -197,7 +197,7 @@ func (e *Etcd) CreateOrUpdate(snapshot *api.RangeAllocation) error {
|
||||
defer e.lock.Unlock()
|
||||
|
||||
last := ""
|
||||
err := e.helper.GuaranteedUpdate(e.baseKey, &api.RangeAllocation{}, true,
|
||||
err := e.storage.GuaranteedUpdate(e.baseKey, &api.RangeAllocation{}, true,
|
||||
tools.SimpleUpdate(func(input runtime.Object) (output runtime.Object, err error) {
|
||||
existing := input.(*api.RangeAllocation)
|
||||
switch {
|
||||
|
@@ -30,18 +30,18 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func newStorage(t *testing.T) (*Etcd, allocator.Interface, *tools.FakeEtcdClient) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
fakeEtcdClient, s := newEtcdStorage(t)
|
||||
|
||||
mem := allocator.NewAllocationMap(100, "rangeSpecValue")
|
||||
etcd := NewEtcd(mem, "/ranges/serviceips", "serviceipallocation", h)
|
||||
etcd := NewEtcd(mem, "/ranges/serviceips", "serviceipallocation", s)
|
||||
|
||||
return etcd, mem, fakeEtcdClient
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func TestStore(t *testing.T) {
|
||||
other := allocator.NewAllocationMap(100, "rangeSpecValue")
|
||||
|
||||
allocation := &api.RangeAllocation{}
|
||||
if err := storage.helper.ExtractObj(key(), allocation, false); err != nil {
|
||||
if err := storage.storage.ExtractObj(key(), allocation, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if allocation.ResourceVersion != "1" {
|
||||
@@ -118,7 +118,7 @@ func TestStore(t *testing.T) {
|
||||
}
|
||||
|
||||
other = allocator.NewAllocationMap(100, "rangeSpecValue")
|
||||
otherStorage := NewEtcd(other, "/ranges/serviceips", "serviceipallocation", storage.helper)
|
||||
otherStorage := NewEtcd(other, "/ranges/serviceips", "serviceipallocation", storage.storage)
|
||||
if ok, err := otherStorage.Allocate(2); ok || err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@@ -33,15 +33,15 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func newStorage(t *testing.T) (ipallocator.Interface, allocator.Interface, *tools.FakeEtcdClient) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
_, cidr, err := net.ParseCIDR("192.168.1.0/24")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -51,7 +51,7 @@ func newStorage(t *testing.T) (ipallocator.Interface, allocator.Interface, *tool
|
||||
storage := ipallocator.NewAllocatorCIDRRange(cidr, func(max int, rangeSpec string) allocator.Interface {
|
||||
mem := allocator.NewAllocationMap(max, rangeSpec)
|
||||
backing = mem
|
||||
etcd := allocator_etcd.NewEtcd(mem, "/ranges/serviceips", "serviceipallocation", h)
|
||||
etcd := allocator_etcd.NewEtcd(mem, "/ranges/serviceips", "serviceipallocation", etcdStorage)
|
||||
return etcd
|
||||
})
|
||||
|
||||
|
@@ -35,7 +35,7 @@ type REST struct {
|
||||
const Prefix = "/serviceaccounts"
|
||||
|
||||
// NewStorage returns a RESTStorage object that will work against service accounts objects.
|
||||
func NewStorage(h tools.EtcdHelper) *REST {
|
||||
func NewStorage(s tools.StorageInterface) *REST {
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.ServiceAccount{} },
|
||||
NewListFunc: func() runtime.Object { return &api.ServiceAccountList{} },
|
||||
@@ -53,7 +53,7 @@ func NewStorage(h tools.EtcdHelper) *REST {
|
||||
},
|
||||
EndpointName: "serviceaccounts",
|
||||
|
||||
Helper: h,
|
||||
Storage: s,
|
||||
}
|
||||
|
||||
store.CreateStrategy = serviceaccount.Strategy
|
||||
|
@@ -26,11 +26,11 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools/etcdtest"
|
||||
)
|
||||
|
||||
func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
func newEtcdStorage(t *testing.T) (*tools.FakeEtcdClient, tools.StorageInterface) {
|
||||
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||
fakeEtcdClient.TestIndex = true
|
||||
helper := tools.NewEtcdHelper(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, helper
|
||||
etcdStorage := tools.NewEtcdStorage(fakeEtcdClient, testapi.Codec(), etcdtest.PathPrefix())
|
||||
return fakeEtcdClient, etcdStorage
|
||||
}
|
||||
|
||||
func validNewServiceAccount(name string) *api.ServiceAccount {
|
||||
@@ -44,8 +44,8 @@ func validNewServiceAccount(name string) *api.ServiceAccount {
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
serviceAccount := validNewServiceAccount("foo")
|
||||
serviceAccount.ObjectMeta = api.ObjectMeta{GenerateName: "foo-"}
|
||||
@@ -61,8 +61,8 @@ func TestCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewStorage(helper)
|
||||
fakeEtcdClient, etcdStorage := newEtcdStorage(t)
|
||||
storage := NewStorage(etcdStorage)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
key, err := storage.KeyFunc(test.TestContext(), "foo")
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user