diff --git a/pkg/registry/controller_registry.go b/pkg/registry/controller_registry.go index d71e7f90b1f..f5dc00dd36e 100644 --- a/pkg/registry/controller_registry.go +++ b/pkg/registry/controller_registry.go @@ -17,8 +17,6 @@ limitations under the License. package registry import ( - "encoding/json" - "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" @@ -53,7 +51,6 @@ func (storage *ControllerRegistryStorage) Get(id string) (interface{}, error) { if err != nil { return nil, err } - controller.Kind = "cluster#replicationController" return controller, err } @@ -63,8 +60,7 @@ func (storage *ControllerRegistryStorage) Delete(id string) (<-chan interface{}, func (storage *ControllerRegistryStorage) Extract(body []byte) (interface{}, error) { result := api.ReplicationController{} - err := json.Unmarshal(body, &result) - result.Kind = "cluster#replicationController" + err := api.DecodeInto(body, &result) return result, err } diff --git a/pkg/registry/controller_registry_test.go b/pkg/registry/controller_registry_test.go index 5a96d211470..69b04e03e3b 100644 --- a/pkg/registry/controller_registry_test.go +++ b/pkg/registry/controller_registry_test.go @@ -121,12 +121,10 @@ func TestExtractControllerJson(t *testing.T) { ID: "foo", }, } - body, err := json.Marshal(controller) + body, err := api.Encode(&controller) expectNoError(t, err) controllerOut, err := storage.Extract(body) expectNoError(t, err) - // Extract adds a Kind - controller.Kind = "cluster#replicationController" if !reflect.DeepEqual(controller, controllerOut) { t.Errorf("Expected %#v, found %#v", controller, controllerOut) } diff --git a/pkg/registry/pod_registry.go b/pkg/registry/pod_registry.go index f1b1de4fa75..f74dea980f2 100644 --- a/pkg/registry/pod_registry.go +++ b/pkg/registry/pod_registry.go @@ -16,7 +16,6 @@ limitations under the License. package registry import ( - "encoding/json" "fmt" "log" "strings" @@ -73,7 +72,6 @@ func (storage *PodRegistryStorage) List(selector labels.Selector) (interface{}, } } - result.Kind = "cluster#podList" return result, err } @@ -128,7 +126,6 @@ func (storage *PodRegistryStorage) Get(id string) (interface{}, error) { } pod.CurrentState.HostIP = getInstanceIP(storage.cloud, pod.CurrentState.Host) - pod.Kind = "cluster#pod" return pod, err } @@ -138,8 +135,7 @@ func (storage *PodRegistryStorage) Delete(id string) (<-chan interface{}, error) func (storage *PodRegistryStorage) Extract(body []byte) (interface{}, error) { pod := api.Pod{} - err := json.Unmarshal(body, &pod) - pod.Kind = "cluster#pod" + err := api.DecodeInto(body, &pod) return pod, err } diff --git a/pkg/registry/pod_registry_test.go b/pkg/registry/pod_registry_test.go index d984feac56a..8034f3c4a7a 100644 --- a/pkg/registry/pod_registry_test.go +++ b/pkg/registry/pod_registry_test.go @@ -16,7 +16,6 @@ limitations under the License. package registry import ( - "encoding/json" "fmt" "reflect" "testing" @@ -102,12 +101,10 @@ func TestExtractJson(t *testing.T) { ID: "foo", }, } - body, err := json.Marshal(pod) + body, err := api.Encode(&pod) expectNoError(t, err) podOut, err := storage.Extract(body) expectNoError(t, err) - // Extract adds in a kind - pod.Kind = "cluster#pod" if !reflect.DeepEqual(pod, podOut) { t.Errorf("Expected %#v, found %#v", pod, podOut) } diff --git a/pkg/registry/service_registry.go b/pkg/registry/service_registry.go index 6ea48c3ea77..59faa1a8ff9 100644 --- a/pkg/registry/service_registry.go +++ b/pkg/registry/service_registry.go @@ -17,7 +17,6 @@ limitations under the License. package registry import ( - "encoding/json" "fmt" "strconv" "strings" @@ -64,7 +63,6 @@ func (sr *ServiceRegistryStorage) List(selector labels.Selector) (interface{}, e if err != nil { return nil, err } - list.Kind = "cluster#serviceList" var filtered []api.Service for _, service := range list.Items { if selector.Matches(labels.Set(service.Labels)) { @@ -80,7 +78,6 @@ func (sr *ServiceRegistryStorage) Get(id string) (interface{}, error) { if err != nil { return nil, err } - service.Kind = "cluster#service" return service, err } @@ -107,8 +104,7 @@ func (sr *ServiceRegistryStorage) Delete(id string) (<-chan interface{}, error) func (sr *ServiceRegistryStorage) Extract(body []byte) (interface{}, error) { var svc api.Service - err := json.Unmarshal([]byte(body), &svc) - svc.Kind = "cluster#service" + err := api.DecodeInto(body, &svc) return svc, err }