mirror of https://github.com/k3s-io/k3s
Rename Codec and ResourceVersioner to add Default in front, to allow for types of those names
parent
828b70abb9
commit
1c2b65788d
|
@ -266,7 +266,7 @@ func executeAPIRequest(method string, c *client.Client) bool {
|
|||
if setBody {
|
||||
if version != 0 {
|
||||
data := readConfig(storage)
|
||||
obj, err := runtime.Decode(data)
|
||||
obj, err := runtime.DefaultCodec.Decode(data)
|
||||
if err != nil {
|
||||
glog.Fatalf("error setting resource version: %v", err)
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ func executeAPIRequest(method string, c *client.Client) bool {
|
|||
glog.Fatalf("error setting resource version: %v", err)
|
||||
}
|
||||
jsonBase.SetResourceVersion(version)
|
||||
data, err = runtime.Encode(obj)
|
||||
data, err = runtime.DefaultCodec.Encode(obj)
|
||||
if err != nil {
|
||||
glog.Fatalf("error setting resource version: %v", err)
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ func TestApiExamples(t *testing.T) {
|
|||
return
|
||||
}
|
||||
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))
|
||||
return
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ func TestExamples(t *testing.T) {
|
|||
return
|
||||
}
|
||||
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))
|
||||
return
|
||||
}
|
||||
|
@ -168,14 +168,14 @@ func TestReadme(t *testing.T) {
|
|||
}
|
||||
for _, json := range match[1:] {
|
||||
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))
|
||||
return
|
||||
}
|
||||
if errors := validateObject(expectedType); len(errors) > 0 {
|
||||
t.Errorf("%s did not validate correctly: %v", path, errors)
|
||||
}
|
||||
encoded, err := runtime.Encode(expectedType)
|
||||
encoded, err := runtime.DefaultCodec.Encode(expectedType)
|
||||
if err != nil {
|
||||
t.Errorf("Could not encode object: %v", err)
|
||||
continue
|
||||
|
|
|
@ -115,13 +115,13 @@ func runTest(t *testing.T, source runtime.Object) {
|
|||
j.SetKind("")
|
||||
j.SetAPIVersion("")
|
||||
|
||||
data, err := runtime.Codec.Encode(source)
|
||||
data, err := runtime.DefaultCodec.Encode(source)
|
||||
if err != nil {
|
||||
t.Errorf("%v: %v (%#v)", name, err, source)
|
||||
return
|
||||
}
|
||||
|
||||
obj2, err := runtime.Codec.Decode(data)
|
||||
obj2, err := runtime.DefaultCodec.Decode(data)
|
||||
if err != nil {
|
||||
t.Errorf("%v: %v", name, err)
|
||||
return
|
||||
|
@ -132,7 +132,7 @@ func runTest(t *testing.T, source 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 {
|
||||
t.Errorf("2: %v: %v", name, err)
|
||||
return
|
||||
|
@ -174,8 +174,8 @@ func TestEncode_Ptr(t *testing.T) {
|
|||
Labels: map[string]string{"name": "foo"},
|
||||
}
|
||||
obj := runtime.Object(pod)
|
||||
data, err := runtime.Codec.Encode(obj)
|
||||
obj2, err2 := runtime.Codec.Decode(data)
|
||||
data, err := runtime.DefaultCodec.Encode(obj)
|
||||
obj2, err2 := runtime.DefaultCodec.Decode(data)
|
||||
if err != nil || err2 != nil {
|
||||
t.Fatalf("Failure: '%v' '%v'", err, err2)
|
||||
}
|
||||
|
@ -189,11 +189,11 @@ func TestEncode_Ptr(t *testing.T) {
|
|||
|
||||
func TestBadJSONRejection(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
/*badJSONKindMismatch := []byte(`{"kind": "Pod"}`)
|
||||
|
|
|
@ -42,7 +42,7 @@ func convert(obj interface{}) (interface{}, error) {
|
|||
return obj, nil
|
||||
}
|
||||
|
||||
var codec = runtime.Codec
|
||||
var codec = runtime.DefaultCodec
|
||||
|
||||
func init() {
|
||||
runtime.AddKnownTypes("", Simple{}, SimpleList{})
|
||||
|
@ -667,7 +667,7 @@ func TestWriteJSONDecodeError(t *testing.T) {
|
|||
type T struct {
|
||||
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)
|
||||
if status.Reason != api.StatusReasonUnknown {
|
||||
|
|
|
@ -222,7 +222,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.DecodeInto(body, &status); err == nil && status.Status != "" {
|
||||
if err := runtime.DefaultCodec.DecodeInto(body, &status); err == nil && status.Status != "" {
|
||||
isStatusResponse = true
|
||||
}
|
||||
|
||||
|
|
|
@ -309,7 +309,7 @@ func TestCreateController(t *testing.T) {
|
|||
|
||||
func body(obj interface{}, raw *string) *string {
|
||||
if obj != nil {
|
||||
bs, _ := runtime.Encode(obj)
|
||||
bs, _ := runtime.DefaultCodec.Encode(obj)
|
||||
body := string(bs)
|
||||
return &body
|
||||
}
|
||||
|
@ -522,7 +522,7 @@ func TestDoRequest(t *testing.T) {
|
|||
|
||||
func TestDoRequestAccepted(t *testing.T) {
|
||||
status := api.Status{Status: api.StatusWorking}
|
||||
expectedBody, _ := runtime.Encode(status)
|
||||
expectedBody, _ := runtime.DefaultCodec.Encode(status)
|
||||
fakeHandler := util.FakeHandler{
|
||||
StatusCode: 202,
|
||||
ResponseBody: string(expectedBody),
|
||||
|
@ -559,7 +559,7 @@ func TestDoRequestAccepted(t *testing.T) {
|
|||
|
||||
func TestDoRequestAcceptedSuccess(t *testing.T) {
|
||||
status := api.Status{Status: api.StatusSuccess}
|
||||
expectedBody, _ := runtime.Encode(status)
|
||||
expectedBody, _ := runtime.DefaultCodec.Encode(status)
|
||||
fakeHandler := util.FakeHandler{
|
||||
StatusCode: 202,
|
||||
ResponseBody: string(expectedBody),
|
||||
|
@ -579,7 +579,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("Unexpected error %#v", err)
|
||||
}
|
||||
statusOut, err := runtime.Decode(body)
|
||||
statusOut, err := runtime.DefaultCodec.Decode(body)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %#v", err)
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ type Fake struct {
|
|||
|
||||
func (c *Fake) ListPods(selector labels.Selector) (api.PodList, error) {
|
||||
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) {
|
||||
|
@ -74,7 +74,7 @@ func (c *Fake) ListReplicationControllers(selector labels.Selector) (api.Replica
|
|||
|
||||
func (c *Fake) GetReplicationController(name string) (api.ReplicationController, error) {
|
||||
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) {
|
||||
|
|
|
@ -205,7 +205,7 @@ func (r *Request) Body(obj interface{}) *Request {
|
|||
case io.Reader:
|
||||
r.body = t
|
||||
default:
|
||||
data, err := runtime.Encode(obj)
|
||||
data, err := runtime.DefaultCodec.Encode(obj)
|
||||
if err != nil {
|
||||
r.err = err
|
||||
return r
|
||||
|
@ -318,7 +318,7 @@ func (r Result) Get() (interface{}, error) {
|
|||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
return runtime.Decode(r.body)
|
||||
return runtime.DefaultCodec.Decode(r.body)
|
||||
}
|
||||
|
||||
// Into stores the result into obj, if possible.
|
||||
|
@ -326,7 +326,7 @@ func (r Result) Into(obj interface{}) error {
|
|||
if r.err != nil {
|
||||
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.
|
||||
|
|
|
@ -38,7 +38,7 @@ import (
|
|||
func TestDoRequestNewWay(t *testing.T) {
|
||||
reqBody := "request body"
|
||||
expectedObj := &api.Service{Port: 12345}
|
||||
expectedBody, _ := runtime.Encode(expectedObj)
|
||||
expectedBody, _ := runtime.DefaultCodec.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.Encode(reqObj)
|
||||
reqBodyExpected, _ := runtime.DefaultCodec.Encode(reqObj)
|
||||
expectedObj := &api.Service{Port: 12345}
|
||||
expectedBody, _ := runtime.Encode(expectedObj)
|
||||
expectedBody, _ := runtime.DefaultCodec.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.Encode(reqObj)
|
||||
reqBodyExpected, _ := runtime.DefaultCodec.Encode(reqObj)
|
||||
expectedObj := &api.Service{Port: 12345}
|
||||
expectedBody, _ := runtime.Encode(expectedObj)
|
||||
expectedBody, _ := runtime.DefaultCodec.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.Encode(reqObj)
|
||||
reqBodyExpected, err := runtime.DefaultCodec.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.Encode(expectedObj)
|
||||
expectedBody, _ := runtime.DefaultCodec.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.Encode(objects[callNumber])
|
||||
data, err := runtime.DefaultCodec.Encode(objects[callNumber])
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected encode error")
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
|
|||
}
|
||||
|
||||
func TestSyncReplicationControllerDoesNothing(t *testing.T) {
|
||||
body, _ := runtime.Encode(newPodList(2))
|
||||
body, _ := runtime.DefaultCodec.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.Encode(newPodList(2))
|
||||
body, _ := runtime.DefaultCodec.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.Encode(newPodList(0))
|
||||
body, _ := runtime.DefaultCodec.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.Encode(api.Pod{})
|
||||
body, _ := runtime.DefaultCodec.Encode(api.Pod{})
|
||||
fakeHandler := util.FakeHandler{
|
||||
StatusCode: 200,
|
||||
ResponseBody: string(body),
|
||||
|
|
|
@ -44,11 +44,11 @@ func (p *Parser) ToWireFormat(data []byte, storage string) ([]byte, error) {
|
|||
}
|
||||
|
||||
obj := reflect.New(prototypeType).Interface()
|
||||
err := runtime.DecodeInto(data, obj)
|
||||
err := runtime.DefaultCodec.DecodeInto(data, obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return runtime.Encode(obj)
|
||||
return runtime.DefaultCodec.Encode(obj)
|
||||
}
|
||||
|
||||
func (p *Parser) SupportedWireStorage() []string {
|
||||
|
|
|
@ -33,7 +33,7 @@ func TestParseBadStorage(t *testing.T) {
|
|||
}
|
||||
|
||||
func DoParseTest(t *testing.T, storage string, obj interface{}, p *Parser) {
|
||||
jsonData, _ := runtime.Encode(obj)
|
||||
jsonData, _ := runtime.DefaultCodec.Encode(obj)
|
||||
yamlData, _ := yaml.Marshal(obj)
|
||||
t.Logf("Intermediate yaml:\n%v\n", string(yamlData))
|
||||
t.Logf("Intermediate json:\n%v\n", string(jsonData))
|
||||
|
|
|
@ -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.Encode(api.Status{
|
||||
data, _ := runtime.DefaultCodec.Encode(api.Status{
|
||||
Status: api.StatusFailure,
|
||||
Message: fmt.Sprintf("internal error: %#v", err),
|
||||
})
|
||||
|
|
|
@ -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 interface{}, output io.Writer) error {
|
||||
data, err := runtime.Encode(obj)
|
||||
data, err := runtime.DefaultCodec.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.Decode(data)
|
||||
obj, err := runtime.DefaultCodec.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.Decode(data)
|
||||
obj, err := runtime.DefaultCodec.Decode(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ func TestIdentityPrinter(t *testing.T) {
|
|||
}
|
||||
buff.Reset()
|
||||
printer.PrintObj(obj, buff)
|
||||
objOut, err := runtime.Decode([]byte(buff.String()))
|
||||
objOut, err := runtime.DefaultCodec.Decode([]byte(buff.String()))
|
||||
if err != nil {
|
||||
t.Errorf("Unexpeted error: %#v", err)
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@ type SourceEtcd struct {
|
|||
func NewSourceEtcd(key string, client tools.EtcdClient, updates chan<- interface{}) *SourceEtcd {
|
||||
helper := tools.EtcdHelper{
|
||||
client,
|
||||
runtime.Codec,
|
||||
runtime.ResourceVersioner,
|
||||
runtime.DefaultCodec,
|
||||
runtime.DefaultResourceVersioner,
|
||||
}
|
||||
source := &SourceEtcd{
|
||||
key: key,
|
||||
|
|
|
@ -136,5 +136,5 @@ func (m *Master) API_v1beta1() (map[string]apiserver.RESTStorage, apiserver.Code
|
|||
for k, v := range m.storage {
|
||||
storage[k] = v
|
||||
}
|
||||
return storage, runtime.Codec
|
||||
return storage, runtime.DefaultCodec
|
||||
}
|
||||
|
|
|
@ -133,7 +133,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.DecodeInto([]byte(node.Value), &svc)
|
||||
err = runtime.DefaultCodec.DecodeInto([]byte(node.Value), &svc)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to load Service: %s (%#v)", node.Value, err)
|
||||
continue
|
||||
|
@ -166,7 +166,7 @@ func (s ConfigSourceEtcd) GetEndpoints(service string) (api.Endpoints, error) {
|
|||
}
|
||||
// Parse all the endpoint specifications in this value.
|
||||
var e api.Endpoints
|
||||
err = runtime.DecodeInto([]byte(response.Node.Value), &e)
|
||||
err = runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &e)
|
||||
return e, err
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,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.DecodeInto([]byte(response.Node.Value), &svc)
|
||||
err := runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -230,7 +230,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.DecodeInto([]byte(response.Node.Value), &endpoints)
|
||||
err := runtime.DefaultCodec.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
|
||||
|
|
|
@ -38,12 +38,12 @@ func TestNewBindingStorage(t *testing.T) {
|
|||
PodID: "foo",
|
||||
Host: "bar",
|
||||
}
|
||||
body, err := runtime.Encode(binding)
|
||||
body, err := runtime.DefaultCodec.Encode(binding)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected encode error %v", err)
|
||||
}
|
||||
obj := b.New()
|
||||
err = runtime.DecodeInto(body, obj)
|
||||
err = runtime.DefaultCodec.DecodeInto(body, obj)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
|
|
|
@ -112,13 +112,13 @@ func TestControllerDecode(t *testing.T) {
|
|||
ID: "foo",
|
||||
},
|
||||
}
|
||||
body, err := runtime.Encode(controller)
|
||||
body, err := runtime.DefaultCodec.Encode(controller)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ func NewRegistry(client tools.EtcdClient) *Registry {
|
|||
registry := &Registry{
|
||||
EtcdHelper: tools.EtcdHelper{
|
||||
client,
|
||||
runtime.Codec,
|
||||
runtime.ResourceVersioner,
|
||||
runtime.DefaultCodec,
|
||||
runtime.DefaultResourceVersioner,
|
||||
},
|
||||
}
|
||||
registry.manifestFactory = &BasicManifestFactory{
|
||||
|
|
|
@ -108,7 +108,7 @@ func TestEtcdCreatePod(t *testing.T) {
|
|||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
var pod api.Pod
|
||||
err = runtime.DecodeInto([]byte(resp.Node.Value), &pod)
|
||||
err = runtime.DefaultCodec.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.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" {
|
||||
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.DecodeInto([]byte(resp.Node.Value), &pod)
|
||||
err = runtime.DefaultCodec.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.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" {
|
||||
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.DecodeInto([]byte(resp.Node.Value), &pod)
|
||||
err = runtime.DefaultCodec.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.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" {
|
||||
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.DecodeInto([]byte(response.Node.Value), &manifests)
|
||||
runtime.DefaultCodec.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.DecodeInto([]byte(response.Node.Value), &manifests)
|
||||
runtime.DefaultCodec.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.DecodeInto([]byte(resp.Node.Value), &ctrl)
|
||||
err = runtime.DefaultCodec.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.DecodeInto([]byte(resp.Node.Value), &service)
|
||||
err = runtime.DefaultCodec.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.DecodeInto([]byte(response.Node.Value), &endpointsOut)
|
||||
err = runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &endpointsOut)
|
||||
if !reflect.DeepEqual(endpoints, endpointsOut) {
|
||||
t.Errorf("Unexpected endpoints: %#v, expected %#v", endpointsOut, endpoints)
|
||||
}
|
||||
|
|
|
@ -178,13 +178,13 @@ func TestPodDecode(t *testing.T) {
|
|||
ID: "foo",
|
||||
},
|
||||
}
|
||||
body, err := runtime.Encode(expected)
|
||||
body, err := runtime.DefaultCodec.Encode(expected)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ func (a *EmbeddedObject) UnmarshalJSON(b []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
obj, err := Codec.Decode(b)
|
||||
obj, err := DefaultCodec.Decode(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func (a EmbeddedObject) MarshalJSON() ([]byte, error) {
|
|||
return []byte("null"), nil
|
||||
}
|
||||
|
||||
return Codec.Encode(a.Object)
|
||||
return DefaultCodec.Encode(a.Object)
|
||||
}
|
||||
|
||||
// SetYAML implements the yaml.Setter interface.
|
||||
|
@ -67,7 +67,7 @@ func (a *EmbeddedObject) SetYAML(tag string, value interface{}) bool {
|
|||
if err != nil {
|
||||
panic("yaml can't reverse its own object")
|
||||
}
|
||||
obj, err := Codec.Decode(b)
|
||||
obj, err := DefaultCodec.Decode(b)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func (a EmbeddedObject) GetYAML() (tag string, value interface{}) {
|
|||
return
|
||||
}
|
||||
// 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 {
|
||||
panic("impossible to encode API object!")
|
||||
}
|
||||
|
|
|
@ -24,24 +24,9 @@ import (
|
|||
"gopkg.in/v1/yaml"
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
var ResourceVersioner resourceVersioner = NewJSONBaseResourceVersioner()
|
||||
var DefaultResourceVersioner ResourceVersioner = NewJSONBaseResourceVersioner()
|
||||
var DefaultScheme = NewScheme("", "v1beta1")
|
||||
var Codec codec = DefaultScheme
|
||||
var DefaultCodec Codec = DefaultScheme
|
||||
|
||||
// Scheme defines methods for serializing and deserializing API objects. It
|
||||
// is an adaptation of conversion's Scheme for our API objects.
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
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 (
|
|||
|
||||
// NewJSONBaseResourceVersioner returns a resourceVersioner that can set or
|
||||
// retrieve ResourceVersion on objects derived from JSONBase.
|
||||
func NewJSONBaseResourceVersioner() resourceVersioner {
|
||||
func NewJSONBaseResourceVersioner() ResourceVersioner {
|
||||
return &jsonBaseResourceVersioner{}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@ type TestResource struct {
|
|||
}
|
||||
|
||||
var scheme *conversion.Scheme
|
||||
var codec = runtime.Codec
|
||||
var versioner = runtime.ResourceVersioner
|
||||
var codec = runtime.DefaultCodec
|
||||
var versioner = runtime.DefaultResourceVersioner
|
||||
|
||||
func init() {
|
||||
scheme = conversion.NewScheme()
|
||||
|
|
|
@ -84,7 +84,7 @@ func TestExtractObj(t *testing.T) {
|
|||
|
||||
func TestWatch(t *testing.T) {
|
||||
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) {
|
||||
resp, err := client.Set(key, runtime.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue