Move REST* interfaces into pkg/api/rest

Dependency chain is now api -> api/rest -> apiserver.  Makes the
interfaces much cleaner to read, and cleans up some inconsistenties
that crept in along the way.
This commit is contained in:
Clayton Coleman
2015-03-21 12:24:16 -04:00
parent df672504c2
commit d46087db50
30 changed files with 216 additions and 187 deletions

View File

@@ -71,14 +71,14 @@ type PodLister interface {
ListPods(ctx api.Context, labels labels.Selector) (*api.PodList, error)
}
// REST implements apiserver.RESTStorage for the replication controller service.
// REST implements rest.Storage for the replication controller service.
type REST struct {
registry Registry
podLister PodLister
strategy rcStrategy
}
// NewREST returns a new apiserver.RESTStorage for the given registry and PodLister.
// NewREST returns a new rest.Storage for the given registry and PodLister.
func NewREST(registry Registry, podLister PodLister) *REST {
return &REST{
registry: registry,
@@ -167,7 +167,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
}
// Watch returns ReplicationController events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
// It implements rest.Watcher.
func (rs *REST) Watch(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return rs.registry.WatchControllers(ctx, label, field, resourceVersion)
}

View File

@@ -32,7 +32,7 @@ type REST struct {
registry Registry
}
// NewREST returns a new apiserver.RESTStorage implementation for endpoints
// NewREST returns a new rest.Storage implementation for endpoints
func NewREST(registry Registry) *REST {
return &REST{
registry: registry,
@@ -53,7 +53,7 @@ func (rs *REST) List(ctx api.Context, label labels.Selector, field fields.Select
}
// Watch returns Endpoint events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
// It implements rest.Watcher.
func (rs *REST) Watch(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return rs.registry.WatchEndpoints(ctx, label, field, resourceVersion)
}

View File

@@ -135,7 +135,7 @@ func (rs *REST) List(ctx api.Context, label labels.Selector, field fields.Select
}
// Watch returns Events events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
// It implements rest.Watcher.
func (rs *REST) Watch(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return rs.registry.WatchPredicate(ctx, &generic.SelectionPredicate{label, field, rs.getAttrs}, resourceVersion)
}

View File

@@ -21,8 +21,8 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
@@ -74,8 +74,8 @@ func TestRESTCreate(t *testing.T) {
}
for _, item := range table {
_, rest := NewTestREST()
c, err := rest.Create(item.ctx, item.event)
_, storage := NewTestREST()
c, err := storage.Create(item.ctx, item.event)
if !item.valid {
if err == nil {
ctxNS := api.NamespaceValue(item.ctx)
@@ -94,7 +94,7 @@ func TestRESTCreate(t *testing.T) {
t.Errorf("diff: %s", util.ObjectDiff(e, a))
}
// Ensure we implement the interface
_ = apiserver.ResourceWatcher(rest)
_ = rest.Watcher(storage)
}
}

View File

@@ -38,7 +38,7 @@ type REST struct {
registry Registry
}
// NewREST returns a new apiserver.RESTStorage implementation for minion.
// NewREST returns a new rest.Storage implementation for minion.
func NewREST(m Registry) *REST {
return &REST{
registry: m,
@@ -133,7 +133,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
}
// Watch returns Minions events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
// It implements rest.Watcher.
func (rs *REST) Watch(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return rs.registry.WatchMinions(ctx, label, field, resourceVersion)
}

View File

@@ -18,7 +18,7 @@ package namespace
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@@ -44,10 +44,10 @@ type Registry interface {
// Storage is an interface for a standard REST Storage backend
// TODO: move me somewhere common
type Storage interface {
apiserver.RESTGracefulDeleter
apiserver.RESTLister
apiserver.RESTGetter
apiserver.ResourceWatcher
rest.GracefulDeleter
rest.Lister
rest.Getter
rest.Watcher
Create(ctx api.Context, obj runtime.Object) (runtime.Object, error)
Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error)

View File

@@ -26,8 +26,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
etcderrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest/resttest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
@@ -682,7 +682,7 @@ func TestResourceLocation(t *testing.T) {
cache := &fakeCache{statusToReturn: &api.PodStatus{PodIP: expectedIP}}
storage = storage.WithPodStatus(cache)
redirector := apiserver.Redirector(storage)
redirector := rest.Redirector(storage)
location, err := redirector.ResourceLocation(api.NewDefaultContext(), tc.query)
if err != nil {
t.Errorf("Unexpected error: %v", err)

View File

@@ -18,7 +18,7 @@ package pod
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@@ -44,10 +44,10 @@ type Registry interface {
// Storage is an interface for a standard REST Storage backend
// TODO: move me somewhere common
type Storage interface {
apiserver.RESTGracefulDeleter
apiserver.RESTLister
apiserver.RESTGetter
apiserver.ResourceWatcher
rest.GracefulDeleter
rest.Lister
rest.Getter
rest.Watcher
Create(ctx api.Context, obj runtime.Object) (runtime.Object, error)
Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error)

View File

@@ -18,7 +18,7 @@ package resourcequota
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@@ -44,10 +44,10 @@ type Registry interface {
// Storage is an interface for a standard REST Storage backend
// TODO: move me somewhere common
type Storage interface {
apiserver.RESTGracefulDeleter
apiserver.RESTLister
apiserver.RESTGetter
apiserver.ResourceWatcher
rest.GracefulDeleter
rest.Lister
rest.Getter
rest.Watcher
Create(ctx api.Context, obj runtime.Object) (runtime.Object, error)
Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error)

View File

@@ -21,7 +21,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
@@ -73,8 +73,8 @@ func TestRESTCreate(t *testing.T) {
}
for _, item := range table {
_, rest := NewTestREST()
c, err := rest.Create(item.ctx, item.secret)
_, storage := NewTestREST()
c, err := storage.Create(item.ctx, item.secret)
if !item.valid {
if err == nil {
ctxNS := api.NamespaceValue(item.ctx)
@@ -93,7 +93,7 @@ func TestRESTCreate(t *testing.T) {
t.Errorf("diff: %s", util.ObjectDiff(e, a))
}
// Ensure we implement the interface
_ = apiserver.ResourceWatcher(rest)
_ = rest.Watcher(storage)
}
}

View File

@@ -174,7 +174,7 @@ func (rs *REST) List(ctx api.Context, label labels.Selector, field fields.Select
}
// Watch returns Services events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
// It implements rest.Watcher.
func (rs *REST) Watch(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return rs.registry.WatchServices(ctx, label, field, resourceVersion)
}

View File

@@ -24,8 +24,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest/resttest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
cloud "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
@@ -384,7 +384,7 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
Selector: map[string]string{"bar": "baz"},
},
})
redirector := apiserver.Redirector(storage)
redirector := rest.Redirector(storage)
location, err := redirector.ResourceLocation(ctx, "foo")
if err != nil {
t.Errorf("Unexpected error: %v", err)