Combine pkg/apitools and pkg/api/common and call the result pkg/runtime

This commit is contained in:
Daniel Smith
2014-09-02 10:55:27 -07:00
parent 099c8fd36f
commit a63966e73c
44 changed files with 218 additions and 237 deletions

View File

@@ -20,7 +20,7 @@ import (
"reflect"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/golang/glog"
@@ -81,7 +81,7 @@ func (gc *Reflector) watchHandler(w watch.Interface, resourceVersion *uint64) {
glog.Errorf("expected type %v, but watch event object had type %v", e, a)
continue
}
jsonBase, err := apitools.FindJSONBase(event.Object)
jsonBase, err := runtime.FindJSONBase(event.Object)
if err != nil {
glog.Errorf("unable to understand watch event %#v", event)
continue

View File

@@ -27,8 +27,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
@@ -217,7 +217,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 := apitools.DecodeInto(body, &status); err == nil && status.Status != "" {
if err := runtime.DecodeInto(body, &status); err == nil && status.Status != "" {
isStatusResponse = true
}

View File

@@ -26,8 +26,8 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
)
@@ -309,7 +309,7 @@ func TestCreateController(t *testing.T) {
func body(obj interface{}, raw *string) *string {
if obj != nil {
bs, _ := apitools.Encode(obj)
bs, _ := runtime.Encode(obj)
body := string(bs)
return &body
}
@@ -471,7 +471,7 @@ func TestDoRequest(t *testing.T) {
func TestDoRequestAccepted(t *testing.T) {
status := api.Status{Status: api.StatusWorking}
expectedBody, _ := apitools.Encode(status)
expectedBody, _ := runtime.Encode(status)
fakeHandler := util.FakeHandler{
StatusCode: 202,
ResponseBody: string(expectedBody),
@@ -508,7 +508,7 @@ func TestDoRequestAccepted(t *testing.T) {
func TestDoRequestAcceptedSuccess(t *testing.T) {
status := api.Status{Status: api.StatusSuccess}
expectedBody, _ := apitools.Encode(status)
expectedBody, _ := runtime.Encode(status)
fakeHandler := util.FakeHandler{
StatusCode: 202,
ResponseBody: string(expectedBody),
@@ -528,7 +528,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
statusOut, err := apitools.Decode(body)
statusOut, err := runtime.Decode(body)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}

View File

@@ -28,8 +28,8 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
@@ -205,7 +205,7 @@ func (r *Request) Body(obj interface{}) *Request {
case io.Reader:
r.body = t
default:
data, err := apitools.Encode(obj)
data, err := runtime.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 apitools.Decode(r.body)
return runtime.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 apitools.DecodeInto(r.body, obj)
return runtime.DecodeInto(r.body, obj)
}
// Error returns the error executing the request, nil if no error occurred.

View File

@@ -29,9 +29,8 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/common"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
@@ -39,7 +38,7 @@ import (
func TestDoRequestNewWay(t *testing.T) {
reqBody := "request body"
expectedObj := &api.Service{Port: 12345}
expectedBody, _ := apitools.Encode(expectedObj)
expectedBody, _ := runtime.Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
@@ -72,9 +71,9 @@ func TestDoRequestNewWay(t *testing.T) {
func TestDoRequestNewWayReader(t *testing.T) {
reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
reqBodyExpected, _ := apitools.Encode(reqObj)
reqBodyExpected, _ := runtime.Encode(reqObj)
expectedObj := &api.Service{Port: 12345}
expectedBody, _ := apitools.Encode(expectedObj)
expectedBody, _ := runtime.Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
@@ -109,9 +108,9 @@ func TestDoRequestNewWayReader(t *testing.T) {
func TestDoRequestNewWayObj(t *testing.T) {
reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
reqBodyExpected, _ := apitools.Encode(reqObj)
reqBodyExpected, _ := runtime.Encode(reqObj)
expectedObj := &api.Service{Port: 12345}
expectedBody, _ := apitools.Encode(expectedObj)
expectedBody, _ := runtime.Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
@@ -145,7 +144,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
func TestDoRequestNewWayFile(t *testing.T) {
reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
reqBodyExpected, err := apitools.Encode(reqObj)
reqBodyExpected, err := runtime.Encode(reqObj)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -161,7 +160,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
}
expectedObj := &api.Service{Port: 12345}
expectedBody, _ := apitools.Encode(expectedObj)
expectedBody, _ := runtime.Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
@@ -296,7 +295,7 @@ func TestPolling(t *testing.T) {
callNumber := 0
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
data, err := apitools.Encode(objects[callNumber])
data, err := runtime.Encode(objects[callNumber])
if err != nil {
t.Errorf("Unexpected encode error")
}
@@ -402,7 +401,7 @@ func TestWatch(t *testing.T) {
encoder := json.NewEncoder(w)
for _, item := range table {
encoder.Encode(&api.WatchEvent{item.t, common.Object{item.obj}})
encoder.Encode(&api.WatchEvent{item.t, runtime.Object{item.obj}})
flusher.Flush()
}
}))