From fe614aeda2dec5107ab67c6a4c198c17a0b3d8b0 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Tue, 16 Sep 2014 15:56:26 -0400 Subject: [PATCH] Simple refactor for ease of readability runtime.DefaultCodec -> latest.Codec --- cmd/kubecfg/kubecfg.go | 6 ++--- examples/examples_test.go | 8 +++---- pkg/api/serialization_test.go | 14 ++++++------ pkg/apiserver/apiserver_test.go | 4 ++-- pkg/client/client.go | 4 ++-- pkg/client/client_test.go | 10 ++++----- pkg/client/request_test.go | 16 +++++++------- pkg/controller/replication_controller_test.go | 8 +++---- pkg/kubecfg/parse_test.go | 8 +++---- pkg/kubecfg/proxy_server.go | 2 +- pkg/kubecfg/resource_printer.go | 6 ++--- pkg/kubecfg/resource_printer_test.go | 2 +- pkg/kubelet/config/etcd.go | 2 +- pkg/proxy/config/etcd.go | 8 +++---- pkg/registry/binding/rest_test.go | 4 ++-- pkg/registry/controller/rest_test.go | 4 ++-- pkg/registry/etcd/etcd.go | 2 +- pkg/registry/etcd/etcd_test.go | 22 +++++++++---------- pkg/registry/pod/rest_test.go | 4 ++-- pkg/tools/etcd_tools_test.go | 2 +- test/integration/etcd_tools_test.go | 2 +- 21 files changed, 69 insertions(+), 69 deletions(-) diff --git a/cmd/kubecfg/kubecfg.go b/cmd/kubecfg/kubecfg.go index 2c58374e15f..0f9ea4fb5e7 100644 --- a/cmd/kubecfg/kubecfg.go +++ b/cmd/kubecfg/kubecfg.go @@ -129,7 +129,7 @@ func readConfig(storage string) []byte { glog.Fatal("Need config file (-c)") } - data, err := parser.ToWireFormat(readConfigData(), storage, runtime.DefaultCodec) + data, err := parser.ToWireFormat(readConfigData(), storage, latest.Codec) if err != nil { glog.Fatalf("Error parsing %v as an object for %v: %v\n", *config, storage, err) @@ -296,7 +296,7 @@ func executeAPIRequest(method string, c *client.Client) bool { if setBody { if version != 0 { data := readConfig(storage) - obj, err := runtime.DefaultCodec.Decode(data) + obj, err := latest.Codec.Decode(data) if err != nil { glog.Fatalf("error setting resource version: %v", err) } @@ -305,7 +305,7 @@ func executeAPIRequest(method string, c *client.Client) bool { glog.Fatalf("error setting resource version: %v", err) } jsonBase.SetResourceVersion(version) - data, err = runtime.DefaultCodec.Encode(obj) + data, err = latest.Codec.Encode(obj) if err != nil { glog.Fatalf("error setting resource version: %v", err) } diff --git a/examples/examples_test.go b/examples/examples_test.go index 3abb905cf3b..ca369e82d0f 100644 --- a/examples/examples_test.go +++ b/examples/examples_test.go @@ -103,7 +103,7 @@ func TestApiExamples(t *testing.T) { return } tested += 1 - if err := runtime.DefaultCodec.DecodeInto(data, expectedType); err != nil { + if err := latest.Codec.DecodeInto(data, expectedType); err != nil { t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) return } @@ -137,7 +137,7 @@ func TestExamples(t *testing.T) { return } tested += 1 - if err := runtime.DefaultCodec.DecodeInto(data, expectedType); err != nil { + if err := latest.Codec.DecodeInto(data, expectedType); err != nil { t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) return } @@ -168,14 +168,14 @@ func TestReadme(t *testing.T) { } for _, json := range match[1:] { expectedType := &api.Pod{} - if err := runtime.DefaultCodec.DecodeInto([]byte(json), expectedType); err != nil { + if err := latest.Codec.DecodeInto([]byte(json), expectedType); err != nil { t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) return } if errors := validateObject(expectedType); len(errors) > 0 { t.Errorf("%s did not validate correctly: %v", path, errors) } - encoded, err := runtime.DefaultCodec.Encode(expectedType) + encoded, err := latest.Codec.Encode(expectedType) if err != nil { t.Errorf("Could not encode object: %v", err) continue diff --git a/pkg/api/serialization_test.go b/pkg/api/serialization_test.go index d77d0c9d567..1ef750a30c9 100644 --- a/pkg/api/serialization_test.go +++ b/pkg/api/serialization_test.go @@ -135,13 +135,13 @@ func runTest(t *testing.T, source runtime.Object) { j.SetKind("") j.SetAPIVersion("") - data, err := runtime.DefaultCodec.Encode(source) + data, err := latest.Codec.Encode(source) if err != nil { t.Errorf("%v: %v (%#v)", name, err, source) return } - obj2, err := runtime.DefaultCodec.Decode(data) + obj2, err := latest.Codec.Decode(data) if err != nil { t.Errorf("%v: %v", name, err) return @@ -152,7 +152,7 @@ func runTest(t *testing.T, source runtime.Object) { } } obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface().(runtime.Object) - err = runtime.DefaultCodec.DecodeInto(data, obj3) + err = latest.Codec.DecodeInto(data, obj3) if err != nil { t.Errorf("2: %v: %v", name, err) return @@ -194,8 +194,8 @@ func TestEncode_Ptr(t *testing.T) { Labels: map[string]string{"name": "foo"}, } obj := runtime.Object(pod) - data, err := runtime.DefaultCodec.Encode(obj) - obj2, err2 := runtime.DefaultCodec.Decode(data) + data, err := latest.Codec.Encode(obj) + obj2, err2 := latest.Codec.Decode(data) if err != nil || err2 != nil { t.Fatalf("Failure: '%v' '%v'", err, err2) } @@ -209,11 +209,11 @@ func TestEncode_Ptr(t *testing.T) { func TestBadJSONRejection(t *testing.T) { badJSONMissingKind := []byte(`{ }`) - if _, err := runtime.DefaultCodec.Decode(badJSONMissingKind); err == nil { + if _, err := latest.Codec.Decode(badJSONMissingKind); err == nil { t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind) } badJSONUnknownType := []byte(`{"kind": "bar"}`) - if _, err1 := runtime.DefaultCodec.Decode(badJSONUnknownType); err1 == nil { + if _, err1 := latest.Codec.Decode(badJSONUnknownType); err1 == nil { t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType) } /*badJSONKindMismatch := []byte(`{"kind": "Pod"}`) diff --git a/pkg/apiserver/apiserver_test.go b/pkg/apiserver/apiserver_test.go index 59dceff11ec..5abab7c6aaf 100644 --- a/pkg/apiserver/apiserver_test.go +++ b/pkg/apiserver/apiserver_test.go @@ -43,7 +43,7 @@ func convert(obj runtime.Object) (runtime.Object, error) { return obj, nil } -var codec = runtime.DefaultCodec +var codec = latest.Codec func init() { runtime.DefaultScheme.AddKnownTypes("", &Simple{}, &SimpleList{}) @@ -676,7 +676,7 @@ func (*UnregisteredAPIObject) IsAnAPIObject() {} func TestWriteJSONDecodeError(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - writeJSON(http.StatusOK, runtime.DefaultCodec, &UnregisteredAPIObject{"Undecodable"}, w) + writeJSON(http.StatusOK, latest.Codec, &UnregisteredAPIObject{"Undecodable"}, w) })) status := expectApiStatus(t, "GET", server.URL, nil, http.StatusInternalServerError) if status.Reason != api.StatusReasonUnknown { diff --git a/pkg/client/client.go b/pkg/client/client.go index 470983e1a8c..0ee69a54c43 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -99,7 +99,7 @@ type Client struct { // to a URL will prepend the server path. Returns an error if host cannot be converted to a // valid URL. func New(host string, auth *AuthInfo) (*Client, error) { - restClient, err := NewRESTClient(host, auth, "/api/v1beta1/", runtime.DefaultCodec) + restClient, err := NewRESTClient(host, auth, "/api/v1beta1/", latest.Codec) if err != nil { return nil, err } @@ -224,7 +224,7 @@ func (c *RESTClient) doRequest(request *http.Request) ([]byte, error) { // Did the server give us a status response? isStatusResponse := false var status api.Status - if err := runtime.DefaultCodec.DecodeInto(body, &status); err == nil && status.Status != "" { + if err := latest.Codec.DecodeInto(body, &status); err == nil && status.Status != "" { isStatusResponse = true } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 02da5a1dd54..ebc89b70e1b 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -48,7 +48,7 @@ func TestValidatesHostParameter(t *testing.T) { "host/server": {"", "", true}, } for k, expected := range testCases { - c, err := NewRESTClient(k, nil, "/api/v1beta1/", runtime.DefaultCodec) + c, err := NewRESTClient(k, nil, "/api/v1beta1/", latest.Codec) switch { case err == nil && expected.Err: t.Errorf("expected error but was nil") @@ -309,7 +309,7 @@ func TestCreateController(t *testing.T) { func body(obj runtime.Object, raw *string) *string { if obj != nil { - bs, _ := runtime.DefaultCodec.Encode(obj) + bs, _ := latest.Codec.Encode(obj) body := string(bs) return &body } @@ -533,7 +533,7 @@ func TestDoRequest(t *testing.T) { func TestDoRequestAccepted(t *testing.T) { status := &api.Status{Status: api.StatusWorking} - expectedBody, _ := runtime.DefaultCodec.Encode(status) + expectedBody, _ := latest.Codec.Encode(status) fakeHandler := util.FakeHandler{ StatusCode: 202, ResponseBody: string(expectedBody), @@ -570,7 +570,7 @@ func TestDoRequestAccepted(t *testing.T) { func TestDoRequestAcceptedSuccess(t *testing.T) { status := &api.Status{Status: api.StatusSuccess} - expectedBody, _ := runtime.DefaultCodec.Encode(status) + expectedBody, _ := latest.Codec.Encode(status) fakeHandler := util.FakeHandler{ StatusCode: 202, ResponseBody: string(expectedBody), @@ -590,7 +590,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) { if err != nil { t.Errorf("Unexpected error %#v", err) } - statusOut, err := runtime.DefaultCodec.Decode(body) + statusOut, err := latest.Codec.Decode(body) if err != nil { t.Errorf("Unexpected error %#v", err) } diff --git a/pkg/client/request_test.go b/pkg/client/request_test.go index a7dab29af13..a0ba4c07b8b 100644 --- a/pkg/client/request_test.go +++ b/pkg/client/request_test.go @@ -38,7 +38,7 @@ import ( func TestDoRequestNewWay(t *testing.T) { reqBody := "request body" expectedObj := &api.Service{Port: 12345} - expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj) + expectedBody, _ := latest.Codec.Encode(expectedObj) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(expectedBody), @@ -71,9 +71,9 @@ func TestDoRequestNewWay(t *testing.T) { func TestDoRequestNewWayReader(t *testing.T) { reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - reqBodyExpected, _ := runtime.DefaultCodec.Encode(reqObj) + reqBodyExpected, _ := latest.Codec.Encode(reqObj) expectedObj := &api.Service{Port: 12345} - expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj) + expectedBody, _ := latest.Codec.Encode(expectedObj) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(expectedBody), @@ -108,9 +108,9 @@ func TestDoRequestNewWayReader(t *testing.T) { func TestDoRequestNewWayObj(t *testing.T) { reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - reqBodyExpected, _ := runtime.DefaultCodec.Encode(reqObj) + reqBodyExpected, _ := latest.Codec.Encode(reqObj) expectedObj := &api.Service{Port: 12345} - expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj) + expectedBody, _ := latest.Codec.Encode(expectedObj) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(expectedBody), @@ -144,7 +144,7 @@ func TestDoRequestNewWayObj(t *testing.T) { func TestDoRequestNewWayFile(t *testing.T) { reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - reqBodyExpected, err := runtime.DefaultCodec.Encode(reqObj) + reqBodyExpected, err := latest.Codec.Encode(reqObj) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -160,7 +160,7 @@ func TestDoRequestNewWayFile(t *testing.T) { } expectedObj := &api.Service{Port: 12345} - expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj) + expectedBody, _ := latest.Codec.Encode(expectedObj) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(expectedBody), @@ -295,7 +295,7 @@ func TestPolling(t *testing.T) { callNumber := 0 testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - data, err := runtime.DefaultCodec.Encode(objects[callNumber]) + data, err := latest.Codec.Encode(objects[callNumber]) if err != nil { t.Errorf("Unexpected encode error") } diff --git a/pkg/controller/replication_controller_test.go b/pkg/controller/replication_controller_test.go index fd319b149d0..d34203ce48c 100644 --- a/pkg/controller/replication_controller_test.go +++ b/pkg/controller/replication_controller_test.go @@ -109,7 +109,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec } func TestSyncReplicationControllerDoesNothing(t *testing.T) { - body, _ := runtime.DefaultCodec.Encode(newPodList(2)) + body, _ := latest.Codec.Encode(newPodList(2)) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(body), @@ -129,7 +129,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) { } func TestSyncReplicationControllerDeletes(t *testing.T) { - body, _ := runtime.DefaultCodec.Encode(newPodList(2)) + body, _ := latest.Codec.Encode(newPodList(2)) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(body), @@ -149,7 +149,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) { } func TestSyncReplicationControllerCreates(t *testing.T) { - body, _ := runtime.DefaultCodec.Encode(newPodList(0)) + body, _ := latest.Codec.Encode(newPodList(0)) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(body), @@ -169,7 +169,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) { } func TestCreateReplica(t *testing.T) { - body, _ := runtime.DefaultCodec.Encode(&api.Pod{}) + body, _ := latest.Codec.Encode(&api.Pod{}) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(body), diff --git a/pkg/kubecfg/parse_test.go b/pkg/kubecfg/parse_test.go index 5681bfd7610..bd037eb7289 100644 --- a/pkg/kubecfg/parse_test.go +++ b/pkg/kubecfg/parse_test.go @@ -27,21 +27,21 @@ import ( func TestParseBadStorage(t *testing.T) { p := NewParser(map[string]runtime.Object{}) - _, err := p.ToWireFormat([]byte("{}"), "badstorage", runtime.DefaultCodec) + _, err := p.ToWireFormat([]byte("{}"), "badstorage", latest.Codec) if err == nil { t.Errorf("Expected error, received none") } } func DoParseTest(t *testing.T, storage string, obj runtime.Object, p *Parser) { - jsonData, _ := runtime.DefaultCodec.Encode(obj) + jsonData, _ := latest.Codec.Encode(obj) var tmp map[string]interface{} json.Unmarshal(jsonData, &tmp) yamlData, _ := yaml.Marshal(tmp) t.Logf("Intermediate yaml:\n%v\n", string(yamlData)) t.Logf("Intermediate json:\n%v\n", string(jsonData)) - jsonGot, jsonErr := p.ToWireFormat(jsonData, storage, runtime.DefaultCodec) - yamlGot, yamlErr := p.ToWireFormat(yamlData, storage, runtime.DefaultCodec) + jsonGot, jsonErr := p.ToWireFormat(jsonData, storage, latest.Codec) + yamlGot, yamlErr := p.ToWireFormat(yamlData, storage, latest.Codec) if jsonErr != nil { t.Errorf("json err: %#v", jsonErr) diff --git a/pkg/kubecfg/proxy_server.go b/pkg/kubecfg/proxy_server.go index 002ba6530ee..6059ec03547 100644 --- a/pkg/kubecfg/proxy_server.go +++ b/pkg/kubecfg/proxy_server.go @@ -53,7 +53,7 @@ func (s *ProxyServer) Serve() error { func (s *ProxyServer) doError(w http.ResponseWriter, err error) { w.WriteHeader(http.StatusInternalServerError) w.Header().Add("Content-type", "application/json") - data, _ := runtime.DefaultCodec.Encode(&api.Status{ + data, _ := latest.Codec.Encode(&api.Status{ Status: api.StatusFailure, Message: fmt.Sprintf("internal error: %#v", err), }) diff --git a/pkg/kubecfg/resource_printer.go b/pkg/kubecfg/resource_printer.go index b3c5a54d348..474d6fec97f 100644 --- a/pkg/kubecfg/resource_printer.go +++ b/pkg/kubecfg/resource_printer.go @@ -50,7 +50,7 @@ func (i *IdentityPrinter) Print(data []byte, w io.Writer) error { // PrintObj is an implementation of ResourcePrinter.PrintObj which simply writes the object to the Writer. func (i *IdentityPrinter) PrintObj(obj runtime.Object, output io.Writer) error { - data, err := runtime.DefaultCodec.Encode(obj) + data, err := latest.Codec.Encode(obj) if err != nil { return err } @@ -260,7 +260,7 @@ func (h *HumanReadablePrinter) Print(data []byte, output io.Writer) error { return fmt.Errorf("unexpected object with no 'kind' field: %s", data) } - obj, err := runtime.DefaultCodec.Decode(data) + obj, err := latest.Codec.Decode(data) if err != nil { return err } @@ -292,7 +292,7 @@ type TemplatePrinter struct { // Print parses the data as JSON, and re-formats it with the Go Template. func (t *TemplatePrinter) Print(data []byte, w io.Writer) error { - obj, err := runtime.DefaultCodec.Decode(data) + obj, err := latest.Codec.Decode(data) if err != nil { return err } diff --git a/pkg/kubecfg/resource_printer_test.go b/pkg/kubecfg/resource_printer_test.go index 6e72168cc64..e9c738cccc8 100644 --- a/pkg/kubecfg/resource_printer_test.go +++ b/pkg/kubecfg/resource_printer_test.go @@ -96,7 +96,7 @@ func TestIdentityPrinter(t *testing.T) { } buff.Reset() printer.PrintObj(obj, buff) - objOut, err := runtime.DefaultCodec.Decode([]byte(buff.String())) + objOut, err := latest.Codec.Decode([]byte(buff.String())) if err != nil { t.Errorf("Unexpeted error: %#v", err) } diff --git a/pkg/kubelet/config/etcd.go b/pkg/kubelet/config/etcd.go index e0d0c785d73..77bcf290cc1 100644 --- a/pkg/kubelet/config/etcd.go +++ b/pkg/kubelet/config/etcd.go @@ -47,7 +47,7 @@ type SourceEtcd struct { func NewSourceEtcd(key string, client tools.EtcdClient, updates chan<- interface{}) *SourceEtcd { helper := tools.EtcdHelper{ client, - runtime.DefaultCodec, + latest.Codec, runtime.DefaultResourceVersioner, } source := &SourceEtcd{ diff --git a/pkg/proxy/config/etcd.go b/pkg/proxy/config/etcd.go index a3a9a6a5f4e..2de91d41a50 100644 --- a/pkg/proxy/config/etcd.go +++ b/pkg/proxy/config/etcd.go @@ -135,7 +135,7 @@ func (s ConfigSourceEtcd) GetServices() ([]api.Service, []api.Endpoints, error) // and create a Service entry for it. for i, node := range response.Node.Nodes { var svc api.Service - err = runtime.DefaultCodec.DecodeInto([]byte(node.Value), &svc) + err = latest.Codec.DecodeInto([]byte(node.Value), &svc) if err != nil { glog.Errorf("Failed to load Service: %s (%#v)", node.Value, err) continue @@ -168,7 +168,7 @@ func (s ConfigSourceEtcd) GetEndpoints(service string) (api.Endpoints, error) { } // Parse all the endpoint specifications in this value. var e api.Endpoints - err = runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &e) + err = latest.Codec.DecodeInto([]byte(response.Node.Value), &e) return e, err } @@ -178,7 +178,7 @@ func etcdResponseToService(response *etcd.Response) (*api.Service, error) { return nil, fmt.Errorf("invalid response from etcd: %#v", response) } var svc api.Service - err := runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &svc) + err := latest.Codec.DecodeInto([]byte(response.Node.Value), &svc) if err != nil { return nil, err } @@ -232,7 +232,7 @@ func (s ConfigSourceEtcd) ProcessChange(response *etcd.Response) { func (s ConfigSourceEtcd) ProcessEndpointResponse(response *etcd.Response) { glog.Infof("Processing a change in endpoint configuration... %s", *response) var endpoints api.Endpoints - err := runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &endpoints) + err := latest.Codec.DecodeInto([]byte(response.Node.Value), &endpoints) if err != nil { glog.Errorf("Failed to parse service out of etcd key: %v : %+v", response.Node.Value, err) return diff --git a/pkg/registry/binding/rest_test.go b/pkg/registry/binding/rest_test.go index 5c8cb688111..ac254f545bb 100644 --- a/pkg/registry/binding/rest_test.go +++ b/pkg/registry/binding/rest_test.go @@ -38,12 +38,12 @@ func TestNewREST(t *testing.T) { PodID: "foo", Host: "bar", } - body, err := runtime.DefaultCodec.Encode(binding) + body, err := latest.Codec.Encode(binding) if err != nil { t.Fatalf("Unexpected encode error %v", err) } obj := b.New() - err = runtime.DefaultCodec.DecodeInto(body, obj) + err = latest.Codec.DecodeInto(body, obj) if err != nil { t.Fatalf("Unexpected error %v", err) } diff --git a/pkg/registry/controller/rest_test.go b/pkg/registry/controller/rest_test.go index d2f66810aa6..eaaeabef1a8 100644 --- a/pkg/registry/controller/rest_test.go +++ b/pkg/registry/controller/rest_test.go @@ -113,13 +113,13 @@ func TestControllerDecode(t *testing.T) { ID: "foo", }, } - body, err := runtime.DefaultCodec.Encode(controller) + body, err := latest.Codec.Encode(controller) if err != nil { t.Errorf("unexpected error: %v", err) } controllerOut := storage.New() - if err := runtime.DefaultCodec.DecodeInto(body, controllerOut); err != nil { + if err := latest.Codec.DecodeInto(body, controllerOut); err != nil { t.Errorf("unexpected error: %v", err) } diff --git a/pkg/registry/etcd/etcd.go b/pkg/registry/etcd/etcd.go index 33a279d7272..b3c57a5ca96 100644 --- a/pkg/registry/etcd/etcd.go +++ b/pkg/registry/etcd/etcd.go @@ -45,7 +45,7 @@ func NewRegistry(client tools.EtcdClient) *Registry { registry := &Registry{ EtcdHelper: tools.EtcdHelper{ client, - runtime.DefaultCodec, + latest.Codec, runtime.DefaultResourceVersioner, }, } diff --git a/pkg/registry/etcd/etcd_test.go b/pkg/registry/etcd/etcd_test.go index d55c0582d38..bf8c9bd7074 100644 --- a/pkg/registry/etcd/etcd_test.go +++ b/pkg/registry/etcd/etcd_test.go @@ -108,7 +108,7 @@ func TestEtcdCreatePod(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var pod api.Pod - err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &pod) + err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &pod) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -122,7 +122,7 @@ func TestEtcdCreatePod(t *testing.T) { t.Errorf("unexpected error: %v", err) } - err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &manifests) + err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &manifests) if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" { t.Errorf("Unexpected manifest list: %#v", manifests) } @@ -235,7 +235,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var pod api.Pod - err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &pod) + err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &pod) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -249,7 +249,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { t.Errorf("unexpected error: %v", err) } - err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &manifests) + err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &manifests) if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" { t.Errorf("Unexpected manifest list: %#v", manifests) } @@ -300,7 +300,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var pod api.Pod - err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &pod) + err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &pod) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -314,7 +314,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { t.Errorf("unexpected error: %v", err) } - err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &manifests) + err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &manifests) if len(manifests.Items) != 2 || manifests.Items[1].ID != "foo" { t.Errorf("Unexpected manifest list: %#v", manifests) } @@ -350,7 +350,7 @@ func TestEtcdDeletePod(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var manifests api.ContainerManifestList - runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &manifests) + latest.Codec.DecodeInto([]byte(response.Node.Value), &manifests) if len(manifests.Items) != 0 { t.Errorf("Unexpected container set: %s, expected empty", response.Node.Value) } @@ -388,7 +388,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var manifests api.ContainerManifestList - runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &manifests) + latest.Codec.DecodeInto([]byte(response.Node.Value), &manifests) if len(manifests.Items) != 1 { t.Fatalf("Unexpected manifest set: %#v, expected empty", manifests) } @@ -607,7 +607,7 @@ func TestEtcdCreateController(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var ctrl api.ReplicationController - err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &ctrl) + err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &ctrl) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -699,7 +699,7 @@ func TestEtcdCreateService(t *testing.T) { } var service api.Service - err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &service) + err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &service) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -874,7 +874,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var endpointsOut api.Endpoints - err = runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &endpointsOut) + err = latest.Codec.DecodeInto([]byte(response.Node.Value), &endpointsOut) if !reflect.DeepEqual(endpoints, endpointsOut) { t.Errorf("Unexpected endpoints: %#v, expected %#v", endpointsOut, endpoints) } diff --git a/pkg/registry/pod/rest_test.go b/pkg/registry/pod/rest_test.go index db79805eaca..8078dd3e756 100644 --- a/pkg/registry/pod/rest_test.go +++ b/pkg/registry/pod/rest_test.go @@ -201,13 +201,13 @@ func TestPodDecode(t *testing.T) { ID: "foo", }, } - body, err := runtime.DefaultCodec.Encode(expected) + body, err := latest.Codec.Encode(expected) if err != nil { t.Errorf("unexpected error: %v", err) } actual := storage.New() - if err := runtime.DefaultCodec.DecodeInto(body, actual); err != nil { + if err := latest.Codec.DecodeInto(body, actual); err != nil { t.Errorf("unexpected error: %v", err) } diff --git a/pkg/tools/etcd_tools_test.go b/pkg/tools/etcd_tools_test.go index f7c497f641a..729b3cdb8aa 100644 --- a/pkg/tools/etcd_tools_test.go +++ b/pkg/tools/etcd_tools_test.go @@ -42,7 +42,7 @@ type TestResource struct { func (*TestResource) IsAnAPIObject() {} var scheme *runtime.Scheme -var codec = runtime.DefaultCodec +var codec = latest.Codec var versioner = runtime.DefaultResourceVersioner func init() { diff --git a/test/integration/etcd_tools_test.go b/test/integration/etcd_tools_test.go index c12df1b24ca..2b313cbdfd6 100644 --- a/test/integration/etcd_tools_test.go +++ b/test/integration/etcd_tools_test.go @@ -90,7 +90,7 @@ func TestExtractObj(t *testing.T) { func TestWatch(t *testing.T) { client := newEtcdClient() - helper := tools.EtcdHelper{Client: client, Codec: runtime.DefaultCodec, ResourceVersioner: runtime.DefaultResourceVersioner} + helper := tools.EtcdHelper{Client: client, Codec: latest.Codec, ResourceVersioner: runtime.DefaultResourceVersioner} withEtcdKey(func(key string) { resp, err := client.Set(key, runtime.DefaultScheme.EncodeOrDie(&api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0) if err != nil {