Skip to content

Commit

Permalink
Combine pkg/apitools and pkg/api/common and call the result pkg/runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
lavalamp committed Sep 2, 2014
1 parent 099c8fd commit a63966e
Show file tree
Hide file tree
Showing 44 changed files with 218 additions and 237 deletions.
10 changes: 5 additions & 5 deletions cmd/kubecfg/kubecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions pkg/api/common/doc.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/api/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
22 changes: 11 additions & 11 deletions pkg/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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"}`)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
10 changes: 5 additions & 5 deletions pkg/apiserver/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/apiserver/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/cache/reflector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand Down
Loading

0 comments on commit a63966e

Please sign in to comment.