Propagate rename; tests pass again.

This commit is contained in:
Daniel Smith 2014-08-31 22:10:49 -07:00
parent 7615c00a9a
commit 099c8fd36f
35 changed files with 183 additions and 151 deletions

View File

@ -29,6 +29,7 @@ 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/util"
@ -237,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 := api.FindJSONBase(obj)
jsonBase, err := apitools.FindJSONBase(obj)
if err != nil {
glog.Fatalf("error finding json base for update: %v", err)
}
@ -257,16 +258,16 @@ func executeAPIRequest(method string, c *client.Client) bool {
if setBody {
if version != 0 {
data := readConfig(storage)
obj, err := api.Decode(data)
obj, err := apitools.Decode(data)
if err != nil {
glog.Fatalf("error setting resource version: %v", err)
}
jsonBase, err := api.FindJSONBase(obj)
jsonBase, err := apitools.FindJSONBase(obj)
if err != nil {
glog.Fatalf("error setting resource version: %v", err)
}
jsonBase.SetResourceVersion(version)
data, err = api.Encode(obj)
data, err = apitools.Encode(obj)
if err != nil {
glog.Fatalf("error setting resource version: %v", err)
}

View File

@ -26,25 +26,27 @@ 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/golang/glog"
)
func validateObject(obj interface{}) (errors []error) {
switch t := obj.(type) {
case *api.ReplicationController:
errors = api.ValidateManifest(&t.DesiredState.PodTemplate.DesiredState.Manifest)
errors = validation.ValidateManifest(&t.DesiredState.PodTemplate.DesiredState.Manifest)
case *api.ReplicationControllerList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Service:
errors = api.ValidateService(t)
errors = validation.ValidateService(t)
case *api.ServiceList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Pod:
errors = api.ValidateManifest(&t.DesiredState.Manifest)
errors = validation.ValidateManifest(&t.DesiredState.Manifest)
case *api.PodList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
@ -101,7 +103,7 @@ func TestApiExamples(t *testing.T) {
return
}
tested += 1
if err := api.DecodeInto(data, expectedType); err != nil {
if err := apitools.DecodeInto(data, expectedType); err != nil {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return
}
@ -135,7 +137,7 @@ func TestExamples(t *testing.T) {
return
}
tested += 1
if err := api.DecodeInto(data, expectedType); err != nil {
if err := apitools.DecodeInto(data, expectedType); err != nil {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return
}
@ -166,14 +168,14 @@ func TestReadme(t *testing.T) {
}
for _, json := range match[1:] {
expectedType := &api.Pod{}
if err := api.DecodeInto([]byte(json), expectedType); err != nil {
if err := apitools.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 := api.Encode(expectedType)
encoded, err := apitools.Encode(expectedType)
if err != nil {
t.Errorf("Could not encode object: %v", err)
continue

View File

@ -31,6 +31,7 @@ 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/version"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
@ -40,11 +41,11 @@ func convert(obj interface{}) (interface{}, error) {
return obj, nil
}
var codec = api.Codec
var codec = apitools.Codec
func init() {
api.AddKnownTypes("", Simple{}, SimpleList{})
api.AddKnownTypes("v1beta1", Simple{}, SimpleList{})
apitools.AddKnownTypes("", Simple{}, SimpleList{})
apitools.AddKnownTypes("v1beta1", Simple{}, SimpleList{})
}
type Simple struct {
@ -696,7 +697,7 @@ func TestWriteJSONDecodeError(t *testing.T) {
type T struct {
Value string
}
writeJSON(http.StatusOK, api.Codec, &T{"Undecodable"}, w)
writeJSON(http.StatusOK, apitools.Codec, &T{"Undecodable"}, w)
}))
status := expectApiStatus(t, "GET", server.URL, nil, http.StatusInternalServerError)
if status.Reason != api.StatusReasonUnknown {

View File

@ -24,6 +24,7 @@ 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/watch"
@ -112,7 +113,7 @@ func (w *WatchServer) HandleWS(ws *websocket.Conn) {
}
err := websocket.JSON.Send(ws, &api.WatchEvent{
Type: event.Type,
Object: api.APIObject{event.Object},
Object: common.Object{event.Object},
})
if err != nil {
// Client disconnect.
@ -159,7 +160,7 @@ func (self *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
err := encoder.Encode(&api.WatchEvent{
Type: event.Type,
Object: api.APIObject{event.Object},
Object: common.Object{event.Object},
})
if err != nil {
// Client disconnect.

View File

@ -20,7 +20,7 @@ import (
"reflect"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"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 := api.FindJSONBase(event.Object)
jsonBase, err := apitools.FindJSONBase(event.Object)
if err != nil {
glog.Errorf("unable to understand watch event %#v", event)
continue

View File

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

View File

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

View File

@ -28,6 +28,7 @@ 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/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
@ -204,7 +205,7 @@ func (r *Request) Body(obj interface{}) *Request {
case io.Reader:
r.body = t
default:
data, err := api.Encode(obj)
data, err := apitools.Encode(obj)
if err != nil {
r.err = err
return r
@ -317,7 +318,7 @@ func (r Result) Get() (interface{}, error) {
if r.err != nil {
return nil, r.err
}
return api.Decode(r.body)
return apitools.Decode(r.body)
}
// Into stores the result into obj, if possible.
@ -325,7 +326,7 @@ func (r Result) Into(obj interface{}) error {
if r.err != nil {
return r.err
}
return api.DecodeInto(r.body, obj)
return apitools.DecodeInto(r.body, obj)
}
// Error returns the error executing the request, nil if no error occurred.

View File

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

View File

@ -27,6 +27,7 @@ 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/tools"
@ -108,7 +109,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
}
func TestSyncReplicationControllerDoesNothing(t *testing.T) {
body, _ := api.Encode(newPodList(2))
body, _ := apitools.Encode(newPodList(2))
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
@ -128,7 +129,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {
}
func TestSyncReplicationControllerDeletes(t *testing.T) {
body, _ := api.Encode(newPodList(2))
body, _ := apitools.Encode(newPodList(2))
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
@ -148,7 +149,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
}
func TestSyncReplicationControllerCreates(t *testing.T) {
body, _ := api.Encode(newPodList(0))
body, _ := apitools.Encode(newPodList(0))
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
@ -168,7 +169,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
}
func TestCreateReplica(t *testing.T) {
body, _ := api.Encode(api.Pod{})
body, _ := apitools.Encode(api.Pod{})
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
@ -291,7 +292,7 @@ func TestSyncronize(t *testing.T) {
}
fakeControllerHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: api.EncodeOrDie(&api.ReplicationControllerList{
ResponseBody: apitools.EncodeOrDie(&api.ReplicationControllerList{
Items: []api.ReplicationController{
controllerSpec1,
controllerSpec2,

View File

@ -20,7 +20,7 @@ import (
"fmt"
"reflect"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
)
type Parser struct {
@ -44,11 +44,11 @@ func (p *Parser) ToWireFormat(data []byte, storage string) ([]byte, error) {
}
obj := reflect.New(prototypeType).Interface()
err := api.DecodeInto(data, obj)
err := apitools.DecodeInto(data, obj)
if err != nil {
return nil, err
}
return api.Encode(obj)
return apitools.Encode(obj)
}
func (p *Parser) SupportedWireStorage() []string {

View File

@ -20,6 +20,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"gopkg.in/v1/yaml"
)
@ -32,7 +33,7 @@ func TestParseBadStorage(t *testing.T) {
}
func DoParseTest(t *testing.T, storage string, obj interface{}, p *Parser) {
jsonData, _ := api.Encode(obj)
jsonData, _ := apitools.Encode(obj)
yamlData, _ := yaml.Marshal(obj)
t.Logf("Intermediate yaml:\n%v\n", string(yamlData))
t.Logf("Intermediate json:\n%v\n", string(jsonData))
@ -119,8 +120,8 @@ type TestParseType struct {
}
func TestParseCustomType(t *testing.T) {
api.AddKnownTypes("", TestParseType{})
api.AddKnownTypes("v1beta1", TestParseType{})
apitools.AddKnownTypes("", TestParseType{})
apitools.AddKnownTypes("v1beta1", TestParseType{})
parser := NewParser(map[string]interface{}{
"custom": TestParseType{},
})

View File

@ -21,6 +21,7 @@ import (
"net/http"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
)
@ -52,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, _ := api.Encode(api.Status{
data, _ := apitools.Encode(api.Status{
Status: api.StatusFailure,
Message: fmt.Sprintf("internal error: %#v", err),
})

View File

@ -26,6 +26,7 @@ import (
"text/template"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/golang/glog"
"gopkg.in/v1/yaml"
@ -49,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 := api.Encode(obj)
data, err := apitools.Encode(obj)
if err != nil {
return err
}
@ -258,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 := api.Decode(data)
obj, err := apitools.Decode(data)
if err != nil {
return err
}
@ -290,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 := api.Decode(data)
obj, err := apitools.Decode(data)
if err != nil {
return err
}

View File

@ -25,6 +25,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"gopkg.in/v1/yaml"
)
@ -95,7 +96,7 @@ func TestIdentityPrinter(t *testing.T) {
}
buff.Reset()
printer.PrintObj(obj, buff)
objOut, err := api.Decode([]byte(buff.String()))
objOut, err := apitools.Decode([]byte(buff.String()))
if err != nil {
t.Errorf("Unexpeted error: %#v", err)
}

View File

@ -22,6 +22,7 @@ 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/tools"
"github.com/coreos/go-etcd/etcd"
@ -35,7 +36,7 @@ func TestGetEtcdData(t *testing.T) {
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: api.EncodeOrDie(&api.ContainerManifestList{
Value: apitools.EncodeOrDie(&api.ContainerManifestList{
Items: []api.ContainerManifest{{ID: "foo"}},
}),
ModifiedIndex: 1,
@ -78,7 +79,7 @@ func TestGetEtcd(t *testing.T) {
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: api.EncodeOrDie(&api.ContainerManifestList{
Value: apitools.EncodeOrDie(&api.ContainerManifestList{
Items: []api.ContainerManifest{manifest},
}),
ModifiedIndex: 1,
@ -112,7 +113,7 @@ func TestWatchEtcd(t *testing.T) {
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: api.EncodeOrDie(&api.ContainerManifestList{}),
Value: apitools.EncodeOrDie(&api.ContainerManifestList{}),
ModifiedIndex: 2,
},
},

View File

@ -24,6 +24,7 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/golang/glog"
@ -69,7 +70,7 @@ func (s *SourceURL) extractFromURL() error {
var manifest api.ContainerManifest
singleErr := yaml.Unmarshal(data, &manifest)
if singleErr == nil {
if errs := api.ValidateManifest(&manifest); len(errs) > 0 {
if errs := validation.ValidateManifest(&manifest); len(errs) > 0 {
singleErr = fmt.Errorf("invalid manifest: %v", errs)
}
}
@ -90,7 +91,7 @@ func (s *SourceURL) extractFromURL() error {
// done at the end. Hence not returning early here.
if multiErr == nil {
for _, manifest := range manifests {
if errs := api.ValidateManifest(&manifest); len(errs) > 0 {
if errs := validation.ValidateManifest(&manifest); len(errs) > 0 {
multiErr = fmt.Errorf("invalid manifest: %v", errs)
break
}

View File

@ -28,6 +28,7 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/health"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
@ -600,7 +601,7 @@ func filterHostPortConflicts(pods []Pod) []Pod {
extract := func(p *api.Port) int { return p.HostPort }
for i := range pods {
pod := &pods[i]
if errs := api.AccumulateUniquePorts(pod.Manifest.Containers, ports, extract); len(errs) != 0 {
if errs := validation.AccumulateUniquePorts(pod.Manifest.Containers, ports, extract); len(errs) != 0 {
glog.Warningf("Pod %s has conflicting ports, ignoring: %v", GetPodFullName(pod), errs)
continue
}

View File

@ -17,8 +17,8 @@ limitations under the License.
package kubelet
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
apierrs "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
@ -26,7 +26,7 @@ func ValidatePod(pod *Pod) (errors []error) {
if !util.IsDNSSubdomain(pod.Name) {
errors = append(errors, apierrs.NewInvalid("Pod.Name", pod.Name))
}
if errs := api.ValidateManifest(&pod.Manifest); len(errs) != 0 {
if errs := validation.ValidateManifest(&pod.Manifest); len(errs) != 0 {
errors = append(errors, errs...)
}
return errors

View File

@ -20,9 +20,9 @@ import (
"net/http"
"time"
"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/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/binding"
@ -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, api.Codec
return storage, apitools.Codec
}

View File

@ -39,6 +39,7 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/coreos/go-etcd/etcd"
@ -132,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 = api.DecodeInto([]byte(node.Value), &svc)
err = apitools.DecodeInto([]byte(node.Value), &svc)
if err != nil {
glog.Errorf("Failed to load Service: %s (%#v)", node.Value, err)
continue
@ -165,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 = api.DecodeInto([]byte(response.Node.Value), &e)
err = apitools.DecodeInto([]byte(response.Node.Value), &e)
return e, err
}
@ -175,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 := api.DecodeInto([]byte(response.Node.Value), &svc)
err := apitools.DecodeInto([]byte(response.Node.Value), &svc)
if err != nil {
return nil, err
}
@ -229,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 := api.DecodeInto([]byte(response.Node.Value), &endpoints)
err := apitools.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

View File

@ -24,6 +24,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/labels"
)
@ -37,12 +38,12 @@ func TestNewBindingStorage(t *testing.T) {
PodID: "foo",
Host: "bar",
}
body, err := api.Encode(binding)
body, err := apitools.Encode(binding)
if err != nil {
t.Fatalf("Unexpected encode error %v", err)
}
obj := b.New()
err = api.DecodeInto(body, obj)
err = apitools.DecodeInto(body, obj)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}

View File

@ -21,6 +21,7 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/pod"
@ -59,7 +60,7 @@ func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
}
// Pod Manifest ID should be assigned by the pod API
controller.DesiredState.PodTemplate.DesiredState.Manifest.ID = ""
if errs := api.ValidateReplicationController(controller); len(errs) > 0 {
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
return nil, apiserver.NewInvalidErr("replicationController", controller.ID, errs)
}
@ -118,7 +119,7 @@ func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
if !ok {
return nil, fmt.Errorf("not a replication controller: %#v", obj)
}
if errs := api.ValidateReplicationController(controller); len(errs) > 0 {
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
return nil, apiserver.NewInvalidErr("replicationController", controller.ID, errs)
}
return apiserver.MakeAsync(func() (interface{}, error) {

View File

@ -26,6 +26,7 @@ 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"
)
@ -111,13 +112,13 @@ func TestControllerDecode(t *testing.T) {
ID: "foo",
},
}
body, err := api.Encode(controller)
body, err := apitools.Encode(controller)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
controllerOut := storage.New()
if err := api.DecodeInto(body, controllerOut); err != nil {
if err := apitools.DecodeInto(body, controllerOut); err != nil {
t.Errorf("unexpected error: %v", err)
}

View File

@ -21,6 +21,7 @@ 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/tools"
@ -44,8 +45,8 @@ func NewRegistry(client tools.EtcdClient) *Registry {
registry := &Registry{
EtcdHelper: tools.EtcdHelper{
client,
api.Codec,
api.ResourceVersioner,
apitools.Codec,
apitools.ResourceVersioner,
},
}
registry.manifestFactory = &BasicManifestFactory{
@ -267,7 +268,7 @@ func (r *Registry) CreateController(controller api.ReplicationController) error
// UpdateController replaces an existing ReplicationController.
func (r *Registry) UpdateController(controller api.ReplicationController) error {
return r.SetObj(makeControllerKey(controller.ID), controller)
return r.SetObj(makeControllerKey(controller.ID), &controller)
}
// DeleteController deletes a ReplicationController specified by its ID.
@ -352,7 +353,7 @@ func (r *Registry) DeleteService(name string) error {
// UpdateService replaces an existing Service.
func (r *Registry) UpdateService(svc api.Service) error {
return r.SetObj(makeServiceKey(svc.ID), svc)
return r.SetObj(makeServiceKey(svc.ID), &svc)
}
// WatchServices begins watching for new, changed, or deleted service configurations.

View File

@ -23,6 +23,7 @@ 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/tools"
@ -40,7 +41,7 @@ func NewTestEtcdRegistry(client tools.EtcdClient) *Registry {
func TestEtcdGetPod(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.Set("/registry/pods/foo", api.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/pods/foo", apitools.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := NewTestEtcdRegistry(fakeClient)
pod, err := registry.GetPod("foo")
if err != nil {
@ -76,7 +77,7 @@ func TestEtcdCreatePod(t *testing.T) {
},
E: tools.EtcdErrorNotFound,
}
fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(&api.ContainerManifestList{}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", apitools.EncodeOrDie(&api.ContainerManifestList{}), 0)
registry := NewTestEtcdRegistry(fakeClient)
err := registry.CreatePod(api.Pod{
JSONBase: api.JSONBase{
@ -107,7 +108,7 @@ func TestEtcdCreatePod(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
var pod api.Pod
err = api.DecodeInto([]byte(resp.Node.Value), &pod)
err = apitools.DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -121,7 +122,7 @@ func TestEtcdCreatePod(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
err = api.DecodeInto([]byte(resp.Node.Value), &manifests)
err = apitools.DecodeInto([]byte(resp.Node.Value), &manifests)
if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests)
}
@ -132,7 +133,7 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) {
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: api.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}),
Value: apitools.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}),
},
},
E: nil,
@ -234,7 +235,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
var pod api.Pod
err = api.DecodeInto([]byte(resp.Node.Value), &pod)
err = apitools.DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -248,7 +249,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
err = api.DecodeInto([]byte(resp.Node.Value), &manifests)
err = apitools.DecodeInto([]byte(resp.Node.Value), &manifests)
if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests)
}
@ -263,7 +264,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
},
E: tools.EtcdErrorNotFound,
}
fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(api.ContainerManifestList{
fakeClient.Set("/registry/hosts/machine/kubelet", apitools.EncodeOrDie(api.ContainerManifestList{
Items: []api.ContainerManifest{
{ID: "bar"},
},
@ -299,7 +300,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
var pod api.Pod
err = api.DecodeInto([]byte(resp.Node.Value), &pod)
err = apitools.DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -313,7 +314,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
err = api.DecodeInto([]byte(resp.Node.Value), &manifests)
err = apitools.DecodeInto([]byte(resp.Node.Value), &manifests)
if len(manifests.Items) != 2 || manifests.Items[1].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests)
}
@ -324,11 +325,11 @@ func TestEtcdDeletePod(t *testing.T) {
fakeClient.TestIndex = true
key := "/registry/pods/foo"
fakeClient.Set(key, api.EncodeOrDie(api.Pod{
fakeClient.Set(key, apitools.EncodeOrDie(api.Pod{
JSONBase: api.JSONBase{ID: "foo"},
DesiredState: api.PodState{Host: "machine"},
}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(&api.ContainerManifestList{
fakeClient.Set("/registry/hosts/machine/kubelet", apitools.EncodeOrDie(&api.ContainerManifestList{
Items: []api.ContainerManifest{
{ID: "foo"},
},
@ -349,7 +350,7 @@ func TestEtcdDeletePod(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
var manifests api.ContainerManifestList
api.DecodeInto([]byte(response.Node.Value), &manifests)
apitools.DecodeInto([]byte(response.Node.Value), &manifests)
if len(manifests.Items) != 0 {
t.Errorf("Unexpected container set: %s, expected empty", response.Node.Value)
}
@ -360,11 +361,11 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
fakeClient.TestIndex = true
key := "/registry/pods/foo"
fakeClient.Set(key, api.EncodeOrDie(api.Pod{
fakeClient.Set(key, apitools.EncodeOrDie(api.Pod{
JSONBase: api.JSONBase{ID: "foo"},
DesiredState: api.PodState{Host: "machine"},
}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(&api.ContainerManifestList{
fakeClient.Set("/registry/hosts/machine/kubelet", apitools.EncodeOrDie(&api.ContainerManifestList{
Items: []api.ContainerManifest{
{ID: "foo"},
{ID: "bar"},
@ -387,7 +388,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
var manifests api.ContainerManifestList
api.DecodeInto([]byte(response.Node.Value), &manifests)
apitools.DecodeInto([]byte(response.Node.Value), &manifests)
if len(manifests.Items) != 1 {
t.Fatalf("Unexpected manifest set: %#v, expected empty", manifests)
}
@ -444,13 +445,13 @@ func TestEtcdListPods(t *testing.T) {
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: api.EncodeOrDie(api.Pod{
Value: apitools.EncodeOrDie(api.Pod{
JSONBase: api.JSONBase{ID: "foo"},
DesiredState: api.PodState{Host: "machine"},
}),
},
{
Value: api.EncodeOrDie(api.Pod{
Value: apitools.EncodeOrDie(api.Pod{
JSONBase: api.JSONBase{ID: "bar"},
DesiredState: api.PodState{Host: "machine"},
}),
@ -519,10 +520,10 @@ func TestEtcdListControllers(t *testing.T) {
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}),
Value: apitools.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}),
},
{
Value: api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "bar"}}),
Value: apitools.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "bar"}}),
},
},
},
@ -542,7 +543,7 @@ func TestEtcdListControllers(t *testing.T) {
func TestEtcdGetController(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.Set("/registry/controllers/foo", api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/controllers/foo", apitools.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := NewTestEtcdRegistry(fakeClient)
ctrl, err := registry.GetController("foo")
if err != nil {
@ -606,7 +607,7 @@ func TestEtcdCreateController(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
var ctrl api.ReplicationController
err = api.DecodeInto([]byte(resp.Node.Value), &ctrl)
err = apitools.DecodeInto([]byte(resp.Node.Value), &ctrl)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -618,7 +619,7 @@ func TestEtcdCreateController(t *testing.T) {
func TestEtcdCreateControllerAlreadyExisting(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.Set("/registry/controllers/foo", api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/controllers/foo", apitools.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := NewTestEtcdRegistry(fakeClient)
err := registry.CreateController(api.ReplicationController{
@ -635,7 +636,7 @@ func TestEtcdUpdateController(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.TestIndex = true
resp, _ := fakeClient.Set("/registry/controllers/foo", api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
resp, _ := fakeClient.Set("/registry/controllers/foo", apitools.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},
@ -661,10 +662,10 @@ func TestEtcdListServices(t *testing.T) {
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}),
Value: apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}),
},
{
Value: api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "bar"}}),
Value: apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "bar"}}),
},
},
},
@ -698,7 +699,7 @@ func TestEtcdCreateService(t *testing.T) {
}
var service api.Service
err = api.DecodeInto([]byte(resp.Node.Value), &service)
err = apitools.DecodeInto([]byte(resp.Node.Value), &service)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -710,7 +711,7 @@ func TestEtcdCreateService(t *testing.T) {
func TestEtcdCreateServiceAlreadyExisting(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.Set("/registry/services/specs/foo", api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/services/specs/foo", apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := NewTestEtcdRegistry(fakeClient)
err := registry.CreateService(api.Service{
JSONBase: api.JSONBase{ID: "foo"},
@ -722,7 +723,7 @@ func TestEtcdCreateServiceAlreadyExisting(t *testing.T) {
func TestEtcdGetService(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.Set("/registry/services/specs/foo", api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/services/specs/foo", apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := NewTestEtcdRegistry(fakeClient)
service, err := registry.GetService("foo")
if err != nil {
@ -774,7 +775,7 @@ func TestEtcdUpdateService(t *testing.T) {
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.TestIndex = true
resp, _ := fakeClient.Set("/registry/services/specs/foo", api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
resp, _ := fakeClient.Set("/registry/services/specs/foo", apitools.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := NewTestEtcdRegistry(fakeClient)
testService := api.Service{
JSONBase: api.JSONBase{ID: "foo", ResourceVersion: resp.Node.ModifiedIndex},
@ -811,7 +812,7 @@ func TestEtcdGetEndpoints(t *testing.T) {
Endpoints: []string{"127.0.0.1:34855"},
}
fakeClient.Set("/registry/services/endpoints/foo", api.EncodeOrDie(endpoints), 0)
fakeClient.Set("/registry/services/endpoints/foo", apitools.EncodeOrDie(endpoints), 0)
got, err := registry.GetEndpoints("foo")
if err != nil {
@ -832,7 +833,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) {
Endpoints: []string{"baz", "bar"},
}
fakeClient.Set("/registry/services/endpoints/foo", api.EncodeOrDie(api.Endpoints{}), 0)
fakeClient.Set("/registry/services/endpoints/foo", apitools.EncodeOrDie(api.Endpoints{}), 0)
err := registry.UpdateEndpoints(endpoints)
if err != nil {
@ -844,7 +845,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) {
t.Fatalf("Unexpected error %v", err)
}
var endpointsOut api.Endpoints
err = api.DecodeInto([]byte(response.Node.Value), &endpointsOut)
err = apitools.DecodeInto([]byte(response.Node.Value), &endpointsOut)
if !reflect.DeepEqual(endpoints, endpointsOut) {
t.Errorf("Unexpected endpoints: %#v, expected %#v", endpointsOut, endpoints)
}

View File

@ -20,7 +20,7 @@ import (
"reflect"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
fake_cloud "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
)
func TestCloudList(t *testing.T) {

View File

@ -23,6 +23,7 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
@ -68,7 +69,7 @@ func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
pod.ID = uuid.NewUUID().String()
}
pod.DesiredState.Manifest.ID = pod.ID
if errs := api.ValidatePod(pod); len(errs) > 0 {
if errs := validation.ValidatePod(pod); len(errs) > 0 {
return nil, apiserver.NewInvalidErr("pod", pod.ID, errs)
}
@ -135,7 +136,7 @@ func (rs RegistryStorage) New() interface{} {
func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
pod := obj.(*api.Pod)
if errs := api.ValidatePod(pod); len(errs) > 0 {
if errs := validation.ValidatePod(pod); len(errs) > 0 {
return nil, apiserver.NewInvalidErr("pod", pod.ID, errs)
}
return apiserver.MakeAsync(func() (interface{}, error) {

View File

@ -24,6 +24,7 @@ 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"
@ -177,13 +178,13 @@ func TestPodDecode(t *testing.T) {
ID: "foo",
},
}
body, err := api.Encode(expected)
body, err := apitools.Encode(expected)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
actual := storage.New()
if err := api.DecodeInto(body, actual); err != nil {
if err := apitools.DecodeInto(body, actual); err != nil {
t.Errorf("unexpected error: %v", err)
}

View File

@ -23,6 +23,7 @@ import (
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
@ -49,7 +50,7 @@ func NewRegistryStorage(registry Registry, cloud cloudprovider.Interface, machin
func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
srv := obj.(*api.Service)
if errs := api.ValidateService(srv); len(errs) > 0 {
if errs := validation.ValidateService(srv); len(errs) > 0 {
return nil, apiserver.NewInvalidErr("service", srv.ID, errs)
}
@ -155,7 +156,7 @@ func GetServiceEnvironmentVariables(registry Registry, machine string) ([]api.En
func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
srv := obj.(*api.Service)
if errs := api.ValidateService(srv); len(errs) > 0 {
if errs := validation.ValidateService(srv); len(errs) > 0 {
return nil, apiserver.NewInvalidErr("service", srv.ID, errs)
}
return apiserver.MakeAsync(func() (interface{}, error) {

View File

@ -24,6 +24,7 @@ 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/watch"
)
@ -35,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, api.APIObject{expect}})
err := encoder.Encode(api.WatchEvent{watch.Added, common.Object{expect}})
if err != nil {
t.Errorf("Unexpected error %v", err)
}

View File

@ -24,6 +24,7 @@ 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/util"
"github.com/coreos/go-etcd/etcd"
@ -40,8 +41,8 @@ type TestResource struct {
}
var scheme *conversion.Scheme
var codec = api.Codec
var versioner = api.ResourceVersioner
var codec = apitools.Codec
var versioner = apitools.ResourceVersioner
func init() {
scheme = conversion.NewScheme()
@ -184,13 +185,13 @@ func TestSetObj(t *testing.T) {
}
func TestSetObjWithVersion(t *testing.T) {
obj := api.Pod{JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1}}
obj := &api.Pod{JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1}}
fakeClient := NewFakeEtcdClient(t)
fakeClient.TestIndex = true
fakeClient.Data["/some/key"] = EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: api.EncodeOrDie(obj),
Value: apitools.EncodeOrDie(obj),
ModifiedIndex: 1,
},
},
@ -235,7 +236,7 @@ func TestAtomicUpdate(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
fakeClient.TestIndex = true
codec := scheme
helper := EtcdHelper{fakeClient, codec, api.NewJSONBaseResourceVersioner()}
helper := EtcdHelper{fakeClient, codec, apitools.NewJSONBaseResourceVersioner()}
// Create a new node.
fakeClient.ExpectNotFoundGet("/some/key")
@ -289,7 +290,7 @@ func TestAtomicUpdate(t *testing.T) {
func TestAtomicUpdateNoChange(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
fakeClient.TestIndex = true
helper := EtcdHelper{fakeClient, scheme, api.NewJSONBaseResourceVersioner()}
helper := EtcdHelper{fakeClient, scheme, apitools.NewJSONBaseResourceVersioner()}
// Create a new node.
fakeClient.ExpectNotFoundGet("/some/key")
@ -321,7 +322,7 @@ func TestAtomicUpdate_CreateCollision(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
fakeClient.TestIndex = true
codec := scheme
helper := EtcdHelper{fakeClient, codec, api.NewJSONBaseResourceVersioner()}
helper := EtcdHelper{fakeClient, codec, apitools.NewJSONBaseResourceVersioner()}
fakeClient.ExpectNotFoundGet("/some/key")

View File

@ -23,6 +23,7 @@ import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/coreos/go-etcd/etcd"
)
@ -47,62 +48,62 @@ func TestWatchInterpretations(t *testing.T) {
}{
"create": {
actions: []string{"create", "get"},
nodeValue: api.EncodeOrDie(podBar),
nodeValue: apitools.EncodeOrDie(podBar),
expectEmit: true,
expectType: watch.Added,
expectObject: podBar,
},
"create but filter blocks": {
actions: []string{"create", "get"},
nodeValue: api.EncodeOrDie(podFoo),
nodeValue: apitools.EncodeOrDie(podFoo),
expectEmit: false,
},
"delete": {
actions: []string{"delete"},
prevNodeValue: api.EncodeOrDie(podBar),
prevNodeValue: apitools.EncodeOrDie(podBar),
expectEmit: true,
expectType: watch.Deleted,
expectObject: podBar,
},
"delete but filter blocks": {
actions: []string{"delete"},
nodeValue: api.EncodeOrDie(podFoo),
nodeValue: apitools.EncodeOrDie(podFoo),
expectEmit: false,
},
"modify appears to create 1": {
actions: []string{"set", "compareAndSwap"},
nodeValue: api.EncodeOrDie(podBar),
nodeValue: apitools.EncodeOrDie(podBar),
expectEmit: true,
expectType: watch.Added,
expectObject: podBar,
},
"modify appears to create 2": {
actions: []string{"set", "compareAndSwap"},
prevNodeValue: api.EncodeOrDie(podFoo),
nodeValue: api.EncodeOrDie(podBar),
prevNodeValue: apitools.EncodeOrDie(podFoo),
nodeValue: apitools.EncodeOrDie(podBar),
expectEmit: true,
expectType: watch.Added,
expectObject: podBar,
},
"modify appears to delete": {
actions: []string{"set", "compareAndSwap"},
prevNodeValue: api.EncodeOrDie(podBar),
nodeValue: api.EncodeOrDie(podFoo),
prevNodeValue: apitools.EncodeOrDie(podBar),
nodeValue: apitools.EncodeOrDie(podFoo),
expectEmit: true,
expectType: watch.Deleted,
expectObject: podBar, // Should return last state that passed the filter!
},
"modify modifies": {
actions: []string{"set", "compareAndSwap"},
prevNodeValue: api.EncodeOrDie(podBar),
nodeValue: api.EncodeOrDie(podBaz),
prevNodeValue: apitools.EncodeOrDie(podBar),
nodeValue: apitools.EncodeOrDie(podBaz),
expectEmit: true,
expectType: watch.Modified,
expectObject: podBaz,
},
"modify ignores": {
actions: []string{"set", "compareAndSwap"},
nodeValue: api.EncodeOrDie(podFoo),
nodeValue: apitools.EncodeOrDie(podFoo),
expectEmit: false,
},
}
@ -258,7 +259,7 @@ func TestWatchEtcdState(t *testing.T) {
{
Action: "create",
Node: &etcd.Node{
Value: string(api.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
},
},
},
@ -272,12 +273,12 @@ func TestWatchEtcdState(t *testing.T) {
{
Action: "compareAndSwap",
Node: &etcd.Node{
Value: string(api.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})),
Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})),
CreatedIndex: 1,
ModifiedIndex: 2,
},
PrevNode: &etcd.Node{
Value: string(api.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
CreatedIndex: 1,
ModifiedIndex: 1,
},
@ -294,7 +295,7 @@ func TestWatchEtcdState(t *testing.T) {
R: &etcd.Response{
Action: "get",
Node: &etcd.Node{
Value: string(api.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
CreatedIndex: 1,
ModifiedIndex: 1,
},
@ -307,12 +308,12 @@ func TestWatchEtcdState(t *testing.T) {
{
Action: "compareAndSwap",
Node: &etcd.Node{
Value: string(api.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})),
Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})),
CreatedIndex: 1,
ModifiedIndex: 2,
},
PrevNode: &etcd.Node{
Value: string(api.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
Value: string(apitools.EncodeOrDie(&api.Endpoints{JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{}})),
CreatedIndex: 1,
ModifiedIndex: 1,
},
@ -369,7 +370,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: api.EncodeOrDie(pod),
Value: apitools.EncodeOrDie(pod),
CreatedIndex: 1,
ModifiedIndex: 1,
},
@ -384,7 +385,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: api.EncodeOrDie(pod),
Value: apitools.EncodeOrDie(pod),
CreatedIndex: 1,
ModifiedIndex: 2,
},
@ -442,13 +443,13 @@ func TestWatchListFromZeroIndex(t *testing.T) {
Dir: true,
Nodes: etcd.Nodes{
&etcd.Node{
Value: api.EncodeOrDie(pod),
Value: apitools.EncodeOrDie(pod),
CreatedIndex: 1,
ModifiedIndex: 1,
Nodes: etcd.Nodes{},
},
&etcd.Node{
Value: api.EncodeOrDie(pod),
Value: apitools.EncodeOrDie(pod),
CreatedIndex: 2,
ModifiedIndex: 2,
Nodes: etcd.Nodes{},

View File

@ -24,6 +24,7 @@ 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"
@ -112,7 +113,7 @@ func TestPollMinions(t *testing.T) {
ml := &api.MinionList{Items: item.minions}
handler := util.FakeHandler{
StatusCode: 200,
ResponseBody: api.EncodeOrDie(ml),
ResponseBody: apitools.EncodeOrDie(ml),
T: t,
}
mux := http.NewServeMux()
@ -139,7 +140,7 @@ func TestDefaultErrorFunc(t *testing.T) {
testPod := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
handler := util.FakeHandler{
StatusCode: 200,
ResponseBody: api.EncodeOrDie(testPod),
ResponseBody: apitools.EncodeOrDie(testPod),
T: t,
}
mux := http.NewServeMux()
@ -258,7 +259,7 @@ func TestBind(t *testing.T) {
t.Errorf("Unexpected error: %v", err)
continue
}
expectedBody := api.EncodeOrDie(item.binding)
expectedBody := apitools.EncodeOrDie(item.binding)
handler.ValidateRequest(t, "/api/v1beta1/bindings", "POST", &expectedBody)
}
}

View File

@ -22,6 +22,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apitools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
@ -83,9 +84,9 @@ func TestExtractObj(t *testing.T) {
func TestWatch(t *testing.T) {
client := newEtcdClient()
helper := tools.EtcdHelper{Client: client, Codec: api.Codec, ResourceVersioner: api.ResourceVersioner}
helper := tools.EtcdHelper{Client: client, Codec: apitools.Codec, ResourceVersioner: apitools.ResourceVersioner}
withEtcdKey(func(key string) {
resp, err := client.Set(key, api.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
resp, err := client.Set(key, apitools.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}