From ef7cce5dad20380e1a84b677132e525a11e5aede Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Sat, 7 Jun 2014 21:07:20 -0700 Subject: [PATCH 1/3] Populate 'Kind' field in all API types being returned. --- pkg/api/types.go | 1 + pkg/apiserver/api_server.go | 5 +++-- pkg/registry/controller_registry.go | 6 ++++-- pkg/registry/service_registry.go | 8 ++++++-- pkg/registry/task_registry.go | 2 ++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index c0e3d1188a8..79225f6fe8f 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -130,6 +130,7 @@ type TaskTemplate struct { // ServiceList holds a list of services type ServiceList struct { + JSONBase Items []Service `json:"items" yaml:"items"` } diff --git a/pkg/apiserver/api_server.go b/pkg/apiserver/api_server.go index 257df303a7f..d648e373173 100644 --- a/pkg/apiserver/api_server.go +++ b/pkg/apiserver/api_server.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package apiserver is ... +// Package apiserver contains the code that provides a RESTful api service package apiserver import ( @@ -50,13 +50,14 @@ type Status struct { // TODO: consider migrating this to go-restful which is a more full-featured version of the same thing. type ApiServer struct { prefix string + apiName string storage map[string]RESTStorage } // New creates a new ApiServer object. // 'storage' contains a map of handlers. // 'prefix' is the hosting path prefix. -func New(storage map[string]RESTStorage, prefix string) *ApiServer { +func New(storage map[string]RESTStorage, prefix, apiName string) *ApiServer { return &ApiServer{ storage: storage, prefix: prefix, diff --git a/pkg/registry/controller_registry.go b/pkg/registry/controller_registry.go index 53bab4c8bc4..05bf8e40711 100644 --- a/pkg/registry/controller_registry.go +++ b/pkg/registry/controller_registry.go @@ -35,7 +35,7 @@ func MakeControllerRegistryStorage(registry ControllerRegistry) apiserver.RESTSt } func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) { - var result ReplicationControllerList + result := ReplicationControllerList{JSONBase: JSONBase{Kind: "cluster#replicationControllerList"}} controllers, err := storage.registry.ListControllers() if err == nil { result = ReplicationControllerList{ @@ -46,7 +46,9 @@ func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) { } func (storage *ControllerRegistryStorage) Get(id string) (interface{}, error) { - return storage.registry.GetController(id) + controller, err := storage.registry.GetController(id) + controller.Kind = "cluster#replicationController" + return controller, err } func (storage *ControllerRegistryStorage) Delete(id string) error { diff --git a/pkg/registry/service_registry.go b/pkg/registry/service_registry.go index 7780a7f6564..542219f001f 100644 --- a/pkg/registry/service_registry.go +++ b/pkg/registry/service_registry.go @@ -60,11 +60,15 @@ func GetServiceEnvironmentVariables(registry ServiceRegistry, machine string) ([ } func (sr *ServiceRegistryStorage) List(*url.URL) (interface{}, error) { - return sr.registry.ListServices() + list, err := sr.registry.ListServices() + list.Kind = "cluster#serviceList" + return list, err } func (sr *ServiceRegistryStorage) Get(id string) (interface{}, error) { - return sr.registry.GetService(id) + service, err := sr.registry.GetService(id) + service.Kind = "cluster#service" + return service, err } func (sr *ServiceRegistryStorage) Delete(id string) error { diff --git a/pkg/registry/task_registry.go b/pkg/registry/task_registry.go index 4623f081a75..7d5af8825e8 100644 --- a/pkg/registry/task_registry.go +++ b/pkg/registry/task_registry.go @@ -76,6 +76,7 @@ func (storage *TaskRegistryStorage) List(url *url.URL) (interface{}, error) { Items: tasks, } } + result.Kind = "cluster#taskList" return result, err } @@ -89,6 +90,7 @@ func (storage *TaskRegistryStorage) Get(id string) (interface{}, error) { return task, err } task.CurrentState.Info = info + task.Kind = "cluster#task" return task, err } From 6e7b3fd969c4466bb54b520184ca743a547e223b Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Sat, 7 Jun 2014 21:56:14 -0700 Subject: [PATCH 2/3] Fix a compile error. --- pkg/apiserver/api_server.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/apiserver/api_server.go b/pkg/apiserver/api_server.go index d648e373173..376d4542f59 100644 --- a/pkg/apiserver/api_server.go +++ b/pkg/apiserver/api_server.go @@ -50,14 +50,13 @@ type Status struct { // TODO: consider migrating this to go-restful which is a more full-featured version of the same thing. type ApiServer struct { prefix string - apiName string storage map[string]RESTStorage } // New creates a new ApiServer object. // 'storage' contains a map of handlers. // 'prefix' is the hosting path prefix. -func New(storage map[string]RESTStorage, prefix, apiName string) *ApiServer { +func New(storage map[string]RESTStorage, prefix string) *ApiServer { return &ApiServer{ storage: storage, prefix: prefix, From 01819532421e4a9525aa311ea8f3c28e23d0d9fe Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Sat, 7 Jun 2014 21:57:36 -0700 Subject: [PATCH 3/3] Add kind in all cases for list. --- pkg/registry/controller_registry.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/registry/controller_registry.go b/pkg/registry/controller_registry.go index 05bf8e40711..126b006d1a9 100644 --- a/pkg/registry/controller_registry.go +++ b/pkg/registry/controller_registry.go @@ -39,7 +39,8 @@ func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) { controllers, err := storage.registry.ListControllers() if err == nil { result = ReplicationControllerList{ - Items: controllers, + JSONBase: JSONBase{Kind: "cluster#replicationControllerList"}, + Items: controllers, } } return result, err