mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Rename NewREST -> NewStorage to align on terminology
This commit is contained in:
parent
5a3f0adbcc
commit
9bb797fe93
@ -349,16 +349,16 @@ func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter)
|
||||
|
||||
// init initializes master.
|
||||
func (m *Master) init(c *Config) {
|
||||
podStorage, bindingStorage, podStatusStorage := podetcd.NewREST(c.EtcdHelper)
|
||||
podStorage, bindingStorage, podStatusStorage := podetcd.NewStorage(c.EtcdHelper)
|
||||
podRegistry := pod.NewRegistry(podStorage)
|
||||
|
||||
eventRegistry := event.NewEtcdRegistry(c.EtcdHelper, uint64(c.EventTTL.Seconds()))
|
||||
limitRangeRegistry := limitrange.NewEtcdRegistry(c.EtcdHelper)
|
||||
|
||||
resourceQuotaStorage, resourceQuotaStatusStorage := resourcequotaetcd.NewREST(c.EtcdHelper)
|
||||
resourceQuotaStorage, resourceQuotaStatusStorage := resourcequotaetcd.NewStorage(c.EtcdHelper)
|
||||
secretRegistry := secret.NewEtcdRegistry(c.EtcdHelper)
|
||||
|
||||
namespaceStorage := namespaceetcd.NewREST(c.EtcdHelper)
|
||||
namespaceStorage := namespaceetcd.NewStorage(c.EtcdHelper)
|
||||
m.namespaceRegistry = namespace.NewRegistry(namespaceStorage)
|
||||
|
||||
// TODO: split me up into distinct storage registries
|
||||
@ -368,7 +368,7 @@ func (m *Master) init(c *Config) {
|
||||
m.endpointRegistry = registry
|
||||
m.nodeRegistry = registry
|
||||
|
||||
nodeStorage := minion.NewREST(m.nodeRegistry)
|
||||
nodeStorage := minion.NewStorage(m.nodeRegistry)
|
||||
// TODO: unify the storage -> registry and storage -> client patterns
|
||||
nodeStorageClient := RESTStorageToNodes(nodeStorage)
|
||||
podCache := NewPodCache(
|
||||
@ -391,18 +391,18 @@ func (m *Master) init(c *Config) {
|
||||
"pods/binding": bindingStorage,
|
||||
"bindings": bindingStorage,
|
||||
|
||||
"replicationControllers": controller.NewREST(registry, podRegistry),
|
||||
"services": service.NewREST(m.serviceRegistry, c.Cloud, m.nodeRegistry, m.portalNet, c.ClusterName),
|
||||
"endpoints": endpoint.NewREST(m.endpointRegistry),
|
||||
"replicationControllers": controller.NewStorage(registry, podRegistry),
|
||||
"services": service.NewStorage(m.serviceRegistry, c.Cloud, m.nodeRegistry, m.portalNet, c.ClusterName),
|
||||
"endpoints": endpoint.NewStorage(m.endpointRegistry),
|
||||
"minions": nodeStorage,
|
||||
"nodes": nodeStorage,
|
||||
"events": event.NewREST(eventRegistry),
|
||||
"events": event.NewStorage(eventRegistry),
|
||||
|
||||
"limitRanges": limitrange.NewREST(limitRangeRegistry),
|
||||
"limitRanges": limitrange.NewStorage(limitRangeRegistry),
|
||||
"resourceQuotas": resourceQuotaStorage,
|
||||
"resourceQuotas/status": resourceQuotaStatusStorage,
|
||||
"namespaces": namespaceStorage,
|
||||
"secrets": secret.NewREST(secretRegistry),
|
||||
"secrets": secret.NewStorage(secretRegistry),
|
||||
}
|
||||
|
||||
apiVersions := []string{"v1beta1", "v1beta2"}
|
||||
|
@ -78,8 +78,8 @@ type REST struct {
|
||||
strategy rcStrategy
|
||||
}
|
||||
|
||||
// NewREST returns a new rest.Storage for the given registry and PodLister.
|
||||
func NewREST(registry Registry, podLister PodLister) *REST {
|
||||
// NewStorage returns a new rest.Storage for the given registry and PodLister.
|
||||
func NewStorage(registry Registry, podLister PodLister) *REST {
|
||||
return &REST{
|
||||
registry: registry,
|
||||
podLister: podLister,
|
||||
|
@ -397,7 +397,7 @@ func (f *fakePodLister) ListPods(ctx api.Context, s labels.Selector) (*api.PodLi
|
||||
|
||||
// TODO: remove, covered by TestCreate
|
||||
func TestCreateControllerWithGeneratedName(t *testing.T) {
|
||||
storage := NewREST(®istrytest.ControllerRegistry{}, nil)
|
||||
storage := NewStorage(®istrytest.ControllerRegistry{}, nil)
|
||||
controller := &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Namespace: api.NamespaceDefault,
|
||||
@ -443,7 +443,7 @@ func TestCreateControllerWithConflictingNamespace(t *testing.T) {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
registry := ®istrytest.ControllerRegistry{}
|
||||
test := resttest.New(t, NewREST(registry, nil), registry.SetError)
|
||||
test := resttest.New(t, NewStorage(registry, nil), registry.SetError)
|
||||
test.TestCreate(
|
||||
// valid
|
||||
&api.ReplicationController{
|
||||
|
@ -32,8 +32,8 @@ type REST struct {
|
||||
registry Registry
|
||||
}
|
||||
|
||||
// NewREST returns a new rest.Storage implementation for endpoints
|
||||
func NewREST(registry Registry) *REST {
|
||||
// NewStorage returns a new rest.Storage implementation for endpoints
|
||||
func NewStorage(registry Registry) *REST {
|
||||
return &REST{
|
||||
registry: registry,
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func TestGetEndpoints(t *testing.T) {
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: 9000}},
|
||||
},
|
||||
}
|
||||
storage := NewREST(registry)
|
||||
storage := NewStorage(registry)
|
||||
ctx := api.NewContext()
|
||||
obj, err := storage.Get(ctx, "foo")
|
||||
if err != nil {
|
||||
@ -49,7 +49,7 @@ func TestGetEndpointsMissingService(t *testing.T) {
|
||||
registry := ®istrytest.ServiceRegistry{
|
||||
Err: errors.NewNotFound("service", "foo"),
|
||||
}
|
||||
storage := NewREST(registry)
|
||||
storage := NewStorage(registry)
|
||||
ctx := api.NewContext()
|
||||
// returns service not found
|
||||
_, err := storage.Get(ctx, "foo")
|
||||
@ -73,7 +73,7 @@ func TestGetEndpointsMissingService(t *testing.T) {
|
||||
|
||||
func TestEndpointsRegistryList(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
storage := NewREST(registry)
|
||||
storage := NewStorage(registry)
|
||||
registry.EndpointsList = api.EndpointsList{
|
||||
ListMeta: api.ListMeta{ResourceVersion: "1"},
|
||||
Items: []api.Endpoints{
|
||||
|
@ -42,7 +42,7 @@ func NewTestEtcdRegistry(client tools.EtcdClient) *Registry {
|
||||
|
||||
func NewTestEtcdRegistryWithPods(client tools.EtcdClient) *Registry {
|
||||
helper := tools.NewEtcdHelper(client, latest.Codec)
|
||||
podStorage, _, _ := podetcd.NewREST(helper)
|
||||
podStorage, _, _ := podetcd.NewStorage(helper)
|
||||
registry := NewRegistry(helper, pod.NewRegistry(podStorage))
|
||||
return registry
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ type REST struct {
|
||||
registry generic.Registry
|
||||
}
|
||||
|
||||
// NewREST returns a new REST. You must use a registry created by
|
||||
// NewStorage returns a new REST. You must use a registry created by
|
||||
// NewEtcdRegistry unless you're testing.
|
||||
func NewREST(registry generic.Registry) *REST {
|
||||
func NewStorage(registry generic.Registry) *REST {
|
||||
return &REST{
|
||||
registry: registry,
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ type testRegistry struct {
|
||||
|
||||
func NewTestREST() (testRegistry, *REST) {
|
||||
reg := testRegistry{registrytest.NewGeneric(nil)}
|
||||
return reg, NewREST(reg)
|
||||
return reg, NewStorage(reg)
|
||||
}
|
||||
|
||||
func testEvent(name string) *api.Event {
|
||||
|
@ -35,9 +35,9 @@ type REST struct {
|
||||
registry generic.Registry
|
||||
}
|
||||
|
||||
// NewREST returns a new REST. You must use a registry created by
|
||||
// NewStorage returns a new REST. You must use a registry created by
|
||||
// NewEtcdRegistry unless you're testing.
|
||||
func NewREST(registry generic.Registry) *REST {
|
||||
func NewStorage(registry generic.Registry) *REST {
|
||||
return &REST{
|
||||
registry: registry,
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ type REST struct {
|
||||
registry Registry
|
||||
}
|
||||
|
||||
// NewREST returns a new rest.Storage implementation for minion.
|
||||
func NewREST(m Registry) *REST {
|
||||
// NewStorage returns a new rest.Storage implementation for minion.
|
||||
func NewStorage(m Registry) *REST {
|
||||
return &REST{
|
||||
registry: m,
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMinionRegistryREST(t *testing.T) {
|
||||
ms := NewREST(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))
|
||||
ms := NewStorage(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))
|
||||
ctx := api.NewContext()
|
||||
if obj, err := ms.Get(ctx, "foo"); err != nil || obj.(*api.Node).Name != "foo" {
|
||||
t.Errorf("missing expected object")
|
||||
@ -88,7 +88,7 @@ func TestMinionRegistryREST(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMinionRegistryValidUpdate(t *testing.T) {
|
||||
storage := NewREST(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))
|
||||
storage := NewStorage(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))
|
||||
ctx := api.NewContext()
|
||||
obj, err := storage.Get(ctx, "foo")
|
||||
if err != nil {
|
||||
@ -113,7 +113,7 @@ var (
|
||||
)
|
||||
|
||||
func TestMinionRegistryValidatesCreate(t *testing.T) {
|
||||
storage := NewREST(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))
|
||||
storage := NewStorage(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))
|
||||
ctx := api.NewContext()
|
||||
failureCases := map[string]api.Node{
|
||||
"zero-length Name": {
|
||||
@ -156,7 +156,7 @@ func contains(nodes *api.NodeList, nodeID string) bool {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
registry := registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{})
|
||||
test := resttest.New(t, NewREST(registry), registry.SetError).ClusterScope()
|
||||
test := resttest.New(t, NewStorage(registry), registry.SetError).ClusterScope()
|
||||
test.TestCreate(
|
||||
// valid
|
||||
&api.Node{
|
||||
|
@ -32,8 +32,8 @@ type REST struct {
|
||||
*etcdgeneric.Etcd
|
||||
}
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against namespaces
|
||||
func NewREST(h tools.EtcdHelper) *REST {
|
||||
// NewStorage returns a RESTStorage object that will work against namespaces
|
||||
func NewStorage(h tools.EtcdHelper) *REST {
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.Namespace{} },
|
||||
NewListFunc: func() runtime.Object { return &api.NamespaceList{} },
|
||||
|
@ -41,7 +41,7 @@ func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
storage := NewREST(h)
|
||||
storage := NewStorage(h)
|
||||
return storage, fakeEtcdClient, h
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ func TestStorage(t *testing.T) {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewREST(helper)
|
||||
storage := NewStorage(helper)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
namespace := validNewNamespace()
|
||||
namespace.ObjectMeta = api.ObjectMeta{}
|
||||
@ -94,7 +94,7 @@ func expectNamespace(t *testing.T, out runtime.Object) (*api.Namespace, bool) {
|
||||
|
||||
func TestCreateSetsFields(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage := NewREST(helper)
|
||||
storage := NewStorage(helper)
|
||||
namespace := validNewNamespace()
|
||||
_, err := storage.Create(api.NewDefaultContext(), namespace)
|
||||
if err != fakeEtcdClient.Err {
|
||||
@ -124,7 +124,7 @@ func TestListEmptyNamespaceList(t *testing.T) {
|
||||
E: fakeEtcdClient.NewError(tools.EtcdErrorCodeNotFound),
|
||||
}
|
||||
|
||||
storage := NewREST(helper)
|
||||
storage := NewStorage(helper)
|
||||
namespaces, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
@ -157,7 +157,7 @@ func TestListNamespaceList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage := NewREST(helper)
|
||||
storage := NewStorage(helper)
|
||||
namespacesObj, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
|
||||
namespaces := namespacesObj.(*api.NamespaceList)
|
||||
if err != nil {
|
||||
@ -204,7 +204,7 @@ func TestListNamespaceListSelection(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage := NewREST(helper)
|
||||
storage := NewStorage(helper)
|
||||
ctx := api.NewDefaultContext()
|
||||
table := []struct {
|
||||
label, field string
|
||||
@ -252,7 +252,7 @@ func TestListNamespaceListSelection(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNamespaceDecode(t *testing.T) {
|
||||
storage := NewREST(tools.EtcdHelper{})
|
||||
storage := NewStorage(tools.EtcdHelper{})
|
||||
expected := validNewNamespace()
|
||||
expected.Status.Phase = api.NamespaceActive
|
||||
body, err := latest.Codec.Encode(expected)
|
||||
@ -281,7 +281,7 @@ func TestGet(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage := NewREST(helper)
|
||||
storage := NewStorage(helper)
|
||||
obj, err := storage.Get(api.NewContext(), "foo")
|
||||
namespace := obj.(*api.Namespace)
|
||||
if err != nil {
|
||||
@ -311,7 +311,7 @@ func TestDeleteNamespace(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage := NewREST(helper)
|
||||
storage := NewStorage(helper)
|
||||
_, err := storage.Delete(api.NewDefaultContext(), "foo", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
@ -38,8 +38,8 @@ type REST struct {
|
||||
etcdgeneric.Etcd
|
||||
}
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against pods.
|
||||
func NewREST(h tools.EtcdHelper) (*REST, *BindingREST, *StatusREST) {
|
||||
// NewStorage returns a RESTStorage object that will work against pods.
|
||||
func NewStorage(h tools.EtcdHelper) (*REST, *BindingREST, *StatusREST) {
|
||||
prefix := "/registry/pods"
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.Pod{} },
|
||||
|
@ -69,7 +69,7 @@ func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *BindingREST, *StatusREST, *tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
storage, bindingStorage, statusStorage := NewREST(h)
|
||||
storage, bindingStorage, statusStorage := NewStorage(h)
|
||||
storage = storage.WithPodStatus(&fakeCache{statusToReturn: &api.PodStatus{}})
|
||||
return storage, bindingStorage, statusStorage, fakeEtcdClient, h
|
||||
}
|
||||
@ -112,7 +112,7 @@ func TestStorage(t *testing.T) {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
@ -132,7 +132,7 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
@ -170,7 +170,7 @@ func expectPod(t *testing.T, out runtime.Object) (*api.Pod, bool) {
|
||||
func TestCreateRegistryError(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
|
||||
pod := validNewPod()
|
||||
_, err := storage.Create(api.NewDefaultContext(), pod)
|
||||
@ -181,7 +181,7 @@ func TestCreateRegistryError(t *testing.T) {
|
||||
|
||||
func TestCreateSetsFields(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
pod := validNewPod()
|
||||
@ -205,7 +205,7 @@ func TestCreateSetsFields(t *testing.T) {
|
||||
func TestListError(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
pods, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
|
||||
@ -233,7 +233,7 @@ func TestListCacheError(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{errorToReturn: client.ErrPodInfoNotAvailable}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -258,7 +258,7 @@ func TestListEmptyPodList(t *testing.T) {
|
||||
E: fakeEtcdClient.NewError(tools.EtcdErrorCodeNotFound),
|
||||
}
|
||||
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
pods, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
|
||||
@ -296,7 +296,7 @@ func TestListPodList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{Phase: api.PodRunning}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -347,7 +347,7 @@ func TestListPodListSelection(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{Phase: api.PodRunning}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -414,7 +414,7 @@ func TestListPodListSelection(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPodDecode(t *testing.T) {
|
||||
storage, _, _ := NewREST(tools.EtcdHelper{})
|
||||
storage, _, _ := NewStorage(tools.EtcdHelper{})
|
||||
expected := validNewPod()
|
||||
body, err := latest.Codec.Encode(expected)
|
||||
if err != nil {
|
||||
@ -443,7 +443,7 @@ func TestGet(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{Phase: api.PodRunning}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -471,7 +471,7 @@ func TestGetCacheError(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{errorToReturn: client.ErrPodInfoNotAvailable}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -491,7 +491,7 @@ func TestGetCacheError(t *testing.T) {
|
||||
func TestPodStorageValidatesCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -511,7 +511,7 @@ func TestPodStorageValidatesCreate(t *testing.T) {
|
||||
// TODO: remove, this is covered by RESTTest.TestCreate
|
||||
func TestCreatePod(t *testing.T) {
|
||||
_, helper := newHelper(t)
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -535,7 +535,7 @@ func TestCreatePod(t *testing.T) {
|
||||
// TODO: remove, this is covered by RESTTest.TestCreate
|
||||
func TestCreateWithConflictingNamespace(t *testing.T) {
|
||||
_, helper := newHelper(t)
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -566,7 +566,7 @@ func TestUpdateWithConflictingNamespace(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -678,7 +678,7 @@ func TestResourceLocation(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{PodIP: expectedIP}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
@ -712,7 +712,7 @@ func TestDeletePod(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _, _ := NewREST(helper)
|
||||
storage, _, _ := NewStorage(helper)
|
||||
cache := &fakeCache{statusToReturn: &api.PodStatus{}}
|
||||
storage = storage.WithPodStatus(cache)
|
||||
|
||||
|
@ -32,8 +32,8 @@ type REST struct {
|
||||
*etcdgeneric.Etcd
|
||||
}
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against ResourceQuota objects.
|
||||
func NewREST(h tools.EtcdHelper) (*REST, *StatusREST) {
|
||||
// NewStorage returns a RESTStorage object that will work against ResourceQuota objects.
|
||||
func NewStorage(h tools.EtcdHelper) (*REST, *StatusREST) {
|
||||
prefix := "/registry/resourcequotas"
|
||||
store := &etcdgeneric.Etcd{
|
||||
NewFunc: func() runtime.Object { return &api.ResourceQuota{} },
|
||||
|
@ -46,7 +46,7 @@ func newHelper(t *testing.T) (*tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
|
||||
func newStorage(t *testing.T) (*REST, *StatusREST, *tools.FakeEtcdClient, tools.EtcdHelper) {
|
||||
fakeEtcdClient, h := newHelper(t)
|
||||
storage, statusStorage := NewREST(h)
|
||||
storage, statusStorage := NewStorage(h)
|
||||
return storage, statusStorage, fakeEtcdClient, h
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ func TestStorage(t *testing.T) {
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _ := NewREST(helper)
|
||||
storage, _ := NewStorage(helper)
|
||||
test := resttest.New(t, storage, fakeEtcdClient.SetError)
|
||||
resourcequota := validNewResourceQuota()
|
||||
resourcequota.ObjectMeta = api.ObjectMeta{}
|
||||
@ -111,7 +111,7 @@ func expectResourceQuota(t *testing.T, out runtime.Object) (*api.ResourceQuota,
|
||||
func TestCreateRegistryError(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage, _ := NewREST(helper)
|
||||
storage, _ := NewStorage(helper)
|
||||
|
||||
resourcequota := validNewResourceQuota()
|
||||
_, err := storage.Create(api.NewDefaultContext(), resourcequota)
|
||||
@ -122,7 +122,7 @@ func TestCreateRegistryError(t *testing.T) {
|
||||
|
||||
func TestCreateSetsFields(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
storage, _ := NewREST(helper)
|
||||
storage, _ := NewStorage(helper)
|
||||
resourcequota := validNewResourceQuota()
|
||||
_, err := storage.Create(api.NewDefaultContext(), resourcequota)
|
||||
if err != fakeEtcdClient.Err {
|
||||
@ -144,7 +144,7 @@ func TestCreateSetsFields(t *testing.T) {
|
||||
func TestListError(t *testing.T) {
|
||||
fakeEtcdClient, helper := newHelper(t)
|
||||
fakeEtcdClient.Err = fmt.Errorf("test error")
|
||||
storage, _ := NewREST(helper)
|
||||
storage, _ := NewStorage(helper)
|
||||
resourcequotas, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
|
||||
if err != fakeEtcdClient.Err {
|
||||
t.Fatalf("Expected %#v, Got %#v", fakeEtcdClient.Err, err)
|
||||
@ -162,7 +162,7 @@ func TestListEmptyResourceQuotaList(t *testing.T) {
|
||||
E: fakeEtcdClient.NewError(tools.EtcdErrorCodeNotFound),
|
||||
}
|
||||
|
||||
storage, _ := NewREST(helper)
|
||||
storage, _ := NewStorage(helper)
|
||||
resourcequotas, err := storage.List(api.NewContext(), labels.Everything(), fields.Everything())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@ -196,7 +196,7 @@ func TestListResourceQuotaList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _ := NewREST(helper)
|
||||
storage, _ := NewStorage(helper)
|
||||
resourcequotasObj, err := storage.List(api.NewDefaultContext(), labels.Everything(), fields.Everything())
|
||||
resourcequotas := resourcequotasObj.(*api.ResourceQuotaList)
|
||||
if err != nil {
|
||||
@ -236,7 +236,7 @@ func TestListResourceQuotaListSelection(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _ := NewREST(helper)
|
||||
storage, _ := NewStorage(helper)
|
||||
ctx := api.NewDefaultContext()
|
||||
|
||||
table := []struct {
|
||||
@ -282,7 +282,7 @@ func TestListResourceQuotaListSelection(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResourceQuotaDecode(t *testing.T) {
|
||||
storage, _ := NewREST(tools.EtcdHelper{})
|
||||
storage, _ := NewStorage(tools.EtcdHelper{})
|
||||
expected := validNewResourceQuota()
|
||||
body, err := latest.Codec.Encode(expected)
|
||||
if err != nil {
|
||||
@ -309,7 +309,7 @@ func TestGet(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _ := NewREST(helper)
|
||||
storage, _ := NewStorage(helper)
|
||||
obj, err := storage.Get(api.WithNamespace(api.NewContext(), "test"), "foo")
|
||||
resourcequota := obj.(*api.ResourceQuota)
|
||||
if err != nil {
|
||||
@ -339,7 +339,7 @@ func TestDeleteResourceQuota(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
storage, _ := NewREST(helper)
|
||||
storage, _ := NewStorage(helper)
|
||||
_, err := storage.Delete(api.NewDefaultContext(), "foo", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
@ -35,9 +35,9 @@ type REST struct {
|
||||
registry generic.Registry
|
||||
}
|
||||
|
||||
// NewREST returns a new REST. You must use a registry created by
|
||||
// NewStorage returns a new REST. You must use a registry created by
|
||||
// NewEtcdRegistry unless you're testing.
|
||||
func NewREST(registry generic.Registry) *REST {
|
||||
func NewStorage(registry generic.Registry) *REST {
|
||||
return &REST{
|
||||
registry: registry,
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type testRegistry struct {
|
||||
|
||||
func NewTestREST() (testRegistry, *REST) {
|
||||
reg := testRegistry{registrytest.NewGeneric(nil)}
|
||||
return reg, NewREST(reg)
|
||||
return reg, NewStorage(reg)
|
||||
}
|
||||
|
||||
func testSecret(name string) *api.Secret {
|
||||
|
@ -45,8 +45,8 @@ type REST struct {
|
||||
clusterName string
|
||||
}
|
||||
|
||||
// NewREST returns a new REST.
|
||||
func NewREST(registry Registry, cloud cloudprovider.Interface, machines minion.Registry, portalNet *net.IPNet,
|
||||
// NewStorage returns a new REST.
|
||||
func NewStorage(registry Registry, cloud cloudprovider.Interface, machines minion.Registry, portalNet *net.IPNet,
|
||||
clusterName string) *REST {
|
||||
// TODO: Before we can replicate masters, this has to be synced (e.g. lives in etcd)
|
||||
ipa := newIPAllocator(portalNet)
|
||||
|
@ -44,7 +44,7 @@ func TestServiceRegistryCreate(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage.portalMgr.randomAttempts = 0
|
||||
|
||||
svc := &api.Service{
|
||||
@ -85,7 +85,7 @@ func TestServiceRegistryCreate(t *testing.T) {
|
||||
|
||||
func TestServiceStorageValidatesCreate(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
storage := NewREST(registry, nil, nil, makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, nil, nil, makeIPNet(t), "kubernetes")
|
||||
failureCases := map[string]api.Service{
|
||||
"empty ID": {
|
||||
ObjectMeta: api.ObjectMeta{Name: ""},
|
||||
@ -128,7 +128,7 @@ func TestServiceRegistryUpdate(t *testing.T) {
|
||||
Selector: map[string]string{"bar": "baz1"},
|
||||
},
|
||||
})
|
||||
storage := NewREST(registry, nil, nil, makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, nil, nil, makeIPNet(t), "kubernetes")
|
||||
updated_svc, created, err := storage.Update(ctx, &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -166,7 +166,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
|
||||
Selector: map[string]string{"bar": "baz"},
|
||||
},
|
||||
})
|
||||
storage := NewREST(registry, nil, nil, makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, nil, nil, makeIPNet(t), "kubernetes")
|
||||
failureCases := map[string]api.Service{
|
||||
"empty ID": {
|
||||
ObjectMeta: api.ObjectMeta{Name: ""},
|
||||
@ -203,7 +203,7 @@ func TestServiceRegistryExternalService(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
svc := &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -236,7 +236,7 @@ func TestServiceRegistryExternalServiceError(t *testing.T) {
|
||||
Err: fmt.Errorf("test error"),
|
||||
}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
svc := &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -262,7 +262,7 @@ func TestServiceRegistryDelete(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
svc := &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -286,7 +286,7 @@ func TestServiceRegistryDeleteExternal(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
svc := &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -311,7 +311,7 @@ func TestServiceRegistryUpdateExternalService(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
|
||||
// Create non-external load balancer.
|
||||
svc1 := &api.Service{
|
||||
@ -355,7 +355,7 @@ func TestServiceRegistryGet(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
registry.CreateService(ctx, &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -377,7 +377,7 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
|
||||
registry.Endpoints = api.Endpoints{Endpoints: []api.Endpoint{{IP: "foo", Port: 80}}}
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
registry.CreateService(ctx, &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -408,7 +408,7 @@ func TestServiceRegistryList(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
storage := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
registry.CreateService(ctx, &api.Service{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -445,7 +445,7 @@ func TestServiceRegistryIPAllocation(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
rest := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest.portalMgr.randomAttempts = 0
|
||||
|
||||
svc1 := &api.Service{
|
||||
@ -507,7 +507,7 @@ func TestServiceRegistryIPReallocation(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
rest := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest.portalMgr.randomAttempts = 0
|
||||
|
||||
svc1 := &api.Service{
|
||||
@ -555,7 +555,7 @@ func TestServiceRegistryIPUpdate(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
rest := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest.portalMgr.randomAttempts = 0
|
||||
|
||||
svc := &api.Service{
|
||||
@ -601,7 +601,7 @@ func TestServiceRegistryIPExternalLoadBalancer(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
rest := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest.portalMgr.randomAttempts = 0
|
||||
|
||||
svc := &api.Service{
|
||||
@ -640,7 +640,7 @@ func TestServiceRegistryIPReloadFromStorage(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
rest1 := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest1 := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest1.portalMgr.randomAttempts = 0
|
||||
|
||||
svc := &api.Service{
|
||||
@ -666,7 +666,7 @@ func TestServiceRegistryIPReloadFromStorage(t *testing.T) {
|
||||
rest1.Create(ctx, svc)
|
||||
|
||||
// This will reload from storage, finding the previous 2
|
||||
rest2 := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest2 := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest2.portalMgr.randomAttempts = 0
|
||||
|
||||
svc = &api.Service{
|
||||
@ -726,7 +726,7 @@ func TestCreate(t *testing.T) {
|
||||
registry := registrytest.NewServiceRegistry()
|
||||
fakeCloud := &cloud.FakeCloud{}
|
||||
machines := []string{"foo", "bar", "baz"}
|
||||
rest := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest := NewStorage(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t), "kubernetes")
|
||||
rest.portalMgr.randomAttempts = 0
|
||||
|
||||
test := resttest.New(t, rest, registry.SetError)
|
||||
|
Loading…
Reference in New Issue
Block a user