Merge pull request #1217 from lavalamp/fixApi

Rename all XStorage types to REST for clarity
This commit is contained in:
Tim Hockin 2014-09-08 15:38:47 -07:00
commit 81b502b0a6
13 changed files with 149 additions and 147 deletions

View File

@ -114,19 +114,19 @@ func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInf
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
m.storage = map[string]apiserver.RESTStorage{
"pods": pod.NewRegistryStorage(&pod.RegistryStorageConfig{
"pods": pod.NewREST(&pod.RESTConfig{
CloudProvider: cloud,
PodCache: podCache,
PodInfoGetter: podInfoGetter,
Registry: m.podRegistry,
}),
"replicationControllers": controller.NewRegistryStorage(m.controllerRegistry, m.podRegistry),
"services": service.NewRegistryStorage(m.serviceRegistry, cloud, m.minionRegistry),
"endpoints": endpoint.NewStorage(m.endpointRegistry),
"minions": minion.NewRegistryStorage(m.minionRegistry),
"replicationControllers": controller.NewREST(m.controllerRegistry, m.podRegistry),
"services": service.NewREST(m.serviceRegistry, cloud, m.minionRegistry),
"endpoints": endpoint.NewREST(m.endpointRegistry),
"minions": minion.NewREST(m.minionRegistry),
// TODO: should appear only in scheduler API group.
"bindings": binding.NewBindingStorage(m.bindingRegistry),
"bindings": binding.NewREST(m.bindingRegistry),
}
}

View File

@ -26,42 +26,42 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
// BindingStorage implements the RESTStorage interface. When bindings are written, it
// REST implements the RESTStorage interface for bindings. When bindings are written, it
// changes the location of the affected pods. This information is eventually reflected
// in the pod's CurrentState.Host field.
type BindingStorage struct {
type REST struct {
registry Registry
}
// NewBindingStorage creates a new BindingStorage backed by the given bindingRegistry.
func NewBindingStorage(bindingRegistry Registry) *BindingStorage {
return &BindingStorage{
// NewREST creates a new REST backed by the given bindingRegistry.
func NewREST(bindingRegistry Registry) *REST {
return &REST{
registry: bindingRegistry,
}
}
// List returns an error because bindings are write-only objects.
func (*BindingStorage) List(selector labels.Selector) (runtime.Object, error) {
func (*REST) List(selector labels.Selector) (runtime.Object, error) {
return nil, errors.NewNotFound("binding", "list")
}
// Get returns an error because bindings are write-only objects.
func (*BindingStorage) Get(id string) (runtime.Object, error) {
func (*REST) Get(id string) (runtime.Object, error) {
return nil, errors.NewNotFound("binding", id)
}
// Delete returns an error because bindings are write-only objects.
func (*BindingStorage) Delete(id string) (<-chan runtime.Object, error) {
func (*REST) Delete(id string) (<-chan runtime.Object, error) {
return nil, errors.NewNotFound("binding", id)
}
// New returns a new binding object fit for having data unmarshalled into it.
func (*BindingStorage) New() runtime.Object {
func (*REST) New() runtime.Object {
return &api.Binding{}
}
// Create attempts to make the assignment indicated by the binding it recieves.
func (b *BindingStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) {
func (b *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
binding, ok := obj.(*api.Binding)
if !ok {
return nil, fmt.Errorf("incorrect type: %#v", obj)
@ -75,6 +75,6 @@ func (b *BindingStorage) Create(obj runtime.Object) (<-chan runtime.Object, erro
}
// Update returns an error-- this object may not be updated.
func (b *BindingStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) {
func (b *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
return nil, fmt.Errorf("Bindings may not be changed.")
}

View File

@ -28,11 +28,11 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
func TestNewBindingStorage(t *testing.T) {
func TestNewREST(t *testing.T) {
mockRegistry := MockRegistry{
OnApplyBinding: func(b *api.Binding) error { return nil },
}
b := NewBindingStorage(mockRegistry)
b := NewREST(mockRegistry)
binding := &api.Binding{
PodID: "foo",
@ -52,11 +52,11 @@ func TestNewBindingStorage(t *testing.T) {
}
}
func TestBindingStorageUnsupported(t *testing.T) {
func TestRESTUnsupported(t *testing.T) {
mockRegistry := MockRegistry{
OnApplyBinding: func(b *api.Binding) error { return nil },
}
b := NewBindingStorage(mockRegistry)
b := NewREST(mockRegistry)
if _, err := b.Delete("binding id"); err == nil {
t.Errorf("unexpected non-error")
}
@ -75,7 +75,7 @@ func TestBindingStorageUnsupported(t *testing.T) {
}
}
func TestBindingStoragePost(t *testing.T) {
func TestRESTPost(t *testing.T) {
table := []struct {
b *api.Binding
err error
@ -94,7 +94,7 @@ func TestBindingStoragePost(t *testing.T) {
return item.err
},
}
b := NewBindingStorage(mockRegistry)
b := NewREST(mockRegistry)
resultChan, err := b.Create(item.b)
if err != nil {
t.Errorf("Unexpected error %v", err)

View File

@ -25,7 +25,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
@ -33,26 +32,29 @@ import (
"code.google.com/p/go-uuid/uuid"
)
// RegistryStorage stores data for the replication controller service.
// It implements apiserver.RESTStorage.
type RegistryStorage struct {
registry Registry
podRegistry pod.Registry
pollPeriod time.Duration
// PodLister is anything that knows how to list pods.
type PodLister interface {
ListPods(labels.Selector) (*api.PodList, error)
}
// NewRegistryStorage returns a new apiserver.RESTStorage for the given
// registry and podRegistry.
func NewRegistryStorage(registry Registry, podRegistry pod.Registry) apiserver.RESTStorage {
return &RegistryStorage{
registry: registry,
podRegistry: podRegistry,
pollPeriod: time.Second * 10,
// REST implements apiserver.RESTStorage for the replication controller service.
type REST struct {
registry Registry
podLister PodLister
pollPeriod time.Duration
}
// NewREST returns a new apiserver.RESTStorage for the given registry and PodLister.
func NewREST(registry Registry, podLister PodLister) *REST {
return &REST{
registry: registry,
podLister: podLister,
pollPeriod: time.Second * 10,
}
}
// Create registers the given ReplicationController.
func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
controller, ok := obj.(*api.ReplicationController)
if !ok {
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
}
// Delete asynchronously deletes the ReplicationController specified by its id.
func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) {
func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
return apiserver.MakeAsync(func() (runtime.Object, error) {
return &api.Status{Status: api.StatusSuccess}, rs.registry.DeleteController(id)
}), nil
}
// Get obtains the ReplicationController specified by its id.
func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
func (rs *REST) Get(id string) (runtime.Object, error) {
controller, err := rs.registry.GetController(id)
if err != nil {
return nil, err
@ -94,7 +96,7 @@ func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
}
// List obtains a list of ReplicationControllers that match selector.
func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error) {
func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
controllers, err := rs.registry.ListControllers()
if err != nil {
return nil, err
@ -110,13 +112,13 @@ func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error
}
// New creates a new ReplicationController for use with Create and Update.
func (rs RegistryStorage) New() runtime.Object {
func (*REST) New() runtime.Object {
return &api.ReplicationController{}
}
// Update replaces a given ReplicationController instance with an existing
// instance in storage.registry.
func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
controller, ok := obj.(*api.ReplicationController)
if !ok {
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
// Watch returns ReplicationController events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
if !field.Empty() {
return nil, fmt.Errorf("no field selector implemented for controllers")
}
@ -149,9 +151,9 @@ func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion u
}), nil
}
func (rs *RegistryStorage) waitForController(ctrl *api.ReplicationController) (runtime.Object, error) {
func (rs *REST) waitForController(ctrl *api.ReplicationController) (runtime.Object, error) {
for {
pods, err := rs.podRegistry.ListPods(labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector())
pods, err := rs.podLister.ListPods(labels.Set(ctrl.DesiredState.ReplicaSelector).AsSelector())
if err != nil {
return ctrl, err
}

View File

@ -26,6 +26,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
@ -35,7 +36,7 @@ func TestListControllersError(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{
Err: fmt.Errorf("test error"),
}
storage := RegistryStorage{
storage := REST{
registry: &mockRegistry,
}
controllers, err := storage.List(nil)
@ -49,7 +50,7 @@ func TestListControllersError(t *testing.T) {
func TestListEmptyControllerList(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{nil, &api.ReplicationControllerList{JSONBase: api.JSONBase{ResourceVersion: 1}}}
storage := RegistryStorage{
storage := REST{
registry: &mockRegistry,
}
controllers, err := storage.List(labels.Everything())
@ -82,7 +83,7 @@ func TestListControllerList(t *testing.T) {
},
},
}
storage := RegistryStorage{
storage := REST{
registry: &mockRegistry,
}
controllersObj, err := storage.List(labels.Everything())
@ -104,7 +105,7 @@ func TestListControllerList(t *testing.T) {
func TestControllerDecode(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{}
storage := RegistryStorage{
storage := REST{
registry: &mockRegistry,
}
controller := &api.ReplicationController{
@ -226,10 +227,10 @@ func TestCreateController(t *testing.T) {
},
},
}
storage := RegistryStorage{
registry: &mockRegistry,
podRegistry: &mockPodRegistry,
pollPeriod: time.Millisecond * 1,
storage := REST{
registry: &mockRegistry,
podLister: &mockPodRegistry,
pollPeriod: time.Millisecond * 1,
}
controller := &api.ReplicationController{
JSONBase: api.JSONBase{ID: "test"},
@ -257,10 +258,10 @@ func TestCreateController(t *testing.T) {
func TestControllerStorageValidatesCreate(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{}
storage := RegistryStorage{
registry: &mockRegistry,
podRegistry: nil,
pollPeriod: time.Millisecond * 1,
storage := REST{
registry: &mockRegistry,
podLister: nil,
pollPeriod: time.Millisecond * 1,
}
failureCases := map[string]api.ReplicationController{
@ -288,10 +289,10 @@ func TestControllerStorageValidatesCreate(t *testing.T) {
func TestControllerStorageValidatesUpdate(t *testing.T) {
mockRegistry := registrytest.ControllerRegistry{}
storage := RegistryStorage{
registry: &mockRegistry,
podRegistry: nil,
pollPeriod: time.Millisecond * 1,
storage := REST{
registry: &mockRegistry,
podLister: nil,
pollPeriod: time.Millisecond * 1,
}
failureCases := map[string]api.ReplicationController{
"empty ID": {

View File

@ -20,31 +20,30 @@ import (
"errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
// Storage adapts endpoints into apiserver's RESTStorage model.
type Storage struct {
// REST adapts endpoints into apiserver's RESTStorage model.
type REST struct {
registry Registry
}
// NewStorage returns a new Storage implementation for endpoints
func NewStorage(registry Registry) apiserver.RESTStorage {
return &Storage{
// NewREST returns a new apiserver.RESTStorage implementation for endpoints
func NewREST(registry Registry) *REST {
return &REST{
registry: registry,
}
}
// Get satisfies the RESTStorage interface.
func (rs *Storage) Get(id string) (runtime.Object, error) {
func (rs *REST) Get(id string) (runtime.Object, error) {
return rs.registry.GetEndpoints(id)
}
// List satisfies the RESTStorage interface.
func (rs *Storage) List(selector labels.Selector) (runtime.Object, error) {
func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
if !selector.Empty() {
return nil, errors.New("label selectors are not supported on endpoints")
}
@ -53,26 +52,26 @@ func (rs *Storage) List(selector labels.Selector) (runtime.Object, error) {
// Watch returns Endpoint events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
func (rs *Storage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
return rs.registry.WatchEndpoints(label, field, resourceVersion)
}
// Create satisfies the RESTStorage interface but is unimplemented.
func (rs *Storage) Create(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
return nil, errors.New("unimplemented")
}
// Update satisfies the RESTStorage interface but is unimplemented.
func (rs *Storage) Update(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
return nil, errors.New("unimplemented")
}
// Delete satisfies the RESTStorage interface but is unimplemented.
func (rs *Storage) Delete(id string) (<-chan runtime.Object, error) {
func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
return nil, errors.New("unimplemented")
}
// New implements the RESTStorage interface.
func (rs Storage) New() runtime.Object {
func (rs REST) New() runtime.Object {
return &api.Endpoints{}
}

View File

@ -33,7 +33,7 @@ func TestGetEndpoints(t *testing.T) {
Endpoints: []string{"127.0.0.1:9000"},
},
}
storage := NewStorage(registry)
storage := NewREST(registry)
obj, err := storage.Get("foo")
if err != nil {
t.Fatalf("unexpected error: %#v", err)
@ -47,7 +47,7 @@ func TestGetEndpointsMissingService(t *testing.T) {
registry := &registrytest.ServiceRegistry{
Err: errors.NewNotFound("service", "foo"),
}
storage := NewStorage(registry)
storage := NewREST(registry)
// returns service not found
_, err := storage.Get("foo")
@ -71,7 +71,7 @@ func TestGetEndpointsMissingService(t *testing.T) {
func TestEndpointsRegistryList(t *testing.T) {
registry := registrytest.NewServiceRegistry()
storage := NewStorage(registry)
storage := NewREST(registry)
registry.EndpointsList = api.EndpointsList{
JSONBase: api.JSONBase{ResourceVersion: 1},
Items: []api.Endpoints{

View File

@ -26,19 +26,19 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
// RegistryStorage implements the RESTStorage interface, backed by a MinionRegistry.
type RegistryStorage struct {
// REST implements the RESTStorage interface, backed by a MinionRegistry.
type REST struct {
registry Registry
}
// NewRegistryStorage returns a new RegistryStorage.
func NewRegistryStorage(m Registry) apiserver.RESTStorage {
return &RegistryStorage{
// NewREST returns a new REST.
func NewREST(m Registry) *REST {
return &REST{
registry: m,
}
}
func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
minion, ok := obj.(*api.Minion)
if !ok {
return nil, fmt.Errorf("not a minion: %#v", obj)
@ -65,7 +65,7 @@ func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, er
}), nil
}
func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) {
func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
exists, err := rs.registry.Contains(id)
if !exists {
return nil, ErrDoesNotExist
@ -78,7 +78,7 @@ func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) {
}), nil
}
func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
func (rs *REST) Get(id string) (runtime.Object, error) {
exists, err := rs.registry.Contains(id)
if !exists {
return nil, ErrDoesNotExist
@ -86,7 +86,7 @@ func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
return rs.toApiMinion(id), err
}
func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error) {
func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
nameList, err := rs.registry.List()
if err != nil {
return nil, err
@ -98,14 +98,14 @@ func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error
return &list, nil
}
func (rs RegistryStorage) New() runtime.Object {
func (*REST) New() runtime.Object {
return &api.Minion{}
}
func (rs *RegistryStorage) Update(minion runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Update(minion runtime.Object) (<-chan runtime.Object, error) {
return nil, fmt.Errorf("Minions can only be created (inserted) and deleted.")
}
func (rs *RegistryStorage) toApiMinion(name string) *api.Minion {
func (rs *REST) toApiMinion(name string) *api.Minion {
return &api.Minion{JSONBase: api.JSONBase{ID: name}}
}

View File

@ -24,9 +24,9 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
)
func TestMinionRegistryStorage(t *testing.T) {
func TestMinionREST(t *testing.T) {
m := NewRegistry([]string{"foo", "bar"})
ms := NewRegistryStorage(m)
ms := NewREST(m)
if obj, err := ms.Get("foo"); err != nil || obj.(*api.Minion).ID != "foo" {
t.Errorf("missing expected object")

View File

@ -37,8 +37,8 @@ import (
"github.com/golang/glog"
)
// RegistryStorage implements the RESTStorage interface in terms of a PodRegistry.
type RegistryStorage struct {
// REST implements the RESTStorage interface in terms of a PodRegistry.
type REST struct {
cloudProvider cloudprovider.Interface
mu sync.Mutex
podCache client.PodInfoGetter
@ -47,16 +47,16 @@ type RegistryStorage struct {
registry Registry
}
type RegistryStorageConfig struct {
type RESTConfig struct {
CloudProvider cloudprovider.Interface
PodCache client.PodInfoGetter
PodInfoGetter client.PodInfoGetter
Registry Registry
}
// NewRegistryStorage returns a new RegistryStorage.
func NewRegistryStorage(config *RegistryStorageConfig) apiserver.RESTStorage {
return &RegistryStorage{
// NewREST returns a new REST.
func NewREST(config *RESTConfig) *REST {
return &REST{
cloudProvider: config.CloudProvider,
podCache: config.PodCache,
podInfoGetter: config.PodInfoGetter,
@ -65,7 +65,7 @@ func NewRegistryStorage(config *RegistryStorageConfig) apiserver.RESTStorage {
}
}
func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
pod := obj.(*api.Pod)
pod.DesiredState.Manifest.UUID = uuid.NewUUID().String()
if len(pod.ID) == 0 {
@ -86,13 +86,13 @@ func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, er
}), nil
}
func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) {
func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
return apiserver.MakeAsync(func() (runtime.Object, error) {
return &api.Status{Status: api.StatusSuccess}, rs.registry.DeletePod(id)
}), nil
}
func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
func (rs *REST) Get(id string) (runtime.Object, error) {
pod, err := rs.registry.GetPod(id)
if err != nil {
return pod, err
@ -108,7 +108,7 @@ func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
return pod, err
}
func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error) {
func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
pods, err := rs.registry.ListPods(selector)
if err == nil {
for i := range pods.Items {
@ -122,7 +122,7 @@ func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error
}
// Watch begins watching for new, changed, or deleted pods.
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
return rs.registry.WatchPods(resourceVersion, func(pod *api.Pod) bool {
fields := labels.Set{
"ID": pod.ID,
@ -133,11 +133,11 @@ func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion u
})
}
func (rs RegistryStorage) New() runtime.Object {
func (*REST) New() runtime.Object {
return &api.Pod{}
}
func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
pod := obj.(*api.Pod)
if errs := validation.ValidatePod(pod); len(errs) > 0 {
return nil, errors.NewInvalid("pod", pod.ID, errs)
@ -150,7 +150,7 @@ func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, er
}), nil
}
func (rs *RegistryStorage) fillPodInfo(pod *api.Pod) {
func (rs *REST) fillPodInfo(pod *api.Pod) {
pod.CurrentState.Host = pod.DesiredState.Host
if pod.CurrentState.Host == "" {
return
@ -237,7 +237,7 @@ func getPodStatus(pod *api.Pod) api.PodStatus {
}
}
func (rs *RegistryStorage) waitForPodRunning(pod *api.Pod) (runtime.Object, error) {
func (rs *REST) waitForPodRunning(pod *api.Pod) (runtime.Object, error) {
for {
podObj, err := rs.Get(pod.ID)
if err != nil || podObj == nil {

View File

@ -57,7 +57,7 @@ func expectPod(t *testing.T, ch <-chan runtime.Object) (*api.Pod, bool) {
func TestCreatePodRegistryError(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
desiredState := api.PodState{
@ -76,7 +76,7 @@ func TestCreatePodRegistryError(t *testing.T) {
func TestCreatePodSetsIds(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
desiredState := api.PodState{
@ -102,7 +102,7 @@ func TestCreatePodSetsIds(t *testing.T) {
func TestCreatePodSetsUUIDs(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
desiredState := api.PodState{
@ -125,7 +125,7 @@ func TestCreatePodSetsUUIDs(t *testing.T) {
func TestListPodsError(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
pods, err := storage.List(labels.Everything())
@ -139,7 +139,7 @@ func TestListPodsError(t *testing.T) {
func TestListEmptyPodList(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(&api.PodList{JSONBase: api.JSONBase{ResourceVersion: 1}})
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
pods, err := storage.List(labels.Everything())
@ -171,7 +171,7 @@ func TestListPodList(t *testing.T) {
},
},
}
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
podsObj, err := storage.List(labels.Everything())
@ -193,7 +193,7 @@ func TestListPodList(t *testing.T) {
func TestPodDecode(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil)
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
expected := &api.Pod{
@ -219,7 +219,7 @@ func TestPodDecode(t *testing.T) {
func TestGetPod(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
obj, err := storage.Get("foo")
@ -237,7 +237,7 @@ func TestGetPodCloud(t *testing.T) {
fakeCloud := &fake_cloud.FakeCloud{}
podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
cloudProvider: fakeCloud,
}
@ -352,7 +352,7 @@ func TestMakePodStatus(t *testing.T) {
func TestPodStorageValidatesCreate(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
pod := &api.Pod{}
@ -368,7 +368,7 @@ func TestPodStorageValidatesCreate(t *testing.T) {
func TestPodStorageValidatesUpdate(t *testing.T) {
podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Err = fmt.Errorf("test error")
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
}
pod := &api.Pod{}
@ -389,7 +389,7 @@ func TestCreatePod(t *testing.T) {
Host: "machine",
},
}
storage := RegistryStorage{
storage := REST{
registry: podRegistry,
podPollPeriod: time.Millisecond * 100,
}
@ -437,7 +437,7 @@ func TestFillPodInfo(t *testing.T) {
},
},
}
storage := RegistryStorage{
storage := REST{
podCache: &fakeGetter,
}
pod := api.Pod{DesiredState: api.PodState{Host: "foo"}}
@ -460,7 +460,7 @@ func TestFillPodInfoNoData(t *testing.T) {
},
},
}
storage := RegistryStorage{
storage := REST{
podCache: &fakeGetter,
}
pod := api.Pod{DesiredState: api.PodState{Host: "foo"}}

View File

@ -34,23 +34,23 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
// RegistryStorage adapts a service registry into apiserver's RESTStorage model.
type RegistryStorage struct {
// REST adapts a service registry into apiserver's RESTStorage model.
type REST struct {
registry Registry
cloud cloudprovider.Interface
machines minion.Registry
}
// NewRegistryStorage returns a new RegistryStorage.
func NewRegistryStorage(registry Registry, cloud cloudprovider.Interface, machines minion.Registry) apiserver.RESTStorage {
return &RegistryStorage{
// NewREST returns a new REST.
func NewREST(registry Registry, cloud cloudprovider.Interface, machines minion.Registry) *REST {
return &REST{
registry: registry,
cloud: cloud,
machines: machines,
}
}
func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Create(obj runtime.Object) (<-chan runtime.Object, error) {
srv := obj.(*api.Service)
if errs := validation.ValidateService(srv); len(errs) > 0 {
return nil, errors.NewInvalid("service", srv.ID, errs)
@ -94,7 +94,7 @@ func (rs *RegistryStorage) Create(obj runtime.Object) (<-chan runtime.Object, er
}), nil
}
func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) {
func (rs *REST) Delete(id string) (<-chan runtime.Object, error) {
service, err := rs.registry.GetService(id)
if err != nil {
return nil, err
@ -105,7 +105,7 @@ func (rs *RegistryStorage) Delete(id string) (<-chan runtime.Object, error) {
}), nil
}
func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
func (rs *REST) Get(id string) (runtime.Object, error) {
s, err := rs.registry.GetService(id)
if err != nil {
return nil, err
@ -113,7 +113,7 @@ func (rs *RegistryStorage) Get(id string) (runtime.Object, error) {
return s, err
}
func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error) {
func (rs *REST) List(selector labels.Selector) (runtime.Object, error) {
list, err := rs.registry.ListServices()
if err != nil {
return nil, err
@ -130,11 +130,11 @@ func (rs *RegistryStorage) List(selector labels.Selector) (runtime.Object, error
// Watch returns Services events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
func (rs *REST) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
return rs.registry.WatchServices(label, field, resourceVersion)
}
func (rs RegistryStorage) New() runtime.Object {
func (*REST) New() runtime.Object {
return &api.Service{}
}
@ -156,7 +156,7 @@ func GetServiceEnvironmentVariables(registry Registry, machine string) ([]api.En
return result, nil
}
func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, error) {
func (rs *REST) Update(obj runtime.Object) (<-chan runtime.Object, error) {
srv := obj.(*api.Service)
if errs := validation.ValidateService(srv); len(errs) > 0 {
return nil, errors.NewInvalid("service", srv.ID, errs)
@ -172,7 +172,7 @@ func (rs *RegistryStorage) Update(obj runtime.Object) (<-chan runtime.Object, er
}
// ResourceLocation returns a URL to which one can send traffic for the specified service.
func (rs *RegistryStorage) ResourceLocation(id string) (string, error) {
func (rs *REST) ResourceLocation(id string) (string, error) {
e, err := rs.registry.GetEndpoints(id)
if err != nil {
return "", err
@ -183,7 +183,7 @@ func (rs *RegistryStorage) ResourceLocation(id string) (string, error) {
return "http://" + e.Endpoints[rand.Intn(len(e.Endpoints))], nil
}
func (rs *RegistryStorage) deleteExternalLoadBalancer(service *api.Service) error {
func (rs *REST) deleteExternalLoadBalancer(service *api.Service) error {
if !service.CreateExternalLoadBalancer || rs.cloud == nil {
return nil
}

View File

@ -34,7 +34,7 @@ func TestServiceRegistryCreate(t *testing.T) {
registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
@ -63,7 +63,7 @@ func TestServiceRegistryCreate(t *testing.T) {
func TestServiceStorageValidatesCreate(t *testing.T) {
registry := registrytest.NewServiceRegistry()
storage := NewRegistryStorage(registry, nil, nil)
storage := NewREST(registry, nil, nil)
failureCases := map[string]api.Service{
"empty ID": {
Port: 6502,
@ -94,7 +94,7 @@ func TestServiceRegistryUpdate(t *testing.T) {
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz1"},
})
storage := NewRegistryStorage(registry, nil, nil)
storage := NewREST(registry, nil, nil)
c, err := storage.Update(&api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
@ -123,7 +123,7 @@ func TestServiceStorageValidatesUpdate(t *testing.T) {
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
})
storage := NewRegistryStorage(registry, nil, nil)
storage := NewREST(registry, nil, nil)
failureCases := map[string]api.Service{
"empty ID": {
Port: 6502,
@ -151,7 +151,7 @@ func TestServiceRegistryExternalService(t *testing.T) {
registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
@ -178,7 +178,7 @@ func TestServiceRegistryExternalServiceError(t *testing.T) {
Err: fmt.Errorf("test error"),
}
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
@ -199,7 +199,7 @@ func TestServiceRegistryDelete(t *testing.T) {
registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
@ -219,7 +219,7 @@ func TestServiceRegistryDeleteExternal(t *testing.T) {
registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
@ -262,7 +262,7 @@ func TestServiceRegistryGet(t *testing.T) {
registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
registry.CreateService(&api.Service{
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
@ -281,12 +281,12 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
registry.Endpoints = api.Endpoints{Endpoints: []string{"foo:80"}}
fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
registry.CreateService(&api.Service{
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
})
redirector := storage.(apiserver.Redirector)
redirector := apiserver.Redirector(storage)
location, err := redirector.ResourceLocation("foo")
if err != nil {
t.Errorf("Unexpected error: %v", err)
@ -309,7 +309,7 @@ func TestServiceRegistryList(t *testing.T) {
registry := registrytest.NewServiceRegistry()
fakeCloud := &cloud.FakeCloud{}
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
storage := NewREST(registry, fakeCloud, minion.NewRegistry(machines))
registry.CreateService(&api.Service{
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},