Commit 1c2b6578 authored by Daniel Smith's avatar Daniel Smith

Rename Codec and ResourceVersioner to add Default in front, to allow for types of those names

parent 828b70ab
...@@ -266,7 +266,7 @@ func executeAPIRequest(method string, c *client.Client) bool { ...@@ -266,7 +266,7 @@ func executeAPIRequest(method string, c *client.Client) bool {
if setBody { if setBody {
if version != 0 { if version != 0 {
data := readConfig(storage) data := readConfig(storage)
obj, err := runtime.Decode(data) obj, err := runtime.DefaultCodec.Decode(data)
if err != nil { if err != nil {
glog.Fatalf("error setting resource version: %v", err) glog.Fatalf("error setting resource version: %v", err)
} }
...@@ -275,7 +275,7 @@ func executeAPIRequest(method string, c *client.Client) bool { ...@@ -275,7 +275,7 @@ func executeAPIRequest(method string, c *client.Client) bool {
glog.Fatalf("error setting resource version: %v", err) glog.Fatalf("error setting resource version: %v", err)
} }
jsonBase.SetResourceVersion(version) jsonBase.SetResourceVersion(version)
data, err = runtime.Encode(obj) data, err = runtime.DefaultCodec.Encode(obj)
if err != nil { if err != nil {
glog.Fatalf("error setting resource version: %v", err) glog.Fatalf("error setting resource version: %v", err)
} }
......
...@@ -103,7 +103,7 @@ func TestApiExamples(t *testing.T) { ...@@ -103,7 +103,7 @@ func TestApiExamples(t *testing.T) {
return return
} }
tested += 1 tested += 1
if err := runtime.DecodeInto(data, expectedType); err != nil { if err := runtime.DefaultCodec.DecodeInto(data, expectedType); err != nil {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return return
} }
...@@ -137,7 +137,7 @@ func TestExamples(t *testing.T) { ...@@ -137,7 +137,7 @@ func TestExamples(t *testing.T) {
return return
} }
tested += 1 tested += 1
if err := runtime.DecodeInto(data, expectedType); err != nil { if err := runtime.DefaultCodec.DecodeInto(data, expectedType); err != nil {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return return
} }
...@@ -168,14 +168,14 @@ func TestReadme(t *testing.T) { ...@@ -168,14 +168,14 @@ func TestReadme(t *testing.T) {
} }
for _, json := range match[1:] { for _, json := range match[1:] {
expectedType := &api.Pod{} expectedType := &api.Pod{}
if err := runtime.DecodeInto([]byte(json), expectedType); err != nil { if err := runtime.DefaultCodec.DecodeInto([]byte(json), expectedType); err != nil {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return return
} }
if errors := validateObject(expectedType); len(errors) > 0 { if errors := validateObject(expectedType); len(errors) > 0 {
t.Errorf("%s did not validate correctly: %v", path, errors) t.Errorf("%s did not validate correctly: %v", path, errors)
} }
encoded, err := runtime.Encode(expectedType) encoded, err := runtime.DefaultCodec.Encode(expectedType)
if err != nil { if err != nil {
t.Errorf("Could not encode object: %v", err) t.Errorf("Could not encode object: %v", err)
continue continue
......
...@@ -115,13 +115,13 @@ func runTest(t *testing.T, source runtime.Object) { ...@@ -115,13 +115,13 @@ func runTest(t *testing.T, source runtime.Object) {
j.SetKind("") j.SetKind("")
j.SetAPIVersion("") j.SetAPIVersion("")
data, err := runtime.Codec.Encode(source) data, err := runtime.DefaultCodec.Encode(source)
if err != nil { if err != nil {
t.Errorf("%v: %v (%#v)", name, err, source) t.Errorf("%v: %v (%#v)", name, err, source)
return return
} }
obj2, err := runtime.Codec.Decode(data) obj2, err := runtime.DefaultCodec.Decode(data)
if err != nil { if err != nil {
t.Errorf("%v: %v", name, err) t.Errorf("%v: %v", name, err)
return return
...@@ -132,7 +132,7 @@ func runTest(t *testing.T, source runtime.Object) { ...@@ -132,7 +132,7 @@ func runTest(t *testing.T, source runtime.Object) {
} }
} }
obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface().(runtime.Object) obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface().(runtime.Object)
err = runtime.Codec.DecodeInto(data, obj3) err = runtime.DefaultCodec.DecodeInto(data, obj3)
if err != nil { if err != nil {
t.Errorf("2: %v: %v", name, err) t.Errorf("2: %v: %v", name, err)
return return
...@@ -174,8 +174,8 @@ func TestEncode_Ptr(t *testing.T) { ...@@ -174,8 +174,8 @@ func TestEncode_Ptr(t *testing.T) {
Labels: map[string]string{"name": "foo"}, Labels: map[string]string{"name": "foo"},
} }
obj := runtime.Object(pod) obj := runtime.Object(pod)
data, err := runtime.Codec.Encode(obj) data, err := runtime.DefaultCodec.Encode(obj)
obj2, err2 := runtime.Codec.Decode(data) obj2, err2 := runtime.DefaultCodec.Decode(data)
if err != nil || err2 != nil { if err != nil || err2 != nil {
t.Fatalf("Failure: '%v' '%v'", err, err2) t.Fatalf("Failure: '%v' '%v'", err, err2)
} }
...@@ -189,11 +189,11 @@ func TestEncode_Ptr(t *testing.T) { ...@@ -189,11 +189,11 @@ func TestEncode_Ptr(t *testing.T) {
func TestBadJSONRejection(t *testing.T) { func TestBadJSONRejection(t *testing.T) {
badJSONMissingKind := []byte(`{ }`) badJSONMissingKind := []byte(`{ }`)
if _, err := runtime.Codec.Decode(badJSONMissingKind); err == nil { if _, err := runtime.DefaultCodec.Decode(badJSONMissingKind); err == nil {
t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind) t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind)
} }
badJSONUnknownType := []byte(`{"kind": "bar"}`) badJSONUnknownType := []byte(`{"kind": "bar"}`)
if _, err1 := runtime.Codec.Decode(badJSONUnknownType); err1 == nil { if _, err1 := runtime.DefaultCodec.Decode(badJSONUnknownType); err1 == nil {
t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType) t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType)
} }
/*badJSONKindMismatch := []byte(`{"kind": "Pod"}`) /*badJSONKindMismatch := []byte(`{"kind": "Pod"}`)
......
...@@ -42,7 +42,7 @@ func convert(obj interface{}) (interface{}, error) { ...@@ -42,7 +42,7 @@ func convert(obj interface{}) (interface{}, error) {
return obj, nil return obj, nil
} }
var codec = runtime.Codec var codec = runtime.DefaultCodec
func init() { func init() {
runtime.AddKnownTypes("", Simple{}, SimpleList{}) runtime.AddKnownTypes("", Simple{}, SimpleList{})
...@@ -667,7 +667,7 @@ func TestWriteJSONDecodeError(t *testing.T) { ...@@ -667,7 +667,7 @@ func TestWriteJSONDecodeError(t *testing.T) {
type T struct { type T struct {
Value string Value string
} }
writeJSON(http.StatusOK, runtime.Codec, &T{"Undecodable"}, w) writeJSON(http.StatusOK, runtime.DefaultCodec, &T{"Undecodable"}, w)
})) }))
status := expectApiStatus(t, "GET", server.URL, nil, http.StatusInternalServerError) status := expectApiStatus(t, "GET", server.URL, nil, http.StatusInternalServerError)
if status.Reason != api.StatusReasonUnknown { if status.Reason != api.StatusReasonUnknown {
......
...@@ -222,7 +222,7 @@ func (c *RESTClient) doRequest(request *http.Request) ([]byte, error) { ...@@ -222,7 +222,7 @@ func (c *RESTClient) doRequest(request *http.Request) ([]byte, error) {
// Did the server give us a status response? // Did the server give us a status response?
isStatusResponse := false isStatusResponse := false
var status api.Status var status api.Status
if err := runtime.DecodeInto(body, &status); err == nil && status.Status != "" { if err := runtime.DefaultCodec.DecodeInto(body, &status); err == nil && status.Status != "" {
isStatusResponse = true isStatusResponse = true
} }
......
...@@ -309,7 +309,7 @@ func TestCreateController(t *testing.T) { ...@@ -309,7 +309,7 @@ func TestCreateController(t *testing.T) {
func body(obj interface{}, raw *string) *string { func body(obj interface{}, raw *string) *string {
if obj != nil { if obj != nil {
bs, _ := runtime.Encode(obj) bs, _ := runtime.DefaultCodec.Encode(obj)
body := string(bs) body := string(bs)
return &body return &body
} }
...@@ -522,7 +522,7 @@ func TestDoRequest(t *testing.T) { ...@@ -522,7 +522,7 @@ func TestDoRequest(t *testing.T) {
func TestDoRequestAccepted(t *testing.T) { func TestDoRequestAccepted(t *testing.T) {
status := api.Status{Status: api.StatusWorking} status := api.Status{Status: api.StatusWorking}
expectedBody, _ := runtime.Encode(status) expectedBody, _ := runtime.DefaultCodec.Encode(status)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 202, StatusCode: 202,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
...@@ -559,7 +559,7 @@ func TestDoRequestAccepted(t *testing.T) { ...@@ -559,7 +559,7 @@ func TestDoRequestAccepted(t *testing.T) {
func TestDoRequestAcceptedSuccess(t *testing.T) { func TestDoRequestAcceptedSuccess(t *testing.T) {
status := api.Status{Status: api.StatusSuccess} status := api.Status{Status: api.StatusSuccess}
expectedBody, _ := runtime.Encode(status) expectedBody, _ := runtime.DefaultCodec.Encode(status)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 202, StatusCode: 202,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
...@@ -579,7 +579,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) { ...@@ -579,7 +579,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
statusOut, err := runtime.Decode(body) statusOut, err := runtime.DefaultCodec.Decode(body)
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
......
...@@ -44,7 +44,7 @@ type Fake struct { ...@@ -44,7 +44,7 @@ type Fake struct {
func (c *Fake) ListPods(selector labels.Selector) (api.PodList, error) { func (c *Fake) ListPods(selector labels.Selector) (api.PodList, error) {
c.Actions = append(c.Actions, FakeAction{Action: "list-pods"}) c.Actions = append(c.Actions, FakeAction{Action: "list-pods"})
return *runtime.CopyOrDie(c.Pods).(*api.PodList), nil return *runtime.DefaultScheme.CopyOrDie(&c.Pods).(*api.PodList), nil
} }
func (c *Fake) GetPod(name string) (api.Pod, error) { func (c *Fake) GetPod(name string) (api.Pod, error) {
...@@ -74,7 +74,7 @@ func (c *Fake) ListReplicationControllers(selector labels.Selector) (api.Replica ...@@ -74,7 +74,7 @@ func (c *Fake) ListReplicationControllers(selector labels.Selector) (api.Replica
func (c *Fake) GetReplicationController(name string) (api.ReplicationController, error) { func (c *Fake) GetReplicationController(name string) (api.ReplicationController, error) {
c.Actions = append(c.Actions, FakeAction{Action: "get-controller", Value: name}) c.Actions = append(c.Actions, FakeAction{Action: "get-controller", Value: name})
return *runtime.CopyOrDie(c.Ctrl).(*api.ReplicationController), nil return *runtime.DefaultScheme.CopyOrDie(&c.Ctrl).(*api.ReplicationController), nil
} }
func (c *Fake) CreateReplicationController(controller api.ReplicationController) (api.ReplicationController, error) { func (c *Fake) CreateReplicationController(controller api.ReplicationController) (api.ReplicationController, error) {
......
...@@ -205,7 +205,7 @@ func (r *Request) Body(obj interface{}) *Request { ...@@ -205,7 +205,7 @@ func (r *Request) Body(obj interface{}) *Request {
case io.Reader: case io.Reader:
r.body = t r.body = t
default: default:
data, err := runtime.Encode(obj) data, err := runtime.DefaultCodec.Encode(obj)
if err != nil { if err != nil {
r.err = err r.err = err
return r return r
...@@ -318,7 +318,7 @@ func (r Result) Get() (interface{}, error) { ...@@ -318,7 +318,7 @@ func (r Result) Get() (interface{}, error) {
if r.err != nil { if r.err != nil {
return nil, r.err return nil, r.err
} }
return runtime.Decode(r.body) return runtime.DefaultCodec.Decode(r.body)
} }
// Into stores the result into obj, if possible. // Into stores the result into obj, if possible.
...@@ -326,7 +326,7 @@ func (r Result) Into(obj interface{}) error { ...@@ -326,7 +326,7 @@ func (r Result) Into(obj interface{}) error {
if r.err != nil { if r.err != nil {
return r.err return r.err
} }
return runtime.DecodeInto(r.body, obj) return runtime.DefaultCodec.DecodeInto(r.body, obj)
} }
// Error returns the error executing the request, nil if no error occurred. // Error returns the error executing the request, nil if no error occurred.
......
...@@ -38,7 +38,7 @@ import ( ...@@ -38,7 +38,7 @@ import (
func TestDoRequestNewWay(t *testing.T) { func TestDoRequestNewWay(t *testing.T) {
reqBody := "request body" reqBody := "request body"
expectedObj := &api.Service{Port: 12345} expectedObj := &api.Service{Port: 12345}
expectedBody, _ := runtime.Encode(expectedObj) expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
...@@ -71,9 +71,9 @@ func TestDoRequestNewWay(t *testing.T) { ...@@ -71,9 +71,9 @@ func TestDoRequestNewWay(t *testing.T) {
func TestDoRequestNewWayReader(t *testing.T) { func TestDoRequestNewWayReader(t *testing.T) {
reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
reqBodyExpected, _ := runtime.Encode(reqObj) reqBodyExpected, _ := runtime.DefaultCodec.Encode(reqObj)
expectedObj := &api.Service{Port: 12345} expectedObj := &api.Service{Port: 12345}
expectedBody, _ := runtime.Encode(expectedObj) expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
...@@ -108,9 +108,9 @@ func TestDoRequestNewWayReader(t *testing.T) { ...@@ -108,9 +108,9 @@ func TestDoRequestNewWayReader(t *testing.T) {
func TestDoRequestNewWayObj(t *testing.T) { func TestDoRequestNewWayObj(t *testing.T) {
reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
reqBodyExpected, _ := runtime.Encode(reqObj) reqBodyExpected, _ := runtime.DefaultCodec.Encode(reqObj)
expectedObj := &api.Service{Port: 12345} expectedObj := &api.Service{Port: 12345}
expectedBody, _ := runtime.Encode(expectedObj) expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
...@@ -144,7 +144,7 @@ func TestDoRequestNewWayObj(t *testing.T) { ...@@ -144,7 +144,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
func TestDoRequestNewWayFile(t *testing.T) { func TestDoRequestNewWayFile(t *testing.T) {
reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
reqBodyExpected, err := runtime.Encode(reqObj) reqBodyExpected, err := runtime.DefaultCodec.Encode(reqObj)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -160,7 +160,7 @@ func TestDoRequestNewWayFile(t *testing.T) { ...@@ -160,7 +160,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
} }
expectedObj := &api.Service{Port: 12345} expectedObj := &api.Service{Port: 12345}
expectedBody, _ := runtime.Encode(expectedObj) expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
...@@ -295,7 +295,7 @@ func TestPolling(t *testing.T) { ...@@ -295,7 +295,7 @@ func TestPolling(t *testing.T) {
callNumber := 0 callNumber := 0
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
data, err := runtime.Encode(objects[callNumber]) data, err := runtime.DefaultCodec.Encode(objects[callNumber])
if err != nil { if err != nil {
t.Errorf("Unexpected encode error") t.Errorf("Unexpected encode error")
} }
......
...@@ -109,7 +109,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec ...@@ -109,7 +109,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
} }
func TestSyncReplicationControllerDoesNothing(t *testing.T) { func TestSyncReplicationControllerDoesNothing(t *testing.T) {
body, _ := runtime.Encode(newPodList(2)) body, _ := runtime.DefaultCodec.Encode(newPodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -129,7 +129,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) { ...@@ -129,7 +129,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {
} }
func TestSyncReplicationControllerDeletes(t *testing.T) { func TestSyncReplicationControllerDeletes(t *testing.T) {
body, _ := runtime.Encode(newPodList(2)) body, _ := runtime.DefaultCodec.Encode(newPodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -149,7 +149,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) { ...@@ -149,7 +149,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
} }
func TestSyncReplicationControllerCreates(t *testing.T) { func TestSyncReplicationControllerCreates(t *testing.T) {
body, _ := runtime.Encode(newPodList(0)) body, _ := runtime.DefaultCodec.Encode(newPodList(0))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
...@@ -169,7 +169,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) { ...@@ -169,7 +169,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
} }
func TestCreateReplica(t *testing.T) { func TestCreateReplica(t *testing.T) {
body, _ := runtime.Encode(api.Pod{}) body, _ := runtime.DefaultCodec.Encode(api.Pod{})
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
......
...@@ -44,11 +44,11 @@ func (p *Parser) ToWireFormat(data []byte, storage string) ([]byte, error) { ...@@ -44,11 +44,11 @@ func (p *Parser) ToWireFormat(data []byte, storage string) ([]byte, error) {
} }
obj := reflect.New(prototypeType).Interface() obj := reflect.New(prototypeType).Interface()
err := runtime.DecodeInto(data, obj) err := runtime.DefaultCodec.DecodeInto(data, obj)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return runtime.Encode(obj) return runtime.DefaultCodec.Encode(obj)
} }
func (p *Parser) SupportedWireStorage() []string { func (p *Parser) SupportedWireStorage() []string {
......
...@@ -33,7 +33,7 @@ func TestParseBadStorage(t *testing.T) { ...@@ -33,7 +33,7 @@ func TestParseBadStorage(t *testing.T) {
} }
func DoParseTest(t *testing.T, storage string, obj interface{}, p *Parser) { func DoParseTest(t *testing.T, storage string, obj interface{}, p *Parser) {
jsonData, _ := runtime.Encode(obj) jsonData, _ := runtime.DefaultCodec.Encode(obj)
yamlData, _ := yaml.Marshal(obj) yamlData, _ := yaml.Marshal(obj)
t.Logf("Intermediate yaml:\n%v\n", string(yamlData)) t.Logf("Intermediate yaml:\n%v\n", string(yamlData))
t.Logf("Intermediate json:\n%v\n", string(jsonData)) t.Logf("Intermediate json:\n%v\n", string(jsonData))
......
...@@ -53,7 +53,7 @@ func (s *ProxyServer) Serve() error { ...@@ -53,7 +53,7 @@ func (s *ProxyServer) Serve() error {
func (s *ProxyServer) doError(w http.ResponseWriter, err error) { func (s *ProxyServer) doError(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
w.Header().Add("Content-type", "application/json") w.Header().Add("Content-type", "application/json")
data, _ := runtime.Encode(api.Status{ data, _ := runtime.DefaultCodec.Encode(api.Status{
Status: api.StatusFailure, Status: api.StatusFailure,
Message: fmt.Sprintf("internal error: %#v", err), Message: fmt.Sprintf("internal error: %#v", err),
}) })
......
...@@ -50,7 +50,7 @@ func (i *IdentityPrinter) Print(data []byte, w io.Writer) error { ...@@ -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. // PrintObj is an implementation of ResourcePrinter.PrintObj which simply writes the object to the Writer.
func (i *IdentityPrinter) PrintObj(obj interface{}, output io.Writer) error { func (i *IdentityPrinter) PrintObj(obj interface{}, output io.Writer) error {
data, err := runtime.Encode(obj) data, err := runtime.DefaultCodec.Encode(obj)
if err != nil { if err != nil {
return err return err
} }
...@@ -260,7 +260,7 @@ func (h *HumanReadablePrinter) Print(data []byte, output io.Writer) error { ...@@ -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) return fmt.Errorf("unexpected object with no 'kind' field: %s", data)
} }
obj, err := runtime.Decode(data) obj, err := runtime.DefaultCodec.Decode(data)
if err != nil { if err != nil {
return err return err
} }
...@@ -292,7 +292,7 @@ type TemplatePrinter struct { ...@@ -292,7 +292,7 @@ type TemplatePrinter struct {
// Print parses the data as JSON, and re-formats it with the Go Template. // Print parses the data as JSON, and re-formats it with the Go Template.
func (t *TemplatePrinter) Print(data []byte, w io.Writer) error { func (t *TemplatePrinter) Print(data []byte, w io.Writer) error {
obj, err := runtime.Decode(data) obj, err := runtime.DefaultCodec.Decode(data)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -96,7 +96,7 @@ func TestIdentityPrinter(t *testing.T) { ...@@ -96,7 +96,7 @@ func TestIdentityPrinter(t *testing.T) {
} }
buff.Reset() buff.Reset()
printer.PrintObj(obj, buff) printer.PrintObj(obj, buff)
objOut, err := runtime.Decode([]byte(buff.String())) objOut, err := runtime.DefaultCodec.Decode([]byte(buff.String()))
if err != nil { if err != nil {
t.Errorf("Unexpeted error: %#v", err) t.Errorf("Unexpeted error: %#v", err)
} }
......
...@@ -47,8 +47,8 @@ type SourceEtcd struct { ...@@ -47,8 +47,8 @@ type SourceEtcd struct {
func NewSourceEtcd(key string, client tools.EtcdClient, updates chan<- interface{}) *SourceEtcd { func NewSourceEtcd(key string, client tools.EtcdClient, updates chan<- interface{}) *SourceEtcd {
helper := tools.EtcdHelper{ helper := tools.EtcdHelper{
client, client,
runtime.Codec, runtime.DefaultCodec,
runtime.ResourceVersioner, runtime.DefaultResourceVersioner,
} }
source := &SourceEtcd{ source := &SourceEtcd{
key: key, key: key,
......
...@@ -136,5 +136,5 @@ func (m *Master) API_v1beta1() (map[string]apiserver.RESTStorage, apiserver.Code ...@@ -136,5 +136,5 @@ func (m *Master) API_v1beta1() (map[string]apiserver.RESTStorage, apiserver.Code
for k, v := range m.storage { for k, v := range m.storage {
storage[k] = v storage[k] = v
} }
return storage, runtime.Codec return storage, runtime.DefaultCodec
} }
...@@ -133,7 +133,7 @@ func (s ConfigSourceEtcd) GetServices() ([]api.Service, []api.Endpoints, error) ...@@ -133,7 +133,7 @@ func (s ConfigSourceEtcd) GetServices() ([]api.Service, []api.Endpoints, error)
// and create a Service entry for it. // and create a Service entry for it.
for i, node := range response.Node.Nodes { for i, node := range response.Node.Nodes {
var svc api.Service var svc api.Service
err = runtime.DecodeInto([]byte(node.Value), &svc) err = runtime.DefaultCodec.DecodeInto([]byte(node.Value), &svc)
if err != nil { if err != nil {
glog.Errorf("Failed to load Service: %s (%#v)", node.Value, err) glog.Errorf("Failed to load Service: %s (%#v)", node.Value, err)
continue continue
...@@ -166,7 +166,7 @@ func (s ConfigSourceEtcd) GetEndpoints(service string) (api.Endpoints, error) { ...@@ -166,7 +166,7 @@ func (s ConfigSourceEtcd) GetEndpoints(service string) (api.Endpoints, error) {
} }
// Parse all the endpoint specifications in this value. // Parse all the endpoint specifications in this value.
var e api.Endpoints var e api.Endpoints
err = runtime.DecodeInto([]byte(response.Node.Value), &e) err = runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &e)
return e, err return e, err
} }
...@@ -176,7 +176,7 @@ func etcdResponseToService(response *etcd.Response) (*api.Service, error) { ...@@ -176,7 +176,7 @@ func etcdResponseToService(response *etcd.Response) (*api.Service, error) {
return nil, fmt.Errorf("invalid response from etcd: %#v", response) return nil, fmt.Errorf("invalid response from etcd: %#v", response)
} }
var svc api.Service var svc api.Service
err := runtime.DecodeInto([]byte(response.Node.Value), &svc) err := runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &svc)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -230,7 +230,7 @@ func (s ConfigSourceEtcd) ProcessChange(response *etcd.Response) { ...@@ -230,7 +230,7 @@ func (s ConfigSourceEtcd) ProcessChange(response *etcd.Response) {
func (s ConfigSourceEtcd) ProcessEndpointResponse(response *etcd.Response) { func (s ConfigSourceEtcd) ProcessEndpointResponse(response *etcd.Response) {
glog.Infof("Processing a change in endpoint configuration... %s", *response) glog.Infof("Processing a change in endpoint configuration... %s", *response)
var endpoints api.Endpoints var endpoints api.Endpoints
err := runtime.DecodeInto([]byte(response.Node.Value), &endpoints) err := runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &endpoints)
if err != nil { if err != nil {
glog.Errorf("Failed to parse service out of etcd key: %v : %+v", response.Node.Value, err) glog.Errorf("Failed to parse service out of etcd key: %v : %+v", response.Node.Value, err)
return return
......
...@@ -38,12 +38,12 @@ func TestNewBindingStorage(t *testing.T) { ...@@ -38,12 +38,12 @@ func TestNewBindingStorage(t *testing.T) {
PodID: "foo", PodID: "foo",
Host: "bar", Host: "bar",
} }
body, err := runtime.Encode(binding) body, err := runtime.DefaultCodec.Encode(binding)
if err != nil { if err != nil {
t.Fatalf("Unexpected encode error %v", err) t.Fatalf("Unexpected encode error %v", err)
} }
obj := b.New() obj := b.New()
err = runtime.DecodeInto(body, obj) err = runtime.DefaultCodec.DecodeInto(body, obj)
if err != nil { if err != nil {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
......
...@@ -112,13 +112,13 @@ func TestControllerDecode(t *testing.T) { ...@@ -112,13 +112,13 @@ func TestControllerDecode(t *testing.T) {
ID: "foo", ID: "foo",
}, },
} }
body, err := runtime.Encode(controller) body, err := runtime.DefaultCodec.Encode(controller)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
controllerOut := storage.New() controllerOut := storage.New()
if err := runtime.DecodeInto(body, controllerOut); err != nil { if err := runtime.DefaultCodec.DecodeInto(body, controllerOut); err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
......
...@@ -45,8 +45,8 @@ func NewRegistry(client tools.EtcdClient) *Registry { ...@@ -45,8 +45,8 @@ func NewRegistry(client tools.EtcdClient) *Registry {
registry := &Registry{ registry := &Registry{
EtcdHelper: tools.EtcdHelper{ EtcdHelper: tools.EtcdHelper{
client, client,
runtime.Codec, runtime.DefaultCodec,
runtime.ResourceVersioner, runtime.DefaultResourceVersioner,
}, },
} }
registry.manifestFactory = &BasicManifestFactory{ registry.manifestFactory = &BasicManifestFactory{
......
...@@ -108,7 +108,7 @@ func TestEtcdCreatePod(t *testing.T) { ...@@ -108,7 +108,7 @@ func TestEtcdCreatePod(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var pod api.Pod var pod api.Pod
err = runtime.DecodeInto([]byte(resp.Node.Value), &pod) err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -122,7 +122,7 @@ func TestEtcdCreatePod(t *testing.T) { ...@@ -122,7 +122,7 @@ func TestEtcdCreatePod(t *testing.T) {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
err = runtime.DecodeInto([]byte(resp.Node.Value), &manifests) err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &manifests)
if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" { if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests) t.Errorf("Unexpected manifest list: %#v", manifests)
} }
...@@ -235,7 +235,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { ...@@ -235,7 +235,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var pod api.Pod var pod api.Pod
err = runtime.DecodeInto([]byte(resp.Node.Value), &pod) err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -249,7 +249,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { ...@@ -249,7 +249,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
err = runtime.DecodeInto([]byte(resp.Node.Value), &manifests) err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &manifests)
if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" { if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests) t.Errorf("Unexpected manifest list: %#v", manifests)
} }
...@@ -300,7 +300,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { ...@@ -300,7 +300,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var pod api.Pod var pod api.Pod
err = runtime.DecodeInto([]byte(resp.Node.Value), &pod) err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -314,7 +314,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { ...@@ -314,7 +314,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
err = runtime.DecodeInto([]byte(resp.Node.Value), &manifests) err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &manifests)
if len(manifests.Items) != 2 || manifests.Items[1].ID != "foo" { if len(manifests.Items) != 2 || manifests.Items[1].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests) t.Errorf("Unexpected manifest list: %#v", manifests)
} }
...@@ -350,7 +350,7 @@ func TestEtcdDeletePod(t *testing.T) { ...@@ -350,7 +350,7 @@ func TestEtcdDeletePod(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var manifests api.ContainerManifestList var manifests api.ContainerManifestList
runtime.DecodeInto([]byte(response.Node.Value), &manifests) runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &manifests)
if len(manifests.Items) != 0 { if len(manifests.Items) != 0 {
t.Errorf("Unexpected container set: %s, expected empty", response.Node.Value) t.Errorf("Unexpected container set: %s, expected empty", response.Node.Value)
} }
...@@ -388,7 +388,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) { ...@@ -388,7 +388,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var manifests api.ContainerManifestList var manifests api.ContainerManifestList
runtime.DecodeInto([]byte(response.Node.Value), &manifests) runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &manifests)
if len(manifests.Items) != 1 { if len(manifests.Items) != 1 {
t.Fatalf("Unexpected manifest set: %#v, expected empty", manifests) t.Fatalf("Unexpected manifest set: %#v, expected empty", manifests)
} }
...@@ -607,7 +607,7 @@ func TestEtcdCreateController(t *testing.T) { ...@@ -607,7 +607,7 @@ func TestEtcdCreateController(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var ctrl api.ReplicationController var ctrl api.ReplicationController
err = runtime.DecodeInto([]byte(resp.Node.Value), &ctrl) err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &ctrl)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -699,7 +699,7 @@ func TestEtcdCreateService(t *testing.T) { ...@@ -699,7 +699,7 @@ func TestEtcdCreateService(t *testing.T) {
} }
var service api.Service var service api.Service
err = runtime.DecodeInto([]byte(resp.Node.Value), &service) err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &service)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -874,7 +874,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) { ...@@ -874,7 +874,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var endpointsOut api.Endpoints var endpointsOut api.Endpoints
err = runtime.DecodeInto([]byte(response.Node.Value), &endpointsOut) err = runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &endpointsOut)
if !reflect.DeepEqual(endpoints, endpointsOut) { if !reflect.DeepEqual(endpoints, endpointsOut) {
t.Errorf("Unexpected endpoints: %#v, expected %#v", endpointsOut, endpoints) t.Errorf("Unexpected endpoints: %#v, expected %#v", endpointsOut, endpoints)
} }
......
...@@ -178,13 +178,13 @@ func TestPodDecode(t *testing.T) { ...@@ -178,13 +178,13 @@ func TestPodDecode(t *testing.T) {
ID: "foo", ID: "foo",
}, },
} }
body, err := runtime.Encode(expected) body, err := runtime.DefaultCodec.Encode(expected)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
actual := storage.New() actual := storage.New()
if err := runtime.DecodeInto(body, actual); err != nil { if err := runtime.DefaultCodec.DecodeInto(body, actual); err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
......
...@@ -33,7 +33,7 @@ func (a *EmbeddedObject) UnmarshalJSON(b []byte) error { ...@@ -33,7 +33,7 @@ func (a *EmbeddedObject) UnmarshalJSON(b []byte) error {
return nil return nil
} }
obj, err := Codec.Decode(b) obj, err := DefaultCodec.Decode(b)
if err != nil { if err != nil {
return err return err
} }
...@@ -48,7 +48,7 @@ func (a EmbeddedObject) MarshalJSON() ([]byte, error) { ...@@ -48,7 +48,7 @@ func (a EmbeddedObject) MarshalJSON() ([]byte, error) {
return []byte("null"), nil return []byte("null"), nil
} }
return Codec.Encode(a.Object) return DefaultCodec.Encode(a.Object)
} }
// SetYAML implements the yaml.Setter interface. // SetYAML implements the yaml.Setter interface.
...@@ -67,7 +67,7 @@ func (a *EmbeddedObject) SetYAML(tag string, value interface{}) bool { ...@@ -67,7 +67,7 @@ func (a *EmbeddedObject) SetYAML(tag string, value interface{}) bool {
if err != nil { if err != nil {
panic("yaml can't reverse its own object") panic("yaml can't reverse its own object")
} }
obj, err := Codec.Decode(b) obj, err := DefaultCodec.Decode(b)
if err != nil { if err != nil {
return false return false
} }
...@@ -82,7 +82,7 @@ func (a EmbeddedObject) GetYAML() (tag string, value interface{}) { ...@@ -82,7 +82,7 @@ func (a EmbeddedObject) GetYAML() (tag string, value interface{}) {
return return
} }
// Encode returns JSON, which is conveniently a subset of YAML. // Encode returns JSON, which is conveniently a subset of YAML.
v, err := Codec.Encode(a.Object) v, err := DefaultCodec.Encode(a.Object)
if err != nil { if err != nil {
panic("impossible to encode API object!") panic("impossible to encode API object!")
} }
......
...@@ -24,24 +24,9 @@ import ( ...@@ -24,24 +24,9 @@ import (
"gopkg.in/v1/yaml" "gopkg.in/v1/yaml"
) )
// codec defines methods for serializing and deserializing API var DefaultResourceVersioner ResourceVersioner = NewJSONBaseResourceVersioner()
// objects.
type codec interface {
Encode(obj Object) (data []byte, err error)
Decode(data []byte) (Object, error)
DecodeInto(data []byte, obj Object) error
}
// resourceVersioner provides methods for setting and retrieving
// the resource version from an API object.
type resourceVersioner interface {
SetResourceVersion(obj Object, version uint64) error
ResourceVersion(obj Object) (uint64, error)
}
var ResourceVersioner resourceVersioner = NewJSONBaseResourceVersioner()
var DefaultScheme = NewScheme("", "v1beta1") var DefaultScheme = NewScheme("", "v1beta1")
var Codec codec = DefaultScheme var DefaultCodec Codec = DefaultScheme
// Scheme defines methods for serializing and deserializing API objects. It // Scheme defines methods for serializing and deserializing API objects. It
// is an adaptation of conversion's Scheme for our API objects. // is an adaptation of conversion's Scheme for our API objects.
......
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package runtime
// Codec defines methods for serializing and deserializing API objects.
type Codec interface {
Encode(obj Object) (data []byte, err error)
Decode(data []byte) (Object, error)
DecodeInto(data []byte, obj Object) error
}
// ResourceVersioner provides methods for setting and retrieving
// the resource version from an API object.
type ResourceVersioner interface {
SetResourceVersion(obj Object, version uint64) error
ResourceVersion(obj Object) (uint64, error)
}
// All api types must support the Object interface. It's deliberately tiny so that this is not an onerous
// burden. Implement it with a pointer reciever; this will allow us to use the go compiler to check the
// one thing about our objects that it's capable of checking for us.
type Object interface {
// This function is used only to enforce membership. It's never called.
// TODO: Consider mass rename in the future to make it do something useful.
IsAnAPIObject()
}
...@@ -23,7 +23,7 @@ import ( ...@@ -23,7 +23,7 @@ import (
// NewJSONBaseResourceVersioner returns a resourceVersioner that can set or // NewJSONBaseResourceVersioner returns a resourceVersioner that can set or
// retrieve ResourceVersion on objects derived from JSONBase. // retrieve ResourceVersion on objects derived from JSONBase.
func NewJSONBaseResourceVersioner() resourceVersioner { func NewJSONBaseResourceVersioner() ResourceVersioner {
return &jsonBaseResourceVersioner{} return &jsonBaseResourceVersioner{}
} }
......
...@@ -41,8 +41,8 @@ type TestResource struct { ...@@ -41,8 +41,8 @@ type TestResource struct {
} }
var scheme *conversion.Scheme var scheme *conversion.Scheme
var codec = runtime.Codec var codec = runtime.DefaultCodec
var versioner = runtime.ResourceVersioner var versioner = runtime.DefaultResourceVersioner
func init() { func init() {
scheme = conversion.NewScheme() scheme = conversion.NewScheme()
......
...@@ -84,7 +84,7 @@ func TestExtractObj(t *testing.T) { ...@@ -84,7 +84,7 @@ func TestExtractObj(t *testing.T) {
func TestWatch(t *testing.T) { func TestWatch(t *testing.T) {
client := newEtcdClient() client := newEtcdClient()
helper := tools.EtcdHelper{Client: client, Codec: runtime.Codec, ResourceVersioner: runtime.ResourceVersioner} helper := tools.EtcdHelper{Client: client, Codec: runtime.DefaultCodec, ResourceVersioner: runtime.DefaultResourceVersioner}
withEtcdKey(func(key string) { withEtcdKey(func(key string) {
resp, err := client.Set(key, runtime.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0) resp, err := client.Set(key, runtime.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment