diff --git a/cmd/kubecfg/kubecfg.go b/cmd/kubecfg/kubecfg.go index 181904ab16..ad36985ea8 100644 --- a/cmd/kubecfg/kubecfg.go +++ b/cmd/kubecfg/kubecfg.go @@ -29,9 +29,9 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubecfg" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/version" verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag" @@ -238,7 +238,7 @@ func executeAPIRequest(method string, c *client.Client) bool { if err != nil { glog.Fatalf("error obtaining resource version for update: %v", err) } - jsonBase, err := apitools.FindJSONBase(obj) + jsonBase, err := runtime.FindJSONBase(obj) if err != nil { glog.Fatalf("error finding json base for update: %v", err) } @@ -258,16 +258,16 @@ func executeAPIRequest(method string, c *client.Client) bool { if setBody { if version != 0 { data := readConfig(storage) - obj, err := apitools.Decode(data) + obj, err := runtime.Decode(data) if err != nil { glog.Fatalf("error setting resource version: %v", err) } - jsonBase, err := apitools.FindJSONBase(obj) + jsonBase, err := runtime.FindJSONBase(obj) if err != nil { glog.Fatalf("error setting resource version: %v", err) } jsonBase.SetResourceVersion(version) - data, err = apitools.Encode(obj) + data, err = runtime.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 beb1027ff7..2747dc46cf 100644 --- a/examples/examples_test.go +++ b/examples/examples_test.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/golang/glog" ) @@ -103,7 +103,7 @@ func TestApiExamples(t *testing.T) { return } tested += 1 - if err := apitools.DecodeInto(data, expectedType); err != nil { + if err := runtime.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 := apitools.DecodeInto(data, expectedType); err != nil { + if err := runtime.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 := apitools.DecodeInto([]byte(json), expectedType); err != nil { + if err := runtime.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 := apitools.Encode(expectedType) + encoded, err := runtime.Encode(expectedType) if err != nil { t.Errorf("Could not encode object: %v", err) continue diff --git a/pkg/api/common/doc.go b/pkg/api/common/doc.go deleted file mode 100644 index 9464773ada..0000000000 --- a/pkg/api/common/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -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 common provides types useful for all versions of any object -// that conforms to the kubernetes API object expectations. -package common diff --git a/pkg/api/register.go b/pkg/api/register.go index 42e3a8c63e..2b62442e32 100644 --- a/pkg/api/register.go +++ b/pkg/api/register.go @@ -17,11 +17,11 @@ limitations under the License. package api import ( - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" ) func init() { - apitools.AddKnownTypes("", + runtime.AddKnownTypes("", PodList{}, Pod{}, ReplicationControllerList{}, diff --git a/pkg/api/serialization_test.go b/pkg/api/serialization_test.go index 37d723a29d..985b595272 100644 --- a/pkg/api/serialization_test.go +++ b/pkg/api/serialization_test.go @@ -25,7 +25,7 @@ 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/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/fsouza/go-dockerclient" "github.com/google/gofuzz" @@ -108,20 +108,20 @@ func objDiff(a, b interface{}) string { func runTest(t *testing.T, source interface{}) { name := reflect.TypeOf(source).Elem().Name() apiObjectFuzzer.Fuzz(source) - j, err := apitools.FindJSONBase(source) + j, err := runtime.FindJSONBase(source) if err != nil { t.Fatalf("Unexpected error %v for %#v", err, source) } j.SetKind("") j.SetAPIVersion("") - data, err := apitools.Encode(source) + data, err := runtime.Encode(source) if err != nil { t.Errorf("%v: %v (%#v)", name, err, source) return } - obj2, err := apitools.Decode(data) + obj2, err := runtime.Decode(data) if err != nil { t.Errorf("%v: %v", name, err) return @@ -132,7 +132,7 @@ func runTest(t *testing.T, source interface{}) { } } obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface() - err = apitools.DecodeInto(data, obj3) + err = runtime.DecodeInto(data, obj3) if err != nil { t.Errorf("2: %v: %v", name, err) return @@ -174,8 +174,8 @@ func TestEncode_NonPtr(t *testing.T) { Labels: map[string]string{"name": "foo"}, } obj := interface{}(pod) - data, err := apitools.Encode(obj) - obj2, err2 := apitools.Decode(data) + data, err := runtime.Encode(obj) + obj2, err2 := runtime.Decode(data) if err != nil || err2 != nil { t.Fatalf("Failure: '%v' '%v'", err, err2) } @@ -192,8 +192,8 @@ func TestEncode_Ptr(t *testing.T) { Labels: map[string]string{"name": "foo"}, } obj := interface{}(pod) - data, err := apitools.Encode(obj) - obj2, err2 := apitools.Decode(data) + data, err := runtime.Encode(obj) + obj2, err2 := runtime.Decode(data) if err != nil || err2 != nil { t.Fatalf("Failure: '%v' '%v'", err, err2) } @@ -207,11 +207,11 @@ func TestEncode_Ptr(t *testing.T) { func TestBadJSONRejection(t *testing.T) { badJSONMissingKind := []byte(`{ }`) - if _, err := apitools.Decode(badJSONMissingKind); err == nil { + if _, err := runtime.Decode(badJSONMissingKind); err == nil { t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind) } badJSONUnknownType := []byte(`{"kind": "bar"}`) - if _, err1 := apitools.Decode(badJSONUnknownType); err1 == nil { + if _, err1 := runtime.Decode(badJSONUnknownType); err1 == nil { t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType) } /*badJSONKindMismatch := []byte(`{"kind": "Pod"}`) diff --git a/pkg/api/types.go b/pkg/api/types.go index a85aaac5e0..1ef0f4028a 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -17,7 +17,7 @@ limitations under the License. package api import ( - "github.com/GoogleCloudPlatform/kubernetes/pkg/api/common" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/fsouza/go-dockerclient" @@ -522,5 +522,5 @@ type WatchEvent struct { // For added or modified objects, this is the new object; for deleted objects, // it's the state of the object immediately prior to its deletion. - Object common.Object + Object runtime.Object } diff --git a/pkg/api/v1beta1/conversion.go b/pkg/api/v1beta1/conversion.go index 8b9ba560c3..20c42e999a 100644 --- a/pkg/api/v1beta1/conversion.go +++ b/pkg/api/v1beta1/conversion.go @@ -19,14 +19,14 @@ package v1beta1 import ( // Alias this so it can be easily changed when we cut the next version. newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" ) func init() { // Shortcut for sub-conversions. TODO: This should possibly be refactored // such that this convert function is passed to each conversion func. - Convert := apitools.Convert - apitools.AddConversionFuncs( + Convert := runtime.Convert + runtime.AddConversionFuncs( // EnvVar's Key is deprecated in favor of Name. func(in *newer.EnvVar, out *EnvVar) error { out.Value = in.Value diff --git a/pkg/api/v1beta1/conversion_test.go b/pkg/api/v1beta1/conversion_test.go index f202735c19..8a2f3b85fe 100644 --- a/pkg/api/v1beta1/conversion_test.go +++ b/pkg/api/v1beta1/conversion_test.go @@ -22,10 +22,10 @@ import ( newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" ) -var Convert = apitools.Convert +var Convert = runtime.Convert func TestEnvConversion(t *testing.T) { nonCanonical := []v1beta1.EnvVar{ diff --git a/pkg/api/v1beta1/register.go b/pkg/api/v1beta1/register.go index 1d4dae99de..ae3f2be40c 100644 --- a/pkg/api/v1beta1/register.go +++ b/pkg/api/v1beta1/register.go @@ -17,11 +17,11 @@ limitations under the License. package v1beta1 import ( - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" ) func init() { - apitools.AddKnownTypes("v1beta1", + runtime.AddKnownTypes("v1beta1", PodList{}, Pod{}, ReplicationControllerList{}, diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index 0812acefae..fb0cfff287 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -17,7 +17,7 @@ limitations under the License. package v1beta1 import ( - "github.com/GoogleCloudPlatform/kubernetes/pkg/api/common" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/GoogleCloudPlatform/kubernetes/third_party/docker-api-structs" @@ -522,5 +522,5 @@ type WatchEvent struct { // For added or modified objects, this is the new object; for deleted objects, // it's the state of the object immediately prior to its deletion. - Object common.Object + Object runtime.Object } diff --git a/pkg/apiserver/apiserver_test.go b/pkg/apiserver/apiserver_test.go index 35ef4a1d0c..5d6789bf74 100644 --- a/pkg/apiserver/apiserver_test.go +++ b/pkg/apiserver/apiserver_test.go @@ -31,8 +31,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/version" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" ) @@ -41,11 +41,11 @@ func convert(obj interface{}) (interface{}, error) { return obj, nil } -var codec = apitools.Codec +var codec = runtime.Codec func init() { - apitools.AddKnownTypes("", Simple{}, SimpleList{}) - apitools.AddKnownTypes("v1beta1", Simple{}, SimpleList{}) + runtime.AddKnownTypes("", Simple{}, SimpleList{}) + runtime.AddKnownTypes("v1beta1", Simple{}, SimpleList{}) } type Simple struct { @@ -697,7 +697,7 @@ func TestWriteJSONDecodeError(t *testing.T) { type T struct { Value string } - writeJSON(http.StatusOK, apitools.Codec, &T{"Undecodable"}, w) + writeJSON(http.StatusOK, runtime.Codec, &T{"Undecodable"}, w) })) status := expectApiStatus(t, "GET", server.URL, nil, http.StatusInternalServerError) if status.Reason != api.StatusReasonUnknown { diff --git a/pkg/apiserver/watch.go b/pkg/apiserver/watch.go index 4e5422cc48..1a0907778f 100644 --- a/pkg/apiserver/watch.go +++ b/pkg/apiserver/watch.go @@ -24,9 +24,9 @@ import ( "code.google.com/p/go.net/websocket" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/api/common" "github.com/GoogleCloudPlatform/kubernetes/pkg/httplog" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" ) @@ -113,7 +113,7 @@ func (w *WatchServer) HandleWS(ws *websocket.Conn) { } err := websocket.JSON.Send(ws, &api.WatchEvent{ Type: event.Type, - Object: common.Object{event.Object}, + Object: runtime.Object{event.Object}, }) if err != nil { // Client disconnect. @@ -160,7 +160,7 @@ func (self *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { } err := encoder.Encode(&api.WatchEvent{ Type: event.Type, - Object: common.Object{event.Object}, + Object: runtime.Object{event.Object}, }) if err != nil { // Client disconnect. diff --git a/pkg/client/cache/reflector.go b/pkg/client/cache/reflector.go index 81ab014c06..31a774410f 100644 --- a/pkg/client/cache/reflector.go +++ b/pkg/client/cache/reflector.go @@ -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 diff --git a/pkg/client/client.go b/pkg/client/client.go index d848cafa4e..338bb5eb16 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -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 } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index c4934e519e..9150e89177 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -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) } diff --git a/pkg/client/request.go b/pkg/client/request.go index a692a59ea3..2aceb7ae47 100644 --- a/pkg/client/request.go +++ b/pkg/client/request.go @@ -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. diff --git a/pkg/client/request_test.go b/pkg/client/request_test.go index 0d3d8e256e..904706bc09 100644 --- a/pkg/client/request_test.go +++ b/pkg/client/request_test.go @@ -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() } })) diff --git a/pkg/controller/replication_controller_test.go b/pkg/controller/replication_controller_test.go index 96143c6e9f..028a0745e1 100644 --- a/pkg/controller/replication_controller_test.go +++ b/pkg/controller/replication_controller_test.go @@ -27,9 +27,9 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "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" @@ -109,7 +109,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec } func TestSyncReplicationControllerDoesNothing(t *testing.T) { - body, _ := apitools.Encode(newPodList(2)) + body, _ := runtime.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, _ := apitools.Encode(newPodList(2)) + body, _ := runtime.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, _ := apitools.Encode(newPodList(0)) + body, _ := runtime.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, _ := apitools.Encode(api.Pod{}) + body, _ := runtime.Encode(api.Pod{}) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(body), @@ -292,7 +292,7 @@ func TestSyncronize(t *testing.T) { } fakeControllerHandler := util.FakeHandler{ StatusCode: 200, - ResponseBody: apitools.EncodeOrDie(&api.ReplicationControllerList{ + ResponseBody: runtime.EncodeOrDie(&api.ReplicationControllerList{ Items: []api.ReplicationController{ controllerSpec1, controllerSpec2, diff --git a/pkg/kubecfg/parse.go b/pkg/kubecfg/parse.go index f363fe5c26..8069d9c1ce 100644 --- a/pkg/kubecfg/parse.go +++ b/pkg/kubecfg/parse.go @@ -20,7 +20,7 @@ import ( "fmt" "reflect" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" ) type Parser struct { @@ -44,11 +44,11 @@ func (p *Parser) ToWireFormat(data []byte, storage string) ([]byte, error) { } obj := reflect.New(prototypeType).Interface() - err := apitools.DecodeInto(data, obj) + err := runtime.DecodeInto(data, obj) if err != nil { return nil, err } - return apitools.Encode(obj) + return runtime.Encode(obj) } func (p *Parser) SupportedWireStorage() []string { diff --git a/pkg/kubecfg/parse_test.go b/pkg/kubecfg/parse_test.go index 790493a45a..99e7f907e2 100644 --- a/pkg/kubecfg/parse_test.go +++ b/pkg/kubecfg/parse_test.go @@ -20,7 +20,7 @@ import ( "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "gopkg.in/v1/yaml" ) @@ -33,7 +33,7 @@ func TestParseBadStorage(t *testing.T) { } func DoParseTest(t *testing.T, storage string, obj interface{}, p *Parser) { - jsonData, _ := apitools.Encode(obj) + jsonData, _ := runtime.Encode(obj) yamlData, _ := yaml.Marshal(obj) t.Logf("Intermediate yaml:\n%v\n", string(yamlData)) t.Logf("Intermediate json:\n%v\n", string(jsonData)) @@ -120,8 +120,8 @@ type TestParseType struct { } func TestParseCustomType(t *testing.T) { - apitools.AddKnownTypes("", TestParseType{}) - apitools.AddKnownTypes("v1beta1", TestParseType{}) + runtime.AddKnownTypes("", TestParseType{}) + runtime.AddKnownTypes("v1beta1", TestParseType{}) parser := NewParser(map[string]interface{}{ "custom": TestParseType{}, }) diff --git a/pkg/kubecfg/proxy_server.go b/pkg/kubecfg/proxy_server.go index a9e03a2f5b..03a2dcdcea 100644 --- a/pkg/kubecfg/proxy_server.go +++ b/pkg/kubecfg/proxy_server.go @@ -21,8 +21,8 @@ import ( "net/http" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" ) // ProxyServer is a http.Handler which proxies Kubernetes APIs to remote API server. @@ -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, _ := apitools.Encode(api.Status{ + data, _ := runtime.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 3f4e06e919..de2f0dcabb 100644 --- a/pkg/kubecfg/resource_printer.go +++ b/pkg/kubecfg/resource_printer.go @@ -26,8 +26,8 @@ import ( "text/template" "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/golang/glog" "gopkg.in/v1/yaml" ) @@ -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 := apitools.Encode(obj) + data, err := runtime.Encode(obj) if err != nil { return err } @@ -259,7 +259,7 @@ func (h *HumanReadablePrinter) Print(data []byte, output io.Writer) error { return fmt.Errorf("unexpected object with no 'kind' field: %s", data) } - obj, err := apitools.Decode(data) + obj, err := runtime.Decode(data) if err != nil { return err } @@ -291,7 +291,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 := apitools.Decode(data) + obj, err := runtime.Decode(data) if err != nil { return err } diff --git a/pkg/kubecfg/resource_printer_test.go b/pkg/kubecfg/resource_printer_test.go index 4a9b3942b3..03b7cc2375 100644 --- a/pkg/kubecfg/resource_printer_test.go +++ b/pkg/kubecfg/resource_printer_test.go @@ -25,7 +25,7 @@ import ( "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "gopkg.in/v1/yaml" ) @@ -96,7 +96,7 @@ func TestIdentityPrinter(t *testing.T) { } buff.Reset() printer.PrintObj(obj, buff) - objOut, err := apitools.Decode([]byte(buff.String())) + objOut, err := runtime.Decode([]byte(buff.String())) if err != nil { t.Errorf("Unexpeted error: %#v", err) } diff --git a/pkg/kubelet/config/etcd_test.go b/pkg/kubelet/config/etcd_test.go index 482527941e..629a626617 100644 --- a/pkg/kubelet/config/etcd_test.go +++ b/pkg/kubelet/config/etcd_test.go @@ -22,8 +22,8 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/coreos/go-etcd/etcd" ) @@ -36,7 +36,7 @@ func TestGetEtcdData(t *testing.T) { fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ - Value: apitools.EncodeOrDie(&api.ContainerManifestList{ + Value: runtime.EncodeOrDie(&api.ContainerManifestList{ Items: []api.ContainerManifest{{ID: "foo"}}, }), ModifiedIndex: 1, @@ -79,7 +79,7 @@ func TestGetEtcd(t *testing.T) { fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ - Value: apitools.EncodeOrDie(&api.ContainerManifestList{ + Value: runtime.EncodeOrDie(&api.ContainerManifestList{ Items: []api.ContainerManifest{manifest}, }), ModifiedIndex: 1, @@ -113,7 +113,7 @@ func TestWatchEtcd(t *testing.T) { fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ - Value: apitools.EncodeOrDie(&api.ContainerManifestList{}), + Value: runtime.EncodeOrDie(&api.ContainerManifestList{}), ModifiedIndex: 2, }, }, diff --git a/pkg/master/master.go b/pkg/master/master.go index 394b726238..8f802108b4 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -22,7 +22,6 @@ import ( _ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/binding" @@ -32,6 +31,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/service" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" servicecontroller "github.com/GoogleCloudPlatform/kubernetes/pkg/service" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" @@ -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, apitools.Codec + return storage, runtime.Codec } diff --git a/pkg/proxy/config/etcd.go b/pkg/proxy/config/etcd.go index 2c239842a4..1e604cbed6 100644 --- a/pkg/proxy/config/etcd.go +++ b/pkg/proxy/config/etcd.go @@ -39,7 +39,7 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/coreos/go-etcd/etcd" @@ -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 = apitools.DecodeInto([]byte(node.Value), &svc) + err = runtime.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 = apitools.DecodeInto([]byte(response.Node.Value), &e) + err = runtime.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 := apitools.DecodeInto([]byte(response.Node.Value), &svc) + err := runtime.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 := apitools.DecodeInto([]byte(response.Node.Value), &endpoints) + err := runtime.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/storage_test.go b/pkg/registry/binding/storage_test.go index 78f374cb54..6dfe59721d 100644 --- a/pkg/registry/binding/storage_test.go +++ b/pkg/registry/binding/storage_test.go @@ -24,8 +24,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" ) func TestNewBindingStorage(t *testing.T) { @@ -38,12 +38,12 @@ func TestNewBindingStorage(t *testing.T) { PodID: "foo", Host: "bar", } - body, err := apitools.Encode(binding) + body, err := runtime.Encode(binding) if err != nil { t.Fatalf("Unexpected encode error %v", err) } obj := b.New() - err = apitools.DecodeInto(body, obj) + err = runtime.DecodeInto(body, obj) if err != nil { t.Fatalf("Unexpected error %v", err) } diff --git a/pkg/registry/controller/storage_test.go b/pkg/registry/controller/storage_test.go index 4cdd146a4f..6bd157e333 100644 --- a/pkg/registry/controller/storage_test.go +++ b/pkg/registry/controller/storage_test.go @@ -26,9 +26,9 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" ) func TestListControllersError(t *testing.T) { @@ -112,13 +112,13 @@ func TestControllerDecode(t *testing.T) { ID: "foo", }, } - body, err := apitools.Encode(controller) + body, err := runtime.Encode(controller) if err != nil { t.Errorf("unexpected error: %v", err) } controllerOut := storage.New() - if err := apitools.DecodeInto(body, controllerOut); err != nil { + if err := runtime.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 be808b14b6..1be8233b9c 100644 --- a/pkg/registry/etcd/etcd.go +++ b/pkg/registry/etcd/etcd.go @@ -21,9 +21,9 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/constraint" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" @@ -45,8 +45,8 @@ func NewRegistry(client tools.EtcdClient) *Registry { registry := &Registry{ EtcdHelper: tools.EtcdHelper{ client, - apitools.Codec, - apitools.ResourceVersioner, + runtime.Codec, + runtime.ResourceVersioner, }, } registry.manifestFactory = &BasicManifestFactory{ diff --git a/pkg/registry/etcd/etcd_test.go b/pkg/registry/etcd/etcd_test.go index f62c07830c..b6951ed969 100644 --- a/pkg/registry/etcd/etcd_test.go +++ b/pkg/registry/etcd/etcd_test.go @@ -23,9 +23,9 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/coreos/go-etcd/etcd" @@ -41,7 +41,7 @@ func NewTestEtcdRegistry(client tools.EtcdClient) *Registry { func TestEtcdGetPod(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) - fakeClient.Set("/registry/pods/foo", apitools.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0) + fakeClient.Set("/registry/pods/foo", runtime.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) pod, err := registry.GetPod("foo") if err != nil { @@ -77,7 +77,7 @@ func TestEtcdCreatePod(t *testing.T) { }, E: tools.EtcdErrorNotFound, } - fakeClient.Set("/registry/hosts/machine/kubelet", apitools.EncodeOrDie(&api.ContainerManifestList{}), 0) + fakeClient.Set("/registry/hosts/machine/kubelet", runtime.EncodeOrDie(&api.ContainerManifestList{}), 0) registry := NewTestEtcdRegistry(fakeClient) err := registry.CreatePod(api.Pod{ JSONBase: api.JSONBase{ @@ -108,7 +108,7 @@ func TestEtcdCreatePod(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var pod api.Pod - err = apitools.DecodeInto([]byte(resp.Node.Value), &pod) + err = runtime.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 = apitools.DecodeInto([]byte(resp.Node.Value), &manifests) + err = runtime.DecodeInto([]byte(resp.Node.Value), &manifests) if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" { t.Errorf("Unexpected manifest list: %#v", manifests) } @@ -133,7 +133,7 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) { fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ - Value: apitools.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), + Value: runtime.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), }, }, E: nil, @@ -235,7 +235,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var pod api.Pod - err = apitools.DecodeInto([]byte(resp.Node.Value), &pod) + err = runtime.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 = apitools.DecodeInto([]byte(resp.Node.Value), &manifests) + err = runtime.DecodeInto([]byte(resp.Node.Value), &manifests) if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" { t.Errorf("Unexpected manifest list: %#v", manifests) } @@ -264,7 +264,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { }, E: tools.EtcdErrorNotFound, } - fakeClient.Set("/registry/hosts/machine/kubelet", apitools.EncodeOrDie(api.ContainerManifestList{ + fakeClient.Set("/registry/hosts/machine/kubelet", runtime.EncodeOrDie(api.ContainerManifestList{ Items: []api.ContainerManifest{ {ID: "bar"}, }, @@ -300,7 +300,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var pod api.Pod - err = apitools.DecodeInto([]byte(resp.Node.Value), &pod) + err = runtime.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 = apitools.DecodeInto([]byte(resp.Node.Value), &manifests) + err = runtime.DecodeInto([]byte(resp.Node.Value), &manifests) if len(manifests.Items) != 2 || manifests.Items[1].ID != "foo" { t.Errorf("Unexpected manifest list: %#v", manifests) } @@ -325,11 +325,11 @@ func TestEtcdDeletePod(t *testing.T) { fakeClient.TestIndex = true key := "/registry/pods/foo" - fakeClient.Set(key, apitools.EncodeOrDie(api.Pod{ + fakeClient.Set(key, runtime.EncodeOrDie(api.Pod{ JSONBase: api.JSONBase{ID: "foo"}, DesiredState: api.PodState{Host: "machine"}, }), 0) - fakeClient.Set("/registry/hosts/machine/kubelet", apitools.EncodeOrDie(&api.ContainerManifestList{ + fakeClient.Set("/registry/hosts/machine/kubelet", runtime.EncodeOrDie(&api.ContainerManifestList{ Items: []api.ContainerManifest{ {ID: "foo"}, }, @@ -350,7 +350,7 @@ func TestEtcdDeletePod(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var manifests api.ContainerManifestList - apitools.DecodeInto([]byte(response.Node.Value), &manifests) + runtime.DecodeInto([]byte(response.Node.Value), &manifests) if len(manifests.Items) != 0 { t.Errorf("Unexpected container set: %s, expected empty", response.Node.Value) } @@ -361,11 +361,11 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) { fakeClient.TestIndex = true key := "/registry/pods/foo" - fakeClient.Set(key, apitools.EncodeOrDie(api.Pod{ + fakeClient.Set(key, runtime.EncodeOrDie(api.Pod{ JSONBase: api.JSONBase{ID: "foo"}, DesiredState: api.PodState{Host: "machine"}, }), 0) - fakeClient.Set("/registry/hosts/machine/kubelet", apitools.EncodeOrDie(&api.ContainerManifestList{ + fakeClient.Set("/registry/hosts/machine/kubelet", runtime.EncodeOrDie(&api.ContainerManifestList{ Items: []api.ContainerManifest{ {ID: "foo"}, {ID: "bar"}, @@ -388,7 +388,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var manifests api.ContainerManifestList - apitools.DecodeInto([]byte(response.Node.Value), &manifests) + runtime.DecodeInto([]byte(response.Node.Value), &manifests) if len(manifests.Items) != 1 { t.Fatalf("Unexpected manifest set: %#v, expected empty", manifests) } @@ -445,13 +445,13 @@ func TestEtcdListPods(t *testing.T) { Node: &etcd.Node{ Nodes: []*etcd.Node{ { - Value: apitools.EncodeOrDie(api.Pod{ + Value: runtime.EncodeOrDie(api.Pod{ JSONBase: api.JSONBase{ID: "foo"}, DesiredState: api.PodState{Host: "machine"}, }), }, { - Value: apitools.EncodeOrDie(api.Pod{ + Value: runtime.EncodeOrDie(api.Pod{ JSONBase: api.JSONBase{ID: "bar"}, DesiredState: api.PodState{Host: "machine"}, }), @@ -520,10 +520,10 @@ func TestEtcdListControllers(t *testing.T) { Node: &etcd.Node{ Nodes: []*etcd.Node{ { - Value: apitools.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), + Value: runtime.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), }, { - Value: apitools.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "bar"}}), + Value: runtime.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "bar"}}), }, }, }, @@ -543,7 +543,7 @@ func TestEtcdListControllers(t *testing.T) { func TestEtcdGetController(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) - fakeClient.Set("/registry/controllers/foo", apitools.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0) + fakeClient.Set("/registry/controllers/foo", runtime.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) ctrl, err := registry.GetController("foo") if err != nil { @@ -607,7 +607,7 @@ func TestEtcdCreateController(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var ctrl api.ReplicationController - err = apitools.DecodeInto([]byte(resp.Node.Value), &ctrl) + err = runtime.DecodeInto([]byte(resp.Node.Value), &ctrl) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -619,7 +619,7 @@ func TestEtcdCreateController(t *testing.T) { func TestEtcdCreateControllerAlreadyExisting(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) - fakeClient.Set("/registry/controllers/foo", apitools.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0) + fakeClient.Set("/registry/controllers/foo", runtime.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) err := registry.CreateController(api.ReplicationController{ @@ -636,7 +636,7 @@ func TestEtcdUpdateController(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true - resp, _ := fakeClient.Set("/registry/controllers/foo", apitools.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0) + resp, _ := fakeClient.Set("/registry/controllers/foo", runtime.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) err := registry.UpdateController(api.ReplicationController{ JSONBase: api.JSONBase{ID: "foo", ResourceVersion: resp.Node.ModifiedIndex}, @@ -662,10 +662,10 @@ func TestEtcdListServices(t *testing.T) { Node: &etcd.Node{ Nodes: []*etcd.Node{ { - Value: apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), + Value: runtime.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), }, { - Value: apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "bar"}}), + Value: runtime.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "bar"}}), }, }, }, @@ -699,7 +699,7 @@ func TestEtcdCreateService(t *testing.T) { } var service api.Service - err = apitools.DecodeInto([]byte(resp.Node.Value), &service) + err = runtime.DecodeInto([]byte(resp.Node.Value), &service) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -711,7 +711,7 @@ func TestEtcdCreateService(t *testing.T) { func TestEtcdCreateServiceAlreadyExisting(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) - fakeClient.Set("/registry/services/specs/foo", apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0) + fakeClient.Set("/registry/services/specs/foo", runtime.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) err := registry.CreateService(api.Service{ JSONBase: api.JSONBase{ID: "foo"}, @@ -723,7 +723,7 @@ func TestEtcdCreateServiceAlreadyExisting(t *testing.T) { func TestEtcdGetService(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) - fakeClient.Set("/registry/services/specs/foo", apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0) + fakeClient.Set("/registry/services/specs/foo", runtime.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) service, err := registry.GetService("foo") if err != nil { @@ -775,7 +775,7 @@ func TestEtcdUpdateService(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true - resp, _ := fakeClient.Set("/registry/services/specs/foo", apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0) + resp, _ := fakeClient.Set("/registry/services/specs/foo", runtime.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) testService := api.Service{ JSONBase: api.JSONBase{ID: "foo", ResourceVersion: resp.Node.ModifiedIndex}, @@ -812,7 +812,7 @@ func TestEtcdGetEndpoints(t *testing.T) { Endpoints: []string{"127.0.0.1:34855"}, } - fakeClient.Set("/registry/services/endpoints/foo", apitools.EncodeOrDie(endpoints), 0) + fakeClient.Set("/registry/services/endpoints/foo", runtime.EncodeOrDie(endpoints), 0) got, err := registry.GetEndpoints("foo") if err != nil { @@ -833,7 +833,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) { Endpoints: []string{"baz", "bar"}, } - fakeClient.Set("/registry/services/endpoints/foo", apitools.EncodeOrDie(api.Endpoints{}), 0) + fakeClient.Set("/registry/services/endpoints/foo", runtime.EncodeOrDie(api.Endpoints{}), 0) err := registry.UpdateEndpoints(endpoints) if err != nil { @@ -845,7 +845,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) { t.Fatalf("Unexpected error %v", err) } var endpointsOut api.Endpoints - err = apitools.DecodeInto([]byte(response.Node.Value), &endpointsOut) + err = runtime.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/storage_test.go b/pkg/registry/pod/storage_test.go index 2a6f922bb5..7268306788 100644 --- a/pkg/registry/pod/storage_test.go +++ b/pkg/registry/pod/storage_test.go @@ -24,10 +24,10 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/fsouza/go-dockerclient" ) @@ -178,13 +178,13 @@ func TestPodDecode(t *testing.T) { ID: "foo", }, } - body, err := apitools.Encode(expected) + body, err := runtime.Encode(expected) if err != nil { t.Errorf("unexpected error: %v", err) } actual := storage.New() - if err := apitools.DecodeInto(body, actual); err != nil { + if err := runtime.DecodeInto(body, actual); err != nil { t.Errorf("unexpected error: %v", err) } diff --git a/pkg/apitools/doc.go b/pkg/runtime/doc.go similarity index 83% rename from pkg/apitools/doc.go rename to pkg/runtime/doc.go index a0550549ef..18c930c8ff 100644 --- a/pkg/apitools/doc.go +++ b/pkg/runtime/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package apitools includes helper functions for working with API objects +// Package runtime includes helper functions for working with API objects // that follow the kubernetes API object conventions, which are: // // 0. Your API objects have a common metadata struct member, JSONBase. @@ -33,10 +33,12 @@ limitations under the License. // 7. All of your serializations and deserializations are handled in a // centralized place. // -// Package apitools provides a conversion helper to make 5 easy, and the +// Package runtime provides a conversion helper to make 5 easy, and the // Encode/Decode/DecodeInto trio to accomplish 7. You can also register // additional "codecs" which use a version of your choice. It's -// recommended that you register your types with apitools in your +// recommended that you register your types with runtime in your // package's init function. // -package apitools +// As a bonus, a few common types useful from all api objects and versions +// are provided in types.go. +package runtime diff --git a/pkg/apitools/helper.go b/pkg/runtime/helper.go similarity index 99% rename from pkg/apitools/helper.go rename to pkg/runtime/helper.go index ddd6a58d6b..c94a5a6ce4 100644 --- a/pkg/apitools/helper.go +++ b/pkg/runtime/helper.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package apitools +package runtime import ( "fmt" diff --git a/pkg/apitools/helper_test.go b/pkg/runtime/helper_test.go similarity index 84% rename from pkg/apitools/helper_test.go rename to pkg/runtime/helper_test.go index 91912349f2..b2bcc9f6bf 100644 --- a/pkg/apitools/helper_test.go +++ b/pkg/runtime/helper_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package apitools_test +package runtime_test import ( "reflect" @@ -22,7 +22,7 @@ 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/runtime" ) func TestEncode_NonPtr(t *testing.T) { @@ -30,8 +30,8 @@ func TestEncode_NonPtr(t *testing.T) { Labels: map[string]string{"name": "foo"}, } obj := interface{}(pod) - data, err := apitools.Encode(obj) - obj2, err2 := apitools.Decode(data) + data, err := runtime.Encode(obj) + obj2, err2 := runtime.Decode(data) if err != nil || err2 != nil { t.Fatalf("Failure: '%v' '%v'", err, err2) } @@ -48,8 +48,8 @@ func TestEncode_Ptr(t *testing.T) { Labels: map[string]string{"name": "foo"}, } obj := interface{}(pod) - data, err := apitools.Encode(obj) - obj2, err2 := apitools.Decode(data) + data, err := runtime.Encode(obj) + obj2, err2 := runtime.Decode(data) if err != nil || err2 != nil { t.Fatalf("Failure: '%v' '%v'", err, err2) } @@ -63,11 +63,11 @@ func TestEncode_Ptr(t *testing.T) { func TestBadJSONRejection(t *testing.T) { badJSONMissingKind := []byte(`{ }`) - if _, err := apitools.Decode(badJSONMissingKind); err == nil { + if _, err := runtime.Decode(badJSONMissingKind); err == nil { t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind) } badJSONUnknownType := []byte(`{"kind": "bar"}`) - if _, err1 := apitools.Decode(badJSONUnknownType); err1 == nil { + if _, err1 := runtime.Decode(badJSONUnknownType); err1 == nil { t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType) } /*badJSONKindMismatch := []byte(`{"kind": "Pod"}`) diff --git a/pkg/apitools/jsonbase.go b/pkg/runtime/jsonbase.go similarity index 99% rename from pkg/apitools/jsonbase.go rename to pkg/runtime/jsonbase.go index 1577cea360..bcd6fe0a50 100644 --- a/pkg/apitools/jsonbase.go +++ b/pkg/runtime/jsonbase.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package apitools +package runtime import ( "fmt" diff --git a/pkg/apitools/jsonbase_test.go b/pkg/runtime/jsonbase_test.go similarity index 95% rename from pkg/apitools/jsonbase_test.go rename to pkg/runtime/jsonbase_test.go index e1843a3e10..759cd7611b 100644 --- a/pkg/apitools/jsonbase_test.go +++ b/pkg/runtime/jsonbase_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package apitools +package runtime import ( "reflect" @@ -126,7 +126,7 @@ func TestResourceVersionerOfAPI(t *testing.T) { Object interface{} Expected uint64 }{ - "pointer to api object with version": {&Service{JSONBase: JSONBase{ResourceVersion: 1}}, 1}, + "pointer to api object with version": {&MyAPIObject{JSONBase: JSONBase{ResourceVersion: 1}}, 1}, } for key, testCase := range setCases { if err := versioning.SetResourceVersion(testCase.Object, 5); err != nil { @@ -145,8 +145,8 @@ func TestResourceVersionerOfAPI(t *testing.T) { Object interface{} Expected uint64 }{ - "empty api object": {Service{}, 0}, - "api object with version": {Service{JSONBase: JSONBase{ResourceVersion: 1}}, 1}, + "empty api object": {MyAPIObject{}, 0}, + "api object with version": {MyAPIObject{JSONBase: JSONBase{ResourceVersion: 1}}, 1}, } for key, testCase := range failingSetCases { if err := versioning.SetResourceVersion(testCase.Object, 5); err == nil { diff --git a/pkg/api/common/object.go b/pkg/runtime/object.go similarity index 91% rename from pkg/api/common/object.go rename to pkg/runtime/object.go index 32ad2ed734..84b5323123 100644 --- a/pkg/api/common/object.go +++ b/pkg/runtime/object.go @@ -14,12 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -package common +package runtime import ( "gopkg.in/v1/yaml" - - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" ) // Encode()/Decode() are the canonical way of converting an API object to/from @@ -35,7 +33,7 @@ func (a *Object) UnmarshalJSON(b []byte) error { return nil } - obj, err := apitools.Decode(b) + obj, err := Decode(b) if err != nil { return err } @@ -50,7 +48,7 @@ func (a Object) MarshalJSON() ([]byte, error) { return []byte("null"), nil } - return apitools.Encode(a.Object) + return Encode(a.Object) } // SetYAML implements the yaml.Setter interface. @@ -69,7 +67,7 @@ func (a *Object) SetYAML(tag string, value interface{}) bool { if err != nil { panic("yaml can't reverse its own object") } - obj, err := apitools.Decode(b) + obj, err := Decode(b) if err != nil { return false } @@ -84,7 +82,7 @@ func (a Object) GetYAML() (tag string, value interface{}) { return } // Encode returns JSON, which is conveniently a subset of YAML. - v, err := apitools.Encode(a.Object) + v, err := Encode(a.Object) if err != nil { panic("impossible to encode API object!") } diff --git a/pkg/api/common/object_test.go b/pkg/runtime/object_test.go similarity index 84% rename from pkg/api/common/object_test.go rename to pkg/runtime/object_test.go index a9316c1871..784c956818 100644 --- a/pkg/api/common/object_test.go +++ b/pkg/runtime/object_test.go @@ -14,14 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package common +package runtime import ( "encoding/json" "reflect" "testing" - - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" ) func TestObject(t *testing.T) { @@ -30,8 +28,8 @@ func TestObject(t *testing.T) { Object Object `yaml:"object,omitempty" json:"object,omitempty"` EmptyObject Object `yaml:"emptyObject,omitempty" json:"emptyObject,omitempty"` } - apitools.AddKnownTypes("", EmbeddedTest{}) - apitools.AddKnownTypes("v1beta1", EmbeddedTest{}) + AddKnownTypes("", EmbeddedTest{}) + AddKnownTypes("v1beta1", EmbeddedTest{}) outer := &EmbeddedTest{ JSONBase: JSONBase{ID: "outer"}, @@ -42,14 +40,14 @@ func TestObject(t *testing.T) { }, } - wire, err := apitools.Encode(outer) + wire, err := Encode(outer) if err != nil { t.Fatalf("Unexpected encode error '%v'", err) } t.Logf("Wire format is:\n%v\n", string(wire)) - decoded, err := apitools.Decode(wire) + decoded, err := Decode(wire) if err != nil { t.Fatalf("Unexpected decode error %v", err) } @@ -58,7 +56,7 @@ func TestObject(t *testing.T) { t.Errorf("Expected: %#v but got %#v", e, a) } - // test JSON decoding, too, since apitools.Decode uses yaml unmarshalling. + // test JSON decoding, too, since Decode uses yaml unmarshalling. var decodedViaJSON EmbeddedTest err = json.Unmarshal(wire, &decodedViaJSON) if err != nil { diff --git a/pkg/api/common/types.go b/pkg/runtime/types.go similarity index 91% rename from pkg/api/common/types.go rename to pkg/runtime/types.go index e76e29db27..8e08487e29 100644 --- a/pkg/api/common/types.go +++ b/pkg/runtime/types.go @@ -14,16 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -package common +package runtime import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) +// Note that the types provided in this file are not versioned and are intended to be +// safe to use from within all versions of every API object. + // JSONBase is shared by all top level objects. The proper way to use it is to inline it in your type, // like this: // type MyAwesomeAPIObject struct { -// common.JSONBase `yaml:",inline" json:",inline"` +// runtime.JSONBase `yaml:",inline" json:",inline"` // ... // other fields // } // diff --git a/pkg/tools/decoder_test.go b/pkg/tools/decoder_test.go index eeb14d9a67..fb76e5e455 100644 --- a/pkg/tools/decoder_test.go +++ b/pkg/tools/decoder_test.go @@ -24,8 +24,8 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/api/common" _ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" ) @@ -36,7 +36,7 @@ func TestDecoder(t *testing.T) { expect := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} go func() { - err := encoder.Encode(api.WatchEvent{watch.Added, common.Object{expect}}) + err := encoder.Encode(api.WatchEvent{watch.Added, runtime.Object{expect}}) if 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 132de4b2f7..da9e64c6b9 100644 --- a/pkg/tools/etcd_tools_test.go +++ b/pkg/tools/etcd_tools_test.go @@ -24,8 +24,8 @@ import ( "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/conversion" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/coreos/go-etcd/etcd" ) @@ -41,8 +41,8 @@ type TestResource struct { } var scheme *conversion.Scheme -var codec = apitools.Codec -var versioner = apitools.ResourceVersioner +var codec = runtime.Codec +var versioner = runtime.ResourceVersioner func init() { scheme = conversion.NewScheme() @@ -191,7 +191,7 @@ func TestSetObjWithVersion(t *testing.T) { fakeClient.Data["/some/key"] = EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ - Value: apitools.EncodeOrDie(obj), + Value: runtime.EncodeOrDie(obj), ModifiedIndex: 1, }, }, @@ -236,7 +236,7 @@ func TestAtomicUpdate(t *testing.T) { fakeClient := NewFakeEtcdClient(t) fakeClient.TestIndex = true codec := scheme - helper := EtcdHelper{fakeClient, codec, apitools.NewJSONBaseResourceVersioner()} + helper := EtcdHelper{fakeClient, codec, runtime.NewJSONBaseResourceVersioner()} // Create a new node. fakeClient.ExpectNotFoundGet("/some/key") @@ -290,7 +290,7 @@ func TestAtomicUpdate(t *testing.T) { func TestAtomicUpdateNoChange(t *testing.T) { fakeClient := NewFakeEtcdClient(t) fakeClient.TestIndex = true - helper := EtcdHelper{fakeClient, scheme, apitools.NewJSONBaseResourceVersioner()} + helper := EtcdHelper{fakeClient, scheme, runtime.NewJSONBaseResourceVersioner()} // Create a new node. fakeClient.ExpectNotFoundGet("/some/key") @@ -322,7 +322,7 @@ func TestAtomicUpdate_CreateCollision(t *testing.T) { fakeClient := NewFakeEtcdClient(t) fakeClient.TestIndex = true codec := scheme - helper := EtcdHelper{fakeClient, codec, apitools.NewJSONBaseResourceVersioner()} + helper := EtcdHelper{fakeClient, codec, runtime.NewJSONBaseResourceVersioner()} fakeClient.ExpectNotFoundGet("/some/key") diff --git a/pkg/tools/etcd_tools_watch_test.go b/pkg/tools/etcd_tools_watch_test.go index 59d59493af..73da21ce23 100644 --- a/pkg/tools/etcd_tools_watch_test.go +++ b/pkg/tools/etcd_tools_watch_test.go @@ -23,7 +23,7 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" "github.com/coreos/go-etcd/etcd" ) @@ -48,62 +48,62 @@ func TestWatchInterpretations(t *testing.T) { }{ "create": { actions: []string{"create", "get"}, - nodeValue: apitools.EncodeOrDie(podBar), + nodeValue: runtime.EncodeOrDie(podBar), expectEmit: true, expectType: watch.Added, expectObject: podBar, }, "create but filter blocks": { actions: []string{"create", "get"}, - nodeValue: apitools.EncodeOrDie(podFoo), + nodeValue: runtime.EncodeOrDie(podFoo), expectEmit: false, }, "delete": { actions: []string{"delete"}, - prevNodeValue: apitools.EncodeOrDie(podBar), + prevNodeValue: runtime.EncodeOrDie(podBar), expectEmit: true, expectType: watch.Deleted, expectObject: podBar, }, "delete but filter blocks": { actions: []string{"delete"}, - nodeValue: apitools.EncodeOrDie(podFoo), + nodeValue: runtime.EncodeOrDie(podFoo), expectEmit: false, }, "modify appears to create 1": { actions: []string{"set", "compareAndSwap"}, - nodeValue: apitools.EncodeOrDie(podBar), + nodeValue: runtime.EncodeOrDie(podBar), expectEmit: true, expectType: watch.Added, expectObject: podBar, }, "modify appears to create 2": { actions: []string{"set", "compareAndSwap"}, - prevNodeValue: apitools.EncodeOrDie(podFoo), - nodeValue: apitools.EncodeOrDie(podBar), + prevNodeValue: runtime.EncodeOrDie(podFoo), + nodeValue: runtime.EncodeOrDie(podBar), expectEmit: true, expectType: watch.Added, expectObject: podBar, }, "modify appears to delete": { actions: []string{"set", "compareAndSwap"}, - prevNodeValue: apitools.EncodeOrDie(podBar), - nodeValue: apitools.EncodeOrDie(podFoo), + prevNodeValue: runtime.EncodeOrDie(podBar), + nodeValue: runtime.EncodeOrDie(podFoo), expectEmit: true, expectType: watch.Deleted, expectObject: podBar, // Should return last state that passed the filter! }, "modify modifies": { actions: []string{"set", "compareAndSwap"}, - prevNodeValue: apitools.EncodeOrDie(podBar), - nodeValue: apitools.EncodeOrDie(podBaz), + prevNodeValue: runtime.EncodeOrDie(podBar), + nodeValue: runtime.EncodeOrDie(podBaz), expectEmit: true, expectType: watch.Modified, expectObject: podBaz, }, "modify ignores": { actions: []string{"set", "compareAndSwap"}, - nodeValue: apitools.EncodeOrDie(podFoo), + nodeValue: runtime.EncodeOrDie(podFoo), expectEmit: false, }, } @@ -259,7 +259,7 @@ func TestWatchEtcdState(t *testing.T) { { Action: "create", Node: &etcd.Node{ - Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})), + Value: string(runtime.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})), }, }, }, @@ -273,12 +273,12 @@ func TestWatchEtcdState(t *testing.T) { { Action: "compareAndSwap", Node: &etcd.Node{ - Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})), + Value: string(runtime.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})), CreatedIndex: 1, ModifiedIndex: 2, }, PrevNode: &etcd.Node{ - Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})), + Value: string(runtime.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})), CreatedIndex: 1, ModifiedIndex: 1, }, @@ -295,7 +295,7 @@ func TestWatchEtcdState(t *testing.T) { R: &etcd.Response{ Action: "get", Node: &etcd.Node{ - Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})), + Value: string(runtime.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})), CreatedIndex: 1, ModifiedIndex: 1, }, @@ -308,12 +308,12 @@ func TestWatchEtcdState(t *testing.T) { { Action: "compareAndSwap", Node: &etcd.Node{ - Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})), + Value: string(runtime.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})), CreatedIndex: 1, ModifiedIndex: 2, }, PrevNode: &etcd.Node{ - Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})), + Value: string(runtime.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})), CreatedIndex: 1, ModifiedIndex: 1, }, @@ -370,7 +370,7 @@ func TestWatchFromZeroIndex(t *testing.T) { EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ - Value: apitools.EncodeOrDie(pod), + Value: runtime.EncodeOrDie(pod), CreatedIndex: 1, ModifiedIndex: 1, }, @@ -385,7 +385,7 @@ func TestWatchFromZeroIndex(t *testing.T) { EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ - Value: apitools.EncodeOrDie(pod), + Value: runtime.EncodeOrDie(pod), CreatedIndex: 1, ModifiedIndex: 2, }, @@ -443,13 +443,13 @@ func TestWatchListFromZeroIndex(t *testing.T) { Dir: true, Nodes: etcd.Nodes{ &etcd.Node{ - Value: apitools.EncodeOrDie(pod), + Value: runtime.EncodeOrDie(pod), CreatedIndex: 1, ModifiedIndex: 1, Nodes: etcd.Nodes{}, }, &etcd.Node{ - Value: apitools.EncodeOrDie(pod), + Value: runtime.EncodeOrDie(pod), CreatedIndex: 2, ModifiedIndex: 2, Nodes: etcd.Nodes{}, diff --git a/plugin/pkg/scheduler/factory/factory_test.go b/plugin/pkg/scheduler/factory/factory_test.go index 7de93a0abe..6ff1b50ea9 100644 --- a/plugin/pkg/scheduler/factory/factory_test.go +++ b/plugin/pkg/scheduler/factory/factory_test.go @@ -24,10 +24,10 @@ import ( "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" ) @@ -113,7 +113,7 @@ func TestPollMinions(t *testing.T) { ml := &api.MinionList{Items: item.minions} handler := util.FakeHandler{ StatusCode: 200, - ResponseBody: apitools.EncodeOrDie(ml), + ResponseBody: runtime.EncodeOrDie(ml), T: t, } mux := http.NewServeMux() @@ -140,7 +140,7 @@ func TestDefaultErrorFunc(t *testing.T) { testPod := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} handler := util.FakeHandler{ StatusCode: 200, - ResponseBody: apitools.EncodeOrDie(testPod), + ResponseBody: runtime.EncodeOrDie(testPod), T: t, } mux := http.NewServeMux() @@ -259,7 +259,7 @@ func TestBind(t *testing.T) { t.Errorf("Unexpected error: %v", err) continue } - expectedBody := apitools.EncodeOrDie(item.binding) + expectedBody := runtime.EncodeOrDie(item.binding) handler.ValidateRequest(t, "/api/v1beta1/bindings", "POST", &expectedBody) } } diff --git a/test/integration/etcd_tools_test.go b/test/integration/etcd_tools_test.go index fcfdf68158..b605a0b75e 100644 --- a/test/integration/etcd_tools_test.go +++ b/test/integration/etcd_tools_test.go @@ -22,7 +22,7 @@ import ( "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/apitools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" ) @@ -84,9 +84,9 @@ func TestExtractObj(t *testing.T) { func TestWatch(t *testing.T) { client := newEtcdClient() - helper := tools.EtcdHelper{Client: client, Codec: apitools.Codec, ResourceVersioner: apitools.ResourceVersioner} + helper := tools.EtcdHelper{Client: client, Codec: runtime.Codec, ResourceVersioner: runtime.ResourceVersioner} withEtcdKey(func(key string) { - resp, err := client.Set(key, apitools.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 { t.Fatalf("unexpected error: %v", err) }