Skip to content

Commit 81b502b

Browse files
committed
Merge pull request kubernetes#1217 from lavalamp/fixApi
Rename all XStorage types to REST for clarity
2 parents a07836c + 759c3f9 commit 81b502b

File tree

13 files changed

+149
-147
lines changed

13 files changed

+149
-147
lines changed

pkg/master/master.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@ func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInf
114114
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
115115

116116
m.storage = map[string]apiserver.RESTStorage{
117-
"pods": pod.NewRegistryStorage(&pod.RegistryStorageConfig{
117+
"pods": pod.NewREST(&pod.RESTConfig{
118118
CloudProvider: cloud,
119119
PodCache: podCache,
120120
PodInfoGetter: podInfoGetter,
121121
Registry: m.podRegistry,
122122
}),
123-
"replicationControllers": controller.NewRegistryStorage(m.controllerRegistry, m.podRegistry),
124-
"services": service.NewRegistryStorage(m.serviceRegistry, cloud, m.minionRegistry),
125-
"endpoints": endpoint.NewStorage(m.endpointRegistry),
126-
"minions": minion.NewRegistryStorage(m.minionRegistry),
123+
"replicationControllers": controller.NewREST(m.controllerRegistry, m.podRegistry),
124+
"services": service.NewREST(m.serviceRegistry, cloud, m.minionRegistry),
125+
"endpoints": endpoint.NewREST(m.endpointRegistry),
126+
"minions": minion.NewREST(m.minionRegistry),
127127

128128
// TODO: should appear only in scheduler API group.
129-
"bindings": binding.NewBindingStorage(m.bindingRegistry),
129+
"bindings": binding.NewREST(m.bindingRegistry),
130130
}
131131
}
132132

pkg/registry/binding/storage.go renamed to pkg/registry/binding/rest.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,42 @@ import (
2626
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
2727
)
2828

29-
// BindingStorage implements the RESTStorage interface. When bindings are written, it
29+
// REST implements the RESTStorage interface for bindings. When bindings are written, it
3030
// changes the location of the affected pods. This information is eventually reflected
3131
// in the pod's CurrentState.Host field.
32-
type BindingStorage struct {
32+
type REST struct {
3333
registry Registry
3434
}
3535

36-
// NewBindingStorage creates a new BindingStorage backed by the given bindingRegistry.
37-
func NewBindingStorage(bindingRegistry Registry) *BindingStorage {
38-
return &BindingStorage{
36+
// NewREST creates a new REST backed by the given bindingRegistry.
37+
func NewREST(bindingRegistry Registry) *REST {
38+
return &REST{
3939
registry: bindingRegistry,
4040
}
4141
}
4242

4343
// List returns an error because bindings are write-only objects.
44-
func (*BindingStorage) List(selector labels.Selector) (runtime.Object, error) {
44+
func (*REST) List(selector labels.Selector) (runtime.Object, error) {
4545
return nil, errors.NewNotFound("binding", "list")
4646
}
4747

4848
// Get returns an error because bindings are write-only objects.
49-
func (*BindingStorage) Get(id string) (runtime.Object, error) {
49+
func (*REST) Get(id string) (runtime.Object, error) {
5050
return nil, errors.NewNotFound("binding", id)
5151
}
5252

5353
// Delete returns an error because bindings are write-only objects.
54-
func (*BindingStorage) Delete(id string) (<-chan runtime.Object, error) {
54+
func (*REST) Delete(id string) (<-chan runtime.Object, error) {
5555
return nil, errors.NewNotFound("binding", id)
5656
}
5757

5858
// New returns a new binding object fit for having data unmarshalled into it.
59-
func (*BindingStorage) New() runtime.Object {
59+
func (*REST) New() runtime.Object {
6060
return &api.Binding{}
6161
}
6262

6363
// Create attempts to make the assignment indicated by the binding it recieves.
64-
func (b *BindingStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) {
64+
func (b *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
6565
binding, ok := obj.(*api.Binding)
6666
if !ok {
6767
return nil, fmt.Errorf("incorrect type: %#v", obj)
@@ -75,6 +75,6 @@ func (b *BindingStorage) Create(obj runtime.Object) (<-chan runtime.Object, erro
7575
}
7676

7777
// Update returns an error-- this object may not be updated.
78-
func (b *BindingStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) {
78+
func (b *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
7979
return nil, fmt.Errorf("Bindings may not be changed.")
8080
}

pkg/registry/binding/storage_test.go renamed to pkg/registry/binding/rest_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import (
2828
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
2929
)
3030

31-
func TestNewBindingStorage(t *testing.T) {
31+
func TestNewREST(t *testing.T) {
3232
mockRegistry := MockRegistry{
3333
OnApplyBinding: func(b *api.Binding) error { return nil },
3434
}
35-
b := NewBindingStorage(mockRegistry)
35+
b := NewREST(mockRegistry)
3636

3737
binding := &api.Binding{
3838
PodID: "foo",
@@ -52,11 +52,11 @@ func TestNewBindingStorage(t *testing.T) {
5252
}
5353
}
5454

55-
func TestBindingStorageUnsupported(t *testing.T) {
55+
func TestRESTUnsupported(t *testing.T) {
5656
mockRegistry := MockRegistry{
5757
OnApplyBinding: func(b *api.Binding) error { return nil },
5858
}
59-
b := NewBindingStorage(mockRegistry)
59+
b := NewREST(mockRegistry)
6060
if _, err := b.Delete("binding id"); err == nil {
6161
t.Errorf("unexpected non-error")
6262
}
@@ -75,7 +75,7 @@ func TestBindingStorageUnsupported(t *testing.T) {
7575
}
7676
}
7777

78-
func TestBindingStoragePost(t *testing.T) {
78+
func TestRESTPost(t *testing.T) {
7979
table := []struct {
8080
b *api.Binding
8181
err error
@@ -94,7 +94,7 @@ func TestBindingStoragePost(t *testing.T) {
9494
return item.err
9595
},
9696
}
97-
b := NewBindingStorage(mockRegistry)
97+
b := NewREST(mockRegistry)
9898
resultChan, err := b.Create(item.b)
9999
if err != nil {
100100
t.Errorf("Unexpected error %v", err)

pkg/registry/controller/storage.go renamed to pkg/registry/controller/rest.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,36 @@ import (
2525
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
2626
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
2727
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
28-
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
2928
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
3029
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
3130
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
3231

3332
"code.google.com/p/go-uuid/uuid"
3433
)
3534

36-
// RegistryStorage stores data for the replication controller service.
37-
// It implements apiserver.RESTStorage.
38-
type RegistryStorage struct {
39-
registry Registry
40-
podRegistry pod.Registry
41-
pollPeriod time.Duration
35+
// PodLister is anything that knows how to list pods.
36+
type PodLister interface {
37+
ListPods(labels.Selector) (*api.PodList, error)
4238
}
4339

44-
// NewRegistryStorage returns a new apiserver.RESTStorage for the given
45-
// registry and podRegistry.
46-
func NewRegistryStorage(registry Registry, podRegistry pod.Registry) apiserver.RESTStorage {
47-
return &RegistryStorage{
48-
registry: registry,
49-
podRegistry: podRegistry,
50-
pollPeriod: time.Second * 10,
40+
// REST implements apiserver.RESTStorage for the replication controller service.
41+
type REST struct {
42+
registry Registry
43+
podLister PodLister
44+
pollPeriod time.Duration
45+
}
46+
47+
// NewREST returns a new apiserver.RESTStorage for the given registry and PodLister.
48+
func NewREST(registry Registry, podLister PodLister) *REST {
49+
return &REST{
50+
registry: registry,
51+
podLister: podLister,
52+
pollPeriod: time.Second * 10,
5153
}
5254
}
5355

5456
// Create registers the given ReplicationController.
55-
func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) {
57+
func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
5658
controller, ok := obj.(*api.ReplicationController)
5759
if !ok {
5860
return nil, fmt.Errorf("not a replication controller: %#v", obj)
@@ -78,14 +80,14 @@ func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, er
7880
}
7981

8082
// Delete asynchronously deletes the ReplicationController specified by its id.
81-
func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) {
83+
func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
8284
return apiserver.MakeAsync(func() (runtime.Object, error) {
8385
return &api.Status{Status: api.StatusSuccess}, rs.registry.DeleteController(id)
8486
}), nil
8587
}
8688

8789
// Get obtains the ReplicationController specified by its id.
88-
func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
90+
func (rs *REST) Get(id string) (runtime.Object, error) {
8991
controller, err := rs.registry.GetController(id)
9092
if err != nil {
9193
return nil, err
@@ -94,7 +96,7 @@ func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
9496
}
9597

9698
// List obtains a list of ReplicationControllers that match selector.
97-
func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error) {
99+
func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
98100
controllers, err := rs.registry.ListControllers()
99101
if err != nil {
100102
return nil, err
@@ -110,13 +112,13 @@ func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error
110112
}
111113

112114
// New creates a new ReplicationController for use with Create and Update.
113-
func (rs RegistryStorage) New() runtime.Object {
115+
func (*REST) New() runtime.Object {
114116
return &api.ReplicationController{}
115117
}
116118

117119
// Update replaces a given ReplicationController instance with an existing
118120
// instance in storage.registry.
119-
func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) {
121+
func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
120122
controller, ok := obj.(*api.ReplicationController)
121123
if !ok {
122124
return nil, fmt.Errorf("not a replication controller: %#v", obj)
@@ -135,7 +137,7 @@ func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, er
135137

136138
// Watch returns ReplicationController events via a watch.Interface.
137139
// It implements apiserver.ResourceWatcher.
138-
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
140+
func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
139141
if !field.Empty() {
140142
return nil, fmt.Errorf("no field selector implemented for controllers")
141143
}
@@ -149,9 +151,9 @@ func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion u
149151
}), nil
150152
}
151153

152-
func (rs *RegistryStorage) waitForController(ctrl *api.ReplicationController) (runtime.Object, error) {
154+
func (rs *REST) waitForController(ctrl *api.ReplicationController) (runtime.Object, error) {
153155
for {
154-
pods, err := rs.podRegistry.ListPods(labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector())
156+
pods, err := rs.podLister.ListPods(labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector())
155157
if err != nil {
156158
return ctrl, err
157159
}

pkg/registry/controller/storage_test.go renamed to pkg/registry/controller/rest_test.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
2828
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
29+
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
2930
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
3031
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
3132
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@@ -35,7 +36,7 @@ func TestListControllersError(t *testing.T) {
3536
mockRegistry := registrytest.ControllerRegistry{
3637
Err: fmt.Errorf("test error"),
3738
}
38-
storage := RegistryStorage{
39+
storage := REST{
3940
registry: &mockRegistry,
4041
}
4142
controllers, err := storage.List(nil)
@@ -49,7 +50,7 @@ func TestListControllersError(t *testing.T) {
4950

5051
func TestListEmptyControllerList(t *testing.T) {
5152
mockRegistry := registrytest.ControllerRegistry{nil, &api.ReplicationControllerList{JSONBase: api.JSONBase{ResourceVersion: 1}}}
52-
storage := RegistryStorage{
53+
storage := REST{
5354
registry: &mockRegistry,
5455
}
5556
controllers, err := storage.List(labels.Everything())
@@ -82,7 +83,7 @@ func TestListControllerList(t *testing.T) {
8283
},
8384
},
8485
}
85-
storage := RegistryStorage{
86+
storage := REST{
8687
registry: &mockRegistry,
8788
}
8889
controllersObj, err := storage.List(labels.Everything())
@@ -104,7 +105,7 @@ func TestListControllerList(t *testing.T) {
104105

105106
func TestControllerDecode(t *testing.T) {
106107
mockRegistry := registrytest.ControllerRegistry{}
107-
storage := RegistryStorage{
108+
storage := REST{
108109
registry: &mockRegistry,
109110
}
110111
controller := &api.ReplicationController{
@@ -226,10 +227,10 @@ func TestCreateController(t *testing.T) {
226227
},
227228
},
228229
}
229-
storage := RegistryStorage{
230-
registry: &mockRegistry,
231-
podRegistry: &mockPodRegistry,
232-
pollPeriod: time.Millisecond * 1,
230+
storage := REST{
231+
registry: &mockRegistry,
232+
podLister: &mockPodRegistry,
233+
pollPeriod: time.Millisecond * 1,
233234
}
234235
controller := &api.ReplicationController{
235236
JSONBase: api.JSONBase{ID: "test"},
@@ -257,10 +258,10 @@ func TestCreateController(t *testing.T) {
257258

258259
func TestControllerStorageValidatesCreate(t *testing.T) {
259260
mockRegistry := registrytest.ControllerRegistry{}
260-
storage := RegistryStorage{
261-
registry: &mockRegistry,
262-
podRegistry: nil,
263-
pollPeriod: time.Millisecond * 1,
261+
storage := REST{
262+
registry: &mockRegistry,
263+
podLister: nil,
264+
pollPeriod: time.Millisecond * 1,
264265
}
265266

266267
failureCases := map[string]api.ReplicationController{
@@ -288,10 +289,10 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
288289

289290
func TestControllerStorageValidatesUpdate(t *testing.T) {
290291
mockRegistry := registrytest.ControllerRegistry{}
291-
storage := RegistryStorage{
292-
registry: &mockRegistry,
293-
podRegistry: nil,
294-
pollPeriod: time.Millisecond * 1,
292+
storage := REST{
293+
registry: &mockRegistry,
294+
podLister: nil,
295+
pollPeriod: time.Millisecond * 1,
295296
}
296297
failureCases := map[string]api.ReplicationController{
297298
"empty ID": {

0 commit comments

Comments
 (0)