fix dot import.

This commit is contained in:
Brendan Burns 2014-06-12 13:17:34 -07:00
parent 54d1e7e86d
commit 0c3b9f2b69
18 changed files with 322 additions and 322 deletions

View File

@ -19,7 +19,7 @@ import (
"encoding/json" "encoding/json"
"net/url" "net/url"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
) )
@ -35,11 +35,11 @@ func MakeControllerRegistryStorage(registry ControllerRegistry) apiserver.RESTSt
} }
func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) { func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) {
result := ReplicationControllerList{JSONBase: JSONBase{Kind: "cluster#replicationControllerList"}} result := api.ReplicationControllerList{JSONBase: api.JSONBase{Kind: "cluster#replicationControllerList"}}
controllers, err := storage.registry.ListControllers() controllers, err := storage.registry.ListControllers()
if err == nil { if err == nil {
result = ReplicationControllerList{ result = api.ReplicationControllerList{
JSONBase: JSONBase{Kind: "cluster#replicationControllerList"}, JSONBase: api.JSONBase{Kind: "cluster#replicationControllerList"},
Items: controllers, Items: controllers,
} }
} }
@ -57,16 +57,16 @@ func (storage *ControllerRegistryStorage) Delete(id string) error {
} }
func (storage *ControllerRegistryStorage) Extract(body string) (interface{}, error) { func (storage *ControllerRegistryStorage) Extract(body string) (interface{}, error) {
result := ReplicationController{} result := api.ReplicationController{}
err := json.Unmarshal([]byte(body), &result) err := json.Unmarshal([]byte(body), &result)
result.Kind = "cluster#replicationController" result.Kind = "cluster#replicationController"
return result, err return result, err
} }
func (storage *ControllerRegistryStorage) Create(controller interface{}) error { func (storage *ControllerRegistryStorage) Create(controller interface{}) error {
return storage.registry.CreateController(controller.(ReplicationController)) return storage.registry.CreateController(controller.(api.ReplicationController))
} }
func (storage *ControllerRegistryStorage) Update(controller interface{}) error { func (storage *ControllerRegistryStorage) Update(controller interface{}) error {
return storage.registry.UpdateController(controller.(ReplicationController)) return storage.registry.UpdateController(controller.(api.ReplicationController))
} }

View File

@ -22,27 +22,27 @@ import (
"reflect" "reflect"
"testing" "testing"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
type MockControllerRegistry struct { type MockControllerRegistry struct {
err error err error
controllers []ReplicationController controllers []api.ReplicationController
} }
func (registry *MockControllerRegistry) ListControllers() ([]ReplicationController, error) { func (registry *MockControllerRegistry) ListControllers() ([]api.ReplicationController, error) {
return registry.controllers, registry.err return registry.controllers, registry.err
} }
func (registry *MockControllerRegistry) GetController(ID string) (*ReplicationController, error) { func (registry *MockControllerRegistry) GetController(ID string) (*api.ReplicationController, error) {
return &ReplicationController{}, registry.err return &api.ReplicationController{}, registry.err
} }
func (registry *MockControllerRegistry) CreateController(controller ReplicationController) error { func (registry *MockControllerRegistry) CreateController(controller api.ReplicationController) error {
return registry.err return registry.err
} }
func (registry *MockControllerRegistry) UpdateController(controller ReplicationController) error { func (registry *MockControllerRegistry) UpdateController(controller api.ReplicationController) error {
return registry.err return registry.err
} }
func (registry *MockControllerRegistry) DeleteController(ID string) error { func (registry *MockControllerRegistry) DeleteController(ID string) error {
@ -57,7 +57,7 @@ func TestListControllersError(t *testing.T) {
registry: &mockRegistry, registry: &mockRegistry,
} }
controllersObj, err := storage.List(nil) controllersObj, err := storage.List(nil)
controllers := controllersObj.(ReplicationControllerList) controllers := controllersObj.(api.ReplicationControllerList)
if err != mockRegistry.err { if err != mockRegistry.err {
t.Errorf("Expected %#v, Got %#v", mockRegistry.err, err) t.Errorf("Expected %#v, Got %#v", mockRegistry.err, err)
} }
@ -73,21 +73,21 @@ func TestListEmptyControllerList(t *testing.T) {
} }
controllers, err := storage.List(nil) controllers, err := storage.List(nil)
expectNoError(t, err) expectNoError(t, err)
if len(controllers.(ReplicationControllerList).Items) != 0 { if len(controllers.(api.ReplicationControllerList).Items) != 0 {
t.Errorf("Unexpected non-zero ctrl list: %#v", controllers) t.Errorf("Unexpected non-zero ctrl list: %#v", controllers)
} }
} }
func TestListControllerList(t *testing.T) { func TestListControllerList(t *testing.T) {
mockRegistry := MockControllerRegistry{ mockRegistry := MockControllerRegistry{
controllers: []ReplicationController{ controllers: []api.ReplicationController{
{ {
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
}, },
{ {
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "bar", ID: "bar",
}, },
}, },
@ -97,7 +97,7 @@ func TestListControllerList(t *testing.T) {
registry: &mockRegistry, registry: &mockRegistry,
} }
controllersObj, err := storage.List(nil) controllersObj, err := storage.List(nil)
controllers := controllersObj.(ReplicationControllerList) controllers := controllersObj.(api.ReplicationControllerList)
expectNoError(t, err) expectNoError(t, err)
if len(controllers.Items) != 2 { if len(controllers.Items) != 2 {
t.Errorf("Unexpected controller list: %#v", controllers) t.Errorf("Unexpected controller list: %#v", controllers)
@ -115,8 +115,8 @@ func TestExtractControllerJson(t *testing.T) {
storage := ControllerRegistryStorage{ storage := ControllerRegistryStorage{
registry: &mockRegistry, registry: &mockRegistry,
} }
controller := ReplicationController{ controller := api.ReplicationController{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
} }
@ -132,22 +132,22 @@ func TestExtractControllerJson(t *testing.T) {
} }
func TestControllerParsing(t *testing.T) { func TestControllerParsing(t *testing.T) {
expectedController := ReplicationController{ expectedController := api.ReplicationController{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "nginxController", ID: "nginxController",
}, },
DesiredState: ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 2, Replicas: 2,
ReplicasInSet: map[string]string{ ReplicasInSet: map[string]string{
"name": "nginx", "name": "nginx",
}, },
PodTemplate: PodTemplate{ PodTemplate: api.PodTemplate{
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Containers: []Container{ Containers: []api.Container{
{ {
Image: "dockerfile/nginx", Image: "dockerfile/nginx",
Ports: []Port{ Ports: []api.Port{
{ {
ContainerPort: 80, ContainerPort: 80,
HostPort: 8080, HostPort: 8080,
@ -177,7 +177,7 @@ func TestControllerParsing(t *testing.T) {
expectNoError(t, err) expectNoError(t, err)
data, err = ioutil.ReadFile(fileName) data, err = ioutil.ReadFile(fileName)
expectNoError(t, err) expectNoError(t, err)
var controller ReplicationController var controller api.ReplicationController
err = json.Unmarshal(data, &controller) err = json.Unmarshal(data, &controller)
expectNoError(t, err) expectNoError(t, err)

View File

@ -19,7 +19,7 @@ import (
"fmt" "fmt"
"log" "log"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
func MakeEndpointController(serviceRegistry ServiceRegistry, podRegistry PodRegistry) *EndpointController { func MakeEndpointController(serviceRegistry ServiceRegistry, podRegistry PodRegistry) *EndpointController {
@ -52,7 +52,7 @@ func (e *EndpointController) SyncServiceEndpoints() error {
// TODO: Use port names in the service object, don't just use port #0 // TODO: Use port names in the service object, don't just use port #0
endpoints[ix] = fmt.Sprintf("%s:%d", pod.CurrentState.Host, pod.DesiredState.Manifest.Containers[0].Ports[0].HostPort) endpoints[ix] = fmt.Sprintf("%s:%d", pod.CurrentState.Host, pod.DesiredState.Manifest.Containers[0].Ports[0].HostPort)
} }
err = e.serviceRegistry.UpdateEndpoints(Endpoints{ err = e.serviceRegistry.UpdateEndpoints(api.Endpoints{
Name: service.ID, Name: service.ID,
Endpoints: endpoints, Endpoints: endpoints,
}) })

View File

@ -19,7 +19,7 @@ import (
"fmt" "fmt"
"testing" "testing"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
func TestSyncEndpointsEmpty(t *testing.T) { func TestSyncEndpointsEmpty(t *testing.T) {
@ -46,8 +46,8 @@ func TestSyncEndpointsError(t *testing.T) {
func TestSyncEndpointsItems(t *testing.T) { func TestSyncEndpointsItems(t *testing.T) {
serviceRegistry := MockServiceRegistry{ serviceRegistry := MockServiceRegistry{
list: ServiceList{ list: api.ServiceList{
Items: []Service{ Items: []api.Service{
{ {
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
@ -57,13 +57,13 @@ func TestSyncEndpointsItems(t *testing.T) {
}, },
} }
podRegistry := MockPodRegistry{ podRegistry := MockPodRegistry{
pods: []Pod{ pods: []api.Pod{
{ {
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Containers: []Container{ Containers: []api.Container{
{ {
Ports: []Port{ Ports: []api.Port{
{ {
HostPort: 8080, HostPort: 8080,
}, },
@ -86,8 +86,8 @@ func TestSyncEndpointsItems(t *testing.T) {
func TestSyncEndpointsPodError(t *testing.T) { func TestSyncEndpointsPodError(t *testing.T) {
serviceRegistry := MockServiceRegistry{ serviceRegistry := MockServiceRegistry{
list: ServiceList{ list: api.ServiceList{
Items: []Service{ Items: []api.Service{
{ {
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",

View File

@ -22,7 +22,7 @@ import (
"github.com/coreos/go-etcd/etcd" "github.com/coreos/go-etcd/etcd"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
// TODO: Need to add a reconciler loop that makes sure that things in pods are reflected into // TODO: Need to add a reconciler loop that makes sure that things in pods are reflected into
@ -66,8 +66,8 @@ func makePodKey(machine, podID string) string {
return "/registry/hosts/" + machine + "/pods/" + podID return "/registry/hosts/" + machine + "/pods/" + podID
} }
func (registry *EtcdRegistry) ListPods(query *map[string]string) ([]Pod, error) { func (registry *EtcdRegistry) ListPods(query *map[string]string) ([]api.Pod, error) {
pods := []Pod{} pods := []api.Pod{}
for _, machine := range registry.machines { for _, machine := range registry.machines {
machinePods, err := registry.listPodsForMachine(machine) machinePods, err := registry.listPodsForMachine(machine)
if err != nil { if err != nil {
@ -95,12 +95,12 @@ func (registry *EtcdRegistry) listEtcdNode(key string) ([]*etcd.Node, error) {
return result.Node.Nodes, nil return result.Node.Nodes, nil
} }
func (registry *EtcdRegistry) listPodsForMachine(machine string) ([]Pod, error) { func (registry *EtcdRegistry) listPodsForMachine(machine string) ([]api.Pod, error) {
pods := []Pod{} pods := []api.Pod{}
key := "/registry/hosts/" + machine + "/pods" key := "/registry/hosts/" + machine + "/pods"
nodes, err := registry.listEtcdNode(key) nodes, err := registry.listEtcdNode(key)
for _, node := range nodes { for _, node := range nodes {
pod := Pod{} pod := api.Pod{}
err = json.Unmarshal([]byte(node.Value), &pod) err = json.Unmarshal([]byte(node.Value), &pod)
if err != nil { if err != nil {
return pods, err return pods, err
@ -111,7 +111,7 @@ func (registry *EtcdRegistry) listPodsForMachine(machine string) ([]Pod, error)
return pods, err return pods, err
} }
func (registry *EtcdRegistry) GetPod(podID string) (*Pod, error) { func (registry *EtcdRegistry) GetPod(podID string) (*api.Pod, error) {
pod, _, err := registry.findPod(podID) pod, _, err := registry.findPod(podID)
return &pod, err return &pod, err
} }
@ -120,14 +120,14 @@ func makeContainerKey(machine string) string {
return "/registry/hosts/" + machine + "/kubelet" return "/registry/hosts/" + machine + "/kubelet"
} }
func (registry *EtcdRegistry) loadManifests(machine string) ([]ContainerManifest, error) { func (registry *EtcdRegistry) loadManifests(machine string) ([]api.ContainerManifest, error) {
var manifests []ContainerManifest var manifests []api.ContainerManifest
response, err := registry.etcdClient.Get(makeContainerKey(machine), false, false) response, err := registry.etcdClient.Get(makeContainerKey(machine), false, false)
if err != nil { if err != nil {
if isEtcdNotFound(err) { if isEtcdNotFound(err) {
err = nil err = nil
manifests = []ContainerManifest{} manifests = []api.ContainerManifest{}
} }
} else { } else {
err = json.Unmarshal([]byte(response.Node.Value), &manifests) err = json.Unmarshal([]byte(response.Node.Value), &manifests)
@ -135,7 +135,7 @@ func (registry *EtcdRegistry) loadManifests(machine string) ([]ContainerManifest
return manifests, err return manifests, err
} }
func (registry *EtcdRegistry) updateManifests(machine string, manifests []ContainerManifest) error { func (registry *EtcdRegistry) updateManifests(machine string, manifests []api.ContainerManifest) error {
containerData, err := json.Marshal(manifests) containerData, err := json.Marshal(manifests)
if err != nil { if err != nil {
return err return err
@ -144,7 +144,7 @@ func (registry *EtcdRegistry) updateManifests(machine string, manifests []Contai
return err return err
} }
func (registry *EtcdRegistry) CreatePod(machineIn string, pod Pod) error { func (registry *EtcdRegistry) CreatePod(machineIn string, pod api.Pod) error {
podOut, machine, err := registry.findPod(pod.ID) podOut, machine, err := registry.findPod(pod.ID)
if err == nil { if err == nil {
return fmt.Errorf("A pod named %s already exists on %s (%#v)", pod.ID, machine, podOut) return fmt.Errorf("A pod named %s already exists on %s (%#v)", pod.ID, machine, podOut)
@ -152,7 +152,7 @@ func (registry *EtcdRegistry) CreatePod(machineIn string, pod Pod) error {
return registry.runPod(pod, machineIn) return registry.runPod(pod, machineIn)
} }
func (registry *EtcdRegistry) runPod(pod Pod, machine string) error { func (registry *EtcdRegistry) runPod(pod api.Pod, machine string) error {
manifests, err := registry.loadManifests(machine) manifests, err := registry.loadManifests(machine)
if err != nil { if err != nil {
return err return err
@ -173,7 +173,7 @@ func (registry *EtcdRegistry) runPod(pod Pod, machine string) error {
return registry.updateManifests(machine, manifests) return registry.updateManifests(machine, manifests)
} }
func (registry *EtcdRegistry) UpdatePod(pod Pod) error { func (registry *EtcdRegistry) UpdatePod(pod api.Pod) error {
return fmt.Errorf("Unimplemented!") return fmt.Errorf("Unimplemented!")
} }
@ -190,7 +190,7 @@ func (registry *EtcdRegistry) deletePodFromMachine(machine, podID string) error
if err != nil { if err != nil {
return err return err
} }
newManifests := make([]ContainerManifest, 0) newManifests := make([]api.ContainerManifest, 0)
found := false found := false
for _, manifest := range manifests { for _, manifest := range manifests {
if manifest.Id != podID { if manifest.Id != podID {
@ -213,33 +213,33 @@ func (registry *EtcdRegistry) deletePodFromMachine(machine, podID string) error
return err return err
} }
func (registry *EtcdRegistry) getPodForMachine(machine, podID string) (Pod, error) { func (registry *EtcdRegistry) getPodForMachine(machine, podID string) (api.Pod, error) {
key := makePodKey(machine, podID) key := makePodKey(machine, podID)
result, err := registry.etcdClient.Get(key, false, false) result, err := registry.etcdClient.Get(key, false, false)
if err != nil { if err != nil {
if isEtcdNotFound(err) { if isEtcdNotFound(err) {
return Pod{}, fmt.Errorf("Not found (%#v).", err) return api.Pod{}, fmt.Errorf("Not found (%#v).", err)
} else { } else {
return Pod{}, err return api.Pod{}, err
} }
} }
if result.Node == nil || len(result.Node.Value) == 0 { if result.Node == nil || len(result.Node.Value) == 0 {
return Pod{}, fmt.Errorf("no nodes field: %#v", result) return api.Pod{}, fmt.Errorf("no nodes field: %#v", result)
} }
pod := Pod{} pod := api.Pod{}
err = json.Unmarshal([]byte(result.Node.Value), &pod) err = json.Unmarshal([]byte(result.Node.Value), &pod)
pod.CurrentState.Host = machine pod.CurrentState.Host = machine
return pod, err return pod, err
} }
func (registry *EtcdRegistry) findPod(podID string) (Pod, string, error) { func (registry *EtcdRegistry) findPod(podID string) (api.Pod, string, error) {
for _, machine := range registry.machines { for _, machine := range registry.machines {
pod, err := registry.getPodForMachine(machine, podID) pod, err := registry.getPodForMachine(machine, podID)
if err == nil { if err == nil {
return pod, machine, nil return pod, machine, nil
} }
} }
return Pod{}, "", fmt.Errorf("Pod not found %s", podID) return api.Pod{}, "", fmt.Errorf("Pod not found %s", podID)
} }
func isEtcdNotFound(err error) bool { func isEtcdNotFound(err error) bool {
@ -259,12 +259,12 @@ func isEtcdNotFound(err error) bool {
return false return false
} }
func (registry *EtcdRegistry) ListControllers() ([]ReplicationController, error) { func (registry *EtcdRegistry) ListControllers() ([]api.ReplicationController, error) {
var controllers []ReplicationController var controllers []api.ReplicationController
key := "/registry/controllers" key := "/registry/controllers"
nodes, err := registry.listEtcdNode(key) nodes, err := registry.listEtcdNode(key)
for _, node := range nodes { for _, node := range nodes {
var controller ReplicationController var controller api.ReplicationController
err = json.Unmarshal([]byte(node.Value), &controller) err = json.Unmarshal([]byte(node.Value), &controller)
if err != nil { if err != nil {
return controllers, err return controllers, err
@ -278,8 +278,8 @@ func makeControllerKey(id string) string {
return "/registry/controllers/" + id return "/registry/controllers/" + id
} }
func (registry *EtcdRegistry) GetController(controllerID string) (*ReplicationController, error) { func (registry *EtcdRegistry) GetController(controllerID string) (*api.ReplicationController, error) {
var controller ReplicationController var controller api.ReplicationController
key := makeControllerKey(controllerID) key := makeControllerKey(controllerID)
result, err := registry.etcdClient.Get(key, false, false) result, err := registry.etcdClient.Get(key, false, false)
if err != nil { if err != nil {
@ -296,12 +296,12 @@ func (registry *EtcdRegistry) GetController(controllerID string) (*ReplicationCo
return &controller, err return &controller, err
} }
func (registry *EtcdRegistry) CreateController(controller ReplicationController) error { func (registry *EtcdRegistry) CreateController(controller api.ReplicationController) error {
// TODO : check for existence here and error. // TODO : check for existence here and error.
return registry.UpdateController(controller) return registry.UpdateController(controller)
} }
func (registry *EtcdRegistry) UpdateController(controller ReplicationController) error { func (registry *EtcdRegistry) UpdateController(controller api.ReplicationController) error {
controllerData, err := json.Marshal(controller) controllerData, err := json.Marshal(controller)
if err != nil { if err != nil {
return err return err
@ -321,25 +321,25 @@ func makeServiceKey(name string) string {
return "/registry/services/specs/" + name return "/registry/services/specs/" + name
} }
func (registry *EtcdRegistry) ListServices() (ServiceList, error) { func (registry *EtcdRegistry) ListServices() (api.ServiceList, error) {
nodes, err := registry.listEtcdNode("/registry/services/specs") nodes, err := registry.listEtcdNode("/registry/services/specs")
if err != nil { if err != nil {
return ServiceList{}, err return api.ServiceList{}, err
} }
var services []Service var services []api.Service
for _, node := range nodes { for _, node := range nodes {
var svc Service var svc api.Service
err := json.Unmarshal([]byte(node.Value), &svc) err := json.Unmarshal([]byte(node.Value), &svc)
if err != nil { if err != nil {
return ServiceList{}, err return api.ServiceList{}, err
} }
services = append(services, svc) services = append(services, svc)
} }
return ServiceList{Items: services}, nil return api.ServiceList{Items: services}, nil
} }
func (registry *EtcdRegistry) CreateService(svc Service) error { func (registry *EtcdRegistry) CreateService(svc api.Service) error {
key := makeServiceKey(svc.ID) key := makeServiceKey(svc.ID)
data, err := json.Marshal(svc) data, err := json.Marshal(svc)
if err != nil { if err != nil {
@ -349,7 +349,7 @@ func (registry *EtcdRegistry) CreateService(svc Service) error {
return err return err
} }
func (registry *EtcdRegistry) GetService(name string) (*Service, error) { func (registry *EtcdRegistry) GetService(name string) (*api.Service, error) {
key := makeServiceKey(name) key := makeServiceKey(name)
response, err := registry.etcdClient.Get(key, false, false) response, err := registry.etcdClient.Get(key, false, false)
if err != nil { if err != nil {
@ -359,7 +359,7 @@ func (registry *EtcdRegistry) GetService(name string) (*Service, error) {
return nil, err return nil, err
} }
} }
var svc Service var svc api.Service
err = json.Unmarshal([]byte(response.Node.Value), &svc) err = json.Unmarshal([]byte(response.Node.Value), &svc)
if err != nil { if err != nil {
return nil, err return nil, err
@ -378,11 +378,11 @@ func (registry *EtcdRegistry) DeleteService(name string) error {
return err return err
} }
func (registry *EtcdRegistry) UpdateService(svc Service) error { func (registry *EtcdRegistry) UpdateService(svc api.Service) error {
return registry.CreateService(svc) return registry.CreateService(svc)
} }
func (registry *EtcdRegistry) UpdateEndpoints(e Endpoints) error { func (registry *EtcdRegistry) UpdateEndpoints(e api.Endpoints) error {
data, err := json.Marshal(e) data, err := json.Marshal(e)
if err != nil { if err != nil {
return err return err

View File

@ -20,14 +20,14 @@ import (
"reflect" "reflect"
"testing" "testing"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/go-etcd/etcd"
) )
func TestEtcdGetPod(t *testing.T) { func TestEtcdGetPod(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t) fakeClient := MakeFakeEtcdClient(t)
fakeClient.Set("/registry/hosts/machine/pods/foo", util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), 0) fakeClient.Set("/registry/hosts/machine/pods/foo", util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
pod, err := registry.GetPod("foo") pod, err := registry.GetPod("foo")
expectNoError(t, err) expectNoError(t, err)
@ -61,15 +61,15 @@ func TestEtcdCreatePod(t *testing.T) {
}, },
E: &etcd.EtcdError{ErrorCode: 100}, E: &etcd.EtcdError{ErrorCode: 100},
} }
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{}), 0) fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreatePod("machine", Pod{ err := registry.CreatePod("machine", api.Pod{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Containers: []Container{ Containers: []api.Container{
{ {
Name: "foo", Name: "foo",
}, },
@ -80,13 +80,13 @@ func TestEtcdCreatePod(t *testing.T) {
expectNoError(t, err) expectNoError(t, err)
resp, err := fakeClient.Get("/registry/hosts/machine/pods/foo", false, false) resp, err := fakeClient.Get("/registry/hosts/machine/pods/foo", false, false)
expectNoError(t, err) expectNoError(t, err)
var pod Pod var pod api.Pod
err = json.Unmarshal([]byte(resp.Node.Value), &pod) err = json.Unmarshal([]byte(resp.Node.Value), &pod)
expectNoError(t, err) expectNoError(t, err)
if pod.ID != "foo" { if pod.ID != "foo" {
t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value) t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value)
} }
var manifests []ContainerManifest var manifests []api.ContainerManifest
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false) resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
expectNoError(t, err) expectNoError(t, err)
err = json.Unmarshal([]byte(resp.Node.Value), &manifests) err = json.Unmarshal([]byte(resp.Node.Value), &manifests)
@ -100,14 +100,14 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) {
fakeClient.Data["/registry/hosts/machine/pods/foo"] = EtcdResponseWithError{ fakeClient.Data["/registry/hosts/machine/pods/foo"] = EtcdResponseWithError{
R: &etcd.Response{ R: &etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), Value: util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}),
}, },
}, },
E: nil, E: nil,
} }
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreatePod("machine", Pod{ err := registry.CreatePod("machine", api.Pod{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
}) })
@ -131,8 +131,8 @@ func TestEtcdCreatePodWithContainersError(t *testing.T) {
E: &etcd.EtcdError{ErrorCode: 200}, E: &etcd.EtcdError{ErrorCode: 200},
} }
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreatePod("machine", Pod{ err := registry.CreatePod("machine", api.Pod{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
}) })
@ -163,14 +163,14 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
E: &etcd.EtcdError{ErrorCode: 100}, E: &etcd.EtcdError{ErrorCode: 100},
} }
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreatePod("machine", Pod{ err := registry.CreatePod("machine", api.Pod{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Id: "foo", Id: "foo",
Containers: []Container{ Containers: []api.Container{
{ {
Name: "foo", Name: "foo",
}, },
@ -181,13 +181,13 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
expectNoError(t, err) expectNoError(t, err)
resp, err := fakeClient.Get("/registry/hosts/machine/pods/foo", false, false) resp, err := fakeClient.Get("/registry/hosts/machine/pods/foo", false, false)
expectNoError(t, err) expectNoError(t, err)
var pod Pod var pod api.Pod
err = json.Unmarshal([]byte(resp.Node.Value), &pod) err = json.Unmarshal([]byte(resp.Node.Value), &pod)
expectNoError(t, err) expectNoError(t, err)
if pod.ID != "foo" { if pod.ID != "foo" {
t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value) t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value)
} }
var manifests []ContainerManifest var manifests []api.ContainerManifest
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false) resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
expectNoError(t, err) expectNoError(t, err)
err = json.Unmarshal([]byte(resp.Node.Value), &manifests) err = json.Unmarshal([]byte(resp.Node.Value), &manifests)
@ -204,20 +204,20 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
}, },
E: &etcd.EtcdError{ErrorCode: 100}, E: &etcd.EtcdError{ErrorCode: 100},
} }
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{ fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{
{ {
Id: "bar", Id: "bar",
}, },
}), 0) }), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreatePod("machine", Pod{ err := registry.CreatePod("machine", api.Pod{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Id: "foo", Id: "foo",
Containers: []Container{ Containers: []api.Container{
{ {
Name: "foo", Name: "foo",
}, },
@ -228,13 +228,13 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
expectNoError(t, err) expectNoError(t, err)
resp, err := fakeClient.Get("/registry/hosts/machine/pods/foo", false, false) resp, err := fakeClient.Get("/registry/hosts/machine/pods/foo", false, false)
expectNoError(t, err) expectNoError(t, err)
var pod Pod var pod api.Pod
err = json.Unmarshal([]byte(resp.Node.Value), &pod) err = json.Unmarshal([]byte(resp.Node.Value), &pod)
expectNoError(t, err) expectNoError(t, err)
if pod.ID != "foo" { if pod.ID != "foo" {
t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value) t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value)
} }
var manifests []ContainerManifest var manifests []api.ContainerManifest
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false) resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
expectNoError(t, err) expectNoError(t, err)
err = json.Unmarshal([]byte(resp.Node.Value), &manifests) err = json.Unmarshal([]byte(resp.Node.Value), &manifests)
@ -246,8 +246,8 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
func TestEtcdDeletePod(t *testing.T) { func TestEtcdDeletePod(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t) fakeClient := MakeFakeEtcdClient(t)
key := "/registry/hosts/machine/pods/foo" key := "/registry/hosts/machine/pods/foo"
fakeClient.Set(key, util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), 0) fakeClient.Set(key, util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{ fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{
{ {
Id: "foo", Id: "foo",
}, },
@ -270,8 +270,8 @@ func TestEtcdDeletePod(t *testing.T) {
func TestEtcdDeletePodMultipleContainers(t *testing.T) { func TestEtcdDeletePodMultipleContainers(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t) fakeClient := MakeFakeEtcdClient(t)
key := "/registry/hosts/machine/pods/foo" key := "/registry/hosts/machine/pods/foo"
fakeClient.Set(key, util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), 0) fakeClient.Set(key, util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{ fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{
{Id: "foo"}, {Id: "foo"},
{Id: "bar"}, {Id: "bar"},
}), 0) }), 0)
@ -285,7 +285,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
t.Errorf("Unexpected key: %s, expected %s", fakeClient.deletedKeys[0], key) t.Errorf("Unexpected key: %s, expected %s", fakeClient.deletedKeys[0], key)
} }
response, _ := fakeClient.Get("/registry/hosts/machine/kubelet", false, false) response, _ := fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
var manifests []ContainerManifest var manifests []api.ContainerManifest
json.Unmarshal([]byte(response.Node.Value), &manifests) json.Unmarshal([]byte(response.Node.Value), &manifests)
if len(manifests) != 1 { if len(manifests) != 1 {
t.Errorf("Unexpected manifest set: %#v, expected empty", manifests) t.Errorf("Unexpected manifest set: %#v, expected empty", manifests)
@ -337,10 +337,10 @@ func TestEtcdListPods(t *testing.T) {
Node: &etcd.Node{ Node: &etcd.Node{
Nodes: []*etcd.Node{ Nodes: []*etcd.Node{
{ {
Value: util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), Value: util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}),
}, },
{ {
Value: util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "bar"}}), Value: util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "bar"}}),
}, },
}, },
}, },
@ -393,10 +393,10 @@ func TestEtcdListControllers(t *testing.T) {
Node: &etcd.Node{ Node: &etcd.Node{
Nodes: []*etcd.Node{ Nodes: []*etcd.Node{
{ {
Value: util.MakeJSONString(ReplicationController{JSONBase: JSONBase{ID: "foo"}}), Value: util.MakeJSONString(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}),
}, },
{ {
Value: util.MakeJSONString(ReplicationController{JSONBase: JSONBase{ID: "bar"}}), Value: util.MakeJSONString(api.ReplicationController{JSONBase: api.JSONBase{ID: "bar"}}),
}, },
}, },
}, },
@ -413,7 +413,7 @@ func TestEtcdListControllers(t *testing.T) {
func TestEtcdGetController(t *testing.T) { func TestEtcdGetController(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t) fakeClient := MakeFakeEtcdClient(t)
fakeClient.Set("/registry/controllers/foo", util.MakeJSONString(ReplicationController{JSONBase: JSONBase{ID: "foo"}}), 0) fakeClient.Set("/registry/controllers/foo", util.MakeJSONString(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
ctrl, err := registry.GetController("foo") ctrl, err := registry.GetController("foo")
expectNoError(t, err) expectNoError(t, err)
@ -459,15 +459,15 @@ func TestEtcdDeleteController(t *testing.T) {
func TestEtcdCreateController(t *testing.T) { func TestEtcdCreateController(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t) fakeClient := MakeFakeEtcdClient(t)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreateController(ReplicationController{ err := registry.CreateController(api.ReplicationController{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
}) })
expectNoError(t, err) expectNoError(t, err)
resp, err := fakeClient.Get("/registry/controllers/foo", false, false) resp, err := fakeClient.Get("/registry/controllers/foo", false, false)
expectNoError(t, err) expectNoError(t, err)
var ctrl ReplicationController var ctrl api.ReplicationController
err = json.Unmarshal([]byte(resp.Node.Value), &ctrl) err = json.Unmarshal([]byte(resp.Node.Value), &ctrl)
expectNoError(t, err) expectNoError(t, err)
if ctrl.ID != "foo" { if ctrl.ID != "foo" {
@ -477,11 +477,11 @@ func TestEtcdCreateController(t *testing.T) {
func TestEtcdUpdateController(t *testing.T) { func TestEtcdUpdateController(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t) fakeClient := MakeFakeEtcdClient(t)
fakeClient.Set("/registry/controllers/foo", util.MakeJSONString(ReplicationController{JSONBase: JSONBase{ID: "foo"}}), 0) fakeClient.Set("/registry/controllers/foo", util.MakeJSONString(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.UpdateController(ReplicationController{ err := registry.UpdateController(api.ReplicationController{
JSONBase: JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
DesiredState: ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 2, Replicas: 2,
}, },
}) })
@ -500,10 +500,10 @@ func TestEtcdListServices(t *testing.T) {
Node: &etcd.Node{ Node: &etcd.Node{
Nodes: []*etcd.Node{ Nodes: []*etcd.Node{
{ {
Value: util.MakeJSONString(Service{JSONBase: JSONBase{ID: "foo"}}), Value: util.MakeJSONString(api.Service{JSONBase: api.JSONBase{ID: "foo"}}),
}, },
{ {
Value: util.MakeJSONString(Service{JSONBase: JSONBase{ID: "bar"}}), Value: util.MakeJSONString(api.Service{JSONBase: api.JSONBase{ID: "bar"}}),
}, },
}, },
}, },
@ -527,13 +527,13 @@ func TestEtcdCreateService(t *testing.T) {
E: &etcd.EtcdError{ErrorCode: 100}, E: &etcd.EtcdError{ErrorCode: 100},
} }
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreateService(Service{ err := registry.CreateService(api.Service{
JSONBase: JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
}) })
expectNoError(t, err) expectNoError(t, err)
resp, err := fakeClient.Get("/registry/services/specs/foo", false, false) resp, err := fakeClient.Get("/registry/services/specs/foo", false, false)
expectNoError(t, err) expectNoError(t, err)
var service Service var service api.Service
err = json.Unmarshal([]byte(resp.Node.Value), &service) err = json.Unmarshal([]byte(resp.Node.Value), &service)
expectNoError(t, err) expectNoError(t, err)
if service.ID != "foo" { if service.ID != "foo" {
@ -543,7 +543,7 @@ func TestEtcdCreateService(t *testing.T) {
func TestEtcdGetService(t *testing.T) { func TestEtcdGetService(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t) fakeClient := MakeFakeEtcdClient(t)
fakeClient.Set("/registry/services/specs/foo", util.MakeJSONString(Service{JSONBase: JSONBase{ID: "foo"}}), 0) fakeClient.Set("/registry/services/specs/foo", util.MakeJSONString(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
service, err := registry.GetService("foo") service, err := registry.GetService("foo")
expectNoError(t, err) expectNoError(t, err)
@ -589,10 +589,10 @@ func TestEtcdDeleteService(t *testing.T) {
func TestEtcdUpdateService(t *testing.T) { func TestEtcdUpdateService(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t) fakeClient := MakeFakeEtcdClient(t)
fakeClient.Set("/registry/services/specs/foo", util.MakeJSONString(Service{JSONBase: JSONBase{ID: "foo"}}), 0) fakeClient.Set("/registry/services/specs/foo", util.MakeJSONString(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.UpdateService(Service{ err := registry.UpdateService(api.Service{
JSONBase: JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
Labels: map[string]string{ Labels: map[string]string{
"baz": "bar", "baz": "bar",
}, },
@ -607,7 +607,7 @@ func TestEtcdUpdateService(t *testing.T) {
func TestEtcdUpdateEndpoints(t *testing.T) { func TestEtcdUpdateEndpoints(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t) fakeClient := MakeFakeEtcdClient(t)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
endpoints := Endpoints{ endpoints := api.Endpoints{
Name: "foo", Name: "foo",
Endpoints: []string{"baz", "bar"}, Endpoints: []string{"baz", "bar"},
} }
@ -615,7 +615,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) {
expectNoError(t, err) expectNoError(t, err)
response, err := fakeClient.Get("/registry/services/endpoints/foo", false, false) response, err := fakeClient.Get("/registry/services/endpoints/foo", false, false)
expectNoError(t, err) expectNoError(t, err)
var endpointsOut Endpoints var endpointsOut api.Endpoints
err = json.Unmarshal([]byte(response.Node.Value), &endpointsOut) err = json.Unmarshal([]byte(response.Node.Value), &endpointsOut)
if !reflect.DeepEqual(endpoints, endpointsOut) { if !reflect.DeepEqual(endpoints, endpointsOut) {
t.Errorf("Unexpected endpoints: %#v, expected %#v", endpointsOut, endpoints) t.Errorf("Unexpected endpoints: %#v, expected %#v", endpointsOut, endpoints)

View File

@ -16,22 +16,22 @@ limitations under the License.
package registry package registry
import ( import (
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
type ManifestFactory interface { type ManifestFactory interface {
// Make a container object for a given pod, given the machine that the pod is running on. // Make a container object for a given pod, given the machine that the pod is running on.
MakeManifest(machine string, pod Pod) (ContainerManifest, error) MakeManifest(machine string, pod api.Pod) (api.ContainerManifest, error)
} }
type BasicManifestFactory struct { type BasicManifestFactory struct {
serviceRegistry ServiceRegistry serviceRegistry ServiceRegistry
} }
func (b *BasicManifestFactory) MakeManifest(machine string, pod Pod) (ContainerManifest, error) { func (b *BasicManifestFactory) MakeManifest(machine string, pod api.Pod) (api.ContainerManifest, error) {
envVars, err := GetServiceEnvironmentVariables(b.serviceRegistry, machine) envVars, err := GetServiceEnvironmentVariables(b.serviceRegistry, machine)
if err != nil { if err != nil {
return ContainerManifest{}, err return api.ContainerManifest{}, err
} }
for ix, container := range pod.DesiredState.Manifest.Containers { for ix, container := range pod.DesiredState.Manifest.Containers {
pod.DesiredState.Manifest.Id = pod.ID pod.DesiredState.Manifest.Id = pod.ID

View File

@ -18,7 +18,7 @@ package registry
import ( import (
"testing" "testing"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
func TestMakeManifestNoServices(t *testing.T) { func TestMakeManifestNoServices(t *testing.T) {
@ -27,11 +27,11 @@ func TestMakeManifestNoServices(t *testing.T) {
serviceRegistry: &registry, serviceRegistry: &registry,
} }
manifest, err := factory.MakeManifest("machine", Pod{ manifest, err := factory.MakeManifest("machine", api.Pod{
JSONBase: JSONBase{ID: "foobar"}, JSONBase: api.JSONBase{ID: "foobar"},
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Containers: []Container{ Containers: []api.Container{
{ {
Name: "foo", Name: "foo",
}, },
@ -53,10 +53,10 @@ func TestMakeManifestNoServices(t *testing.T) {
func TestMakeManifestServices(t *testing.T) { func TestMakeManifestServices(t *testing.T) {
registry := MockServiceRegistry{ registry := MockServiceRegistry{
list: ServiceList{ list: api.ServiceList{
Items: []Service{ Items: []api.Service{
{ {
JSONBase: JSONBase{ID: "test"}, JSONBase: api.JSONBase{ID: "test"},
Port: 8080, Port: 8080,
}, },
}, },
@ -66,10 +66,10 @@ func TestMakeManifestServices(t *testing.T) {
serviceRegistry: &registry, serviceRegistry: &registry,
} }
manifest, err := factory.MakeManifest("machine", Pod{ manifest, err := factory.MakeManifest("machine", api.Pod{
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Containers: []Container{ Containers: []api.Container{
{ {
Name: "foo", Name: "foo",
}, },
@ -90,10 +90,10 @@ func TestMakeManifestServices(t *testing.T) {
func TestMakeManifestServicesExistingEnvVar(t *testing.T) { func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
registry := MockServiceRegistry{ registry := MockServiceRegistry{
list: ServiceList{ list: api.ServiceList{
Items: []Service{ Items: []api.Service{
{ {
JSONBase: JSONBase{ID: "test"}, JSONBase: api.JSONBase{ID: "test"},
Port: 8080, Port: 8080,
}, },
}, },
@ -103,12 +103,12 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
serviceRegistry: &registry, serviceRegistry: &registry,
} }
manifest, err := factory.MakeManifest("machine", Pod{ manifest, err := factory.MakeManifest("machine", api.Pod{
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Containers: []Container{ Containers: []api.Container{
{ {
Env: []EnvVar{ Env: []api.EnvVar{
{ {
Name: "foo", Name: "foo",
Value: "bar", Value: "bar",

View File

@ -16,27 +16,27 @@ limitations under the License.
package registry package registry
import ( import (
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
// An implementation of PodRegistry and ControllerRegistry that is backed by memory // An implementation of PodRegistry and ControllerRegistry that is backed by memory
// Mainly used for testing. // Mainly used for testing.
type MemoryRegistry struct { type MemoryRegistry struct {
podData map[string]Pod podData map[string]api.Pod
controllerData map[string]ReplicationController controllerData map[string]api.ReplicationController
serviceData map[string]Service serviceData map[string]api.Service
} }
func MakeMemoryRegistry() *MemoryRegistry { func MakeMemoryRegistry() *MemoryRegistry {
return &MemoryRegistry{ return &MemoryRegistry{
podData: map[string]Pod{}, podData: map[string]api.Pod{},
controllerData: map[string]ReplicationController{}, controllerData: map[string]api.ReplicationController{},
serviceData: map[string]Service{}, serviceData: map[string]api.Service{},
} }
} }
func (registry *MemoryRegistry) ListPods(labelQuery *map[string]string) ([]Pod, error) { func (registry *MemoryRegistry) ListPods(labelQuery *map[string]string) ([]api.Pod, error) {
result := []Pod{} result := []api.Pod{}
for _, value := range registry.podData { for _, value := range registry.podData {
if LabelsMatch(value, labelQuery) { if LabelsMatch(value, labelQuery) {
result = append(result, value) result = append(result, value)
@ -45,7 +45,7 @@ func (registry *MemoryRegistry) ListPods(labelQuery *map[string]string) ([]Pod,
return result, nil return result, nil
} }
func (registry *MemoryRegistry) GetPod(podID string) (*Pod, error) { func (registry *MemoryRegistry) GetPod(podID string) (*api.Pod, error) {
pod, found := registry.podData[podID] pod, found := registry.podData[podID]
if found { if found {
return &pod, nil return &pod, nil
@ -54,7 +54,7 @@ func (registry *MemoryRegistry) GetPod(podID string) (*Pod, error) {
} }
} }
func (registry *MemoryRegistry) CreatePod(machine string, pod Pod) error { func (registry *MemoryRegistry) CreatePod(machine string, pod api.Pod) error {
registry.podData[pod.ID] = pod registry.podData[pod.ID] = pod
return nil return nil
} }
@ -64,20 +64,20 @@ func (registry *MemoryRegistry) DeletePod(podID string) error {
return nil return nil
} }
func (registry *MemoryRegistry) UpdatePod(pod Pod) error { func (registry *MemoryRegistry) UpdatePod(pod api.Pod) error {
registry.podData[pod.ID] = pod registry.podData[pod.ID] = pod
return nil return nil
} }
func (registry *MemoryRegistry) ListControllers() ([]ReplicationController, error) { func (registry *MemoryRegistry) ListControllers() ([]api.ReplicationController, error) {
result := []ReplicationController{} result := []api.ReplicationController{}
for _, value := range registry.controllerData { for _, value := range registry.controllerData {
result = append(result, value) result = append(result, value)
} }
return result, nil return result, nil
} }
func (registry *MemoryRegistry) GetController(controllerID string) (*ReplicationController, error) { func (registry *MemoryRegistry) GetController(controllerID string) (*api.ReplicationController, error) {
controller, found := registry.controllerData[controllerID] controller, found := registry.controllerData[controllerID]
if found { if found {
return &controller, nil return &controller, nil
@ -86,7 +86,7 @@ func (registry *MemoryRegistry) GetController(controllerID string) (*Replication
} }
} }
func (registry *MemoryRegistry) CreateController(controller ReplicationController) error { func (registry *MemoryRegistry) CreateController(controller api.ReplicationController) error {
registry.controllerData[controller.ID] = controller registry.controllerData[controller.ID] = controller
return nil return nil
} }
@ -96,25 +96,25 @@ func (registry *MemoryRegistry) DeleteController(controllerId string) error {
return nil return nil
} }
func (registry *MemoryRegistry) UpdateController(controller ReplicationController) error { func (registry *MemoryRegistry) UpdateController(controller api.ReplicationController) error {
registry.controllerData[controller.ID] = controller registry.controllerData[controller.ID] = controller
return nil return nil
} }
func (registry *MemoryRegistry) ListServices() (ServiceList, error) { func (registry *MemoryRegistry) ListServices() (api.ServiceList, error) {
var list []Service var list []api.Service
for _, value := range registry.serviceData { for _, value := range registry.serviceData {
list = append(list, value) list = append(list, value)
} }
return ServiceList{Items: list}, nil return api.ServiceList{Items: list}, nil
} }
func (registry *MemoryRegistry) CreateService(svc Service) error { func (registry *MemoryRegistry) CreateService(svc api.Service) error {
registry.serviceData[svc.ID] = svc registry.serviceData[svc.ID] = svc
return nil return nil
} }
func (registry *MemoryRegistry) GetService(name string) (*Service, error) { func (registry *MemoryRegistry) GetService(name string) (*api.Service, error) {
svc, found := registry.serviceData[name] svc, found := registry.serviceData[name]
if found { if found {
return &svc, nil return &svc, nil
@ -128,10 +128,10 @@ func (registry *MemoryRegistry) DeleteService(name string) error {
return nil return nil
} }
func (registry *MemoryRegistry) UpdateService(svc Service) error { func (registry *MemoryRegistry) UpdateService(svc api.Service) error {
return registry.CreateService(svc) return registry.CreateService(svc)
} }
func (registry *MemoryRegistry) UpdateEndpoints(e Endpoints) error { func (registry *MemoryRegistry) UpdateEndpoints(e api.Endpoints) error {
return nil return nil
} }

View File

@ -18,7 +18,7 @@ package registry
import ( import (
"testing" "testing"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
func TestListPodsEmpty(t *testing.T) { func TestListPodsEmpty(t *testing.T) {
@ -32,7 +32,7 @@ func TestListPodsEmpty(t *testing.T) {
func TestMemoryListPods(t *testing.T) { func TestMemoryListPods(t *testing.T) {
registry := MakeMemoryRegistry() registry := MakeMemoryRegistry()
registry.CreatePod("machine", Pod{JSONBase: JSONBase{ID: "foo"}}) registry.CreatePod("machine", api.Pod{JSONBase: api.JSONBase{ID: "foo"}})
pods, err := registry.ListPods(nil) pods, err := registry.ListPods(nil)
expectNoError(t, err) expectNoError(t, err)
if len(pods) != 1 || pods[0].ID != "foo" { if len(pods) != 1 || pods[0].ID != "foo" {
@ -42,7 +42,7 @@ func TestMemoryListPods(t *testing.T) {
func TestMemorySetGetPods(t *testing.T) { func TestMemorySetGetPods(t *testing.T) {
registry := MakeMemoryRegistry() registry := MakeMemoryRegistry()
expectedPod := Pod{JSONBase: JSONBase{ID: "foo"}} expectedPod := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
registry.CreatePod("machine", expectedPod) registry.CreatePod("machine", expectedPod)
pod, err := registry.GetPod("foo") pod, err := registry.GetPod("foo")
expectNoError(t, err) expectNoError(t, err)
@ -53,12 +53,12 @@ func TestMemorySetGetPods(t *testing.T) {
func TestMemorySetUpdateGetPods(t *testing.T) { func TestMemorySetUpdateGetPods(t *testing.T) {
registry := MakeMemoryRegistry() registry := MakeMemoryRegistry()
oldPod := Pod{JSONBase: JSONBase{ID: "foo"}} oldPod := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
expectedPod := Pod{ expectedPod := api.Pod{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
DesiredState: PodState{ DesiredState: api.PodState{
Host: "foo.com", Host: "foo.com",
}, },
} }
@ -73,7 +73,7 @@ func TestMemorySetUpdateGetPods(t *testing.T) {
func TestMemorySetDeleteGetPods(t *testing.T) { func TestMemorySetDeleteGetPods(t *testing.T) {
registry := MakeMemoryRegistry() registry := MakeMemoryRegistry()
expectedPod := Pod{JSONBase: JSONBase{ID: "foo"}} expectedPod := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
registry.CreatePod("machine", expectedPod) registry.CreatePod("machine", expectedPod)
registry.DeletePod("foo") registry.DeletePod("foo")
pod, err := registry.GetPod("foo") pod, err := registry.GetPod("foo")
@ -94,7 +94,7 @@ func TestListControllersEmpty(t *testing.T) {
func TestMemoryListControllers(t *testing.T) { func TestMemoryListControllers(t *testing.T) {
registry := MakeMemoryRegistry() registry := MakeMemoryRegistry()
registry.CreateController(ReplicationController{JSONBase: JSONBase{ID: "foo"}}) registry.CreateController(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}})
pods, err := registry.ListControllers() pods, err := registry.ListControllers()
expectNoError(t, err) expectNoError(t, err)
if len(pods) != 1 || pods[0].ID != "foo" { if len(pods) != 1 || pods[0].ID != "foo" {
@ -104,7 +104,7 @@ func TestMemoryListControllers(t *testing.T) {
func TestMemorySetGetControllers(t *testing.T) { func TestMemorySetGetControllers(t *testing.T) {
registry := MakeMemoryRegistry() registry := MakeMemoryRegistry()
expectedController := ReplicationController{JSONBase: JSONBase{ID: "foo"}} expectedController := api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}
registry.CreateController(expectedController) registry.CreateController(expectedController)
pod, err := registry.GetController("foo") pod, err := registry.GetController("foo")
expectNoError(t, err) expectNoError(t, err)
@ -115,12 +115,12 @@ func TestMemorySetGetControllers(t *testing.T) {
func TestMemorySetUpdateGetControllers(t *testing.T) { func TestMemorySetUpdateGetControllers(t *testing.T) {
registry := MakeMemoryRegistry() registry := MakeMemoryRegistry()
oldController := ReplicationController{JSONBase: JSONBase{ID: "foo"}} oldController := api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}
expectedController := ReplicationController{ expectedController := api.ReplicationController{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
DesiredState: ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: 2, Replicas: 2,
}, },
} }
@ -135,7 +135,7 @@ func TestMemorySetUpdateGetControllers(t *testing.T) {
func TestMemorySetDeleteGetControllers(t *testing.T) { func TestMemorySetDeleteGetControllers(t *testing.T) {
registry := MakeMemoryRegistry() registry := MakeMemoryRegistry()
expectedController := ReplicationController{JSONBase: JSONBase{ID: "foo"}} expectedController := api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}
registry.CreateController(expectedController) registry.CreateController(expectedController)
registry.DeleteController("foo") registry.DeleteController("foo")
pod, err := registry.GetController("foo") pod, err := registry.GetController("foo")

View File

@ -16,24 +16,24 @@ limitations under the License.
package registry package registry
import ( import (
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
type MockServiceRegistry struct { type MockServiceRegistry struct {
list ServiceList list api.ServiceList
err error err error
endpoints Endpoints endpoints api.Endpoints
} }
func (m *MockServiceRegistry) ListServices() (ServiceList, error) { func (m *MockServiceRegistry) ListServices() (api.ServiceList, error) {
return m.list, m.err return m.list, m.err
} }
func (m *MockServiceRegistry) CreateService(svc Service) error { func (m *MockServiceRegistry) CreateService(svc api.Service) error {
return m.err return m.err
} }
func (m *MockServiceRegistry) GetService(name string) (*Service, error) { func (m *MockServiceRegistry) GetService(name string) (*api.Service, error) {
return nil, m.err return nil, m.err
} }
@ -41,11 +41,11 @@ func (m *MockServiceRegistry) DeleteService(name string) error {
return m.err return m.err
} }
func (m *MockServiceRegistry) UpdateService(svc Service) error { func (m *MockServiceRegistry) UpdateService(svc api.Service) error {
return m.err return m.err
} }
func (m *MockServiceRegistry) UpdateEndpoints(e Endpoints) error { func (m *MockServiceRegistry) UpdateEndpoints(e api.Endpoints) error {
m.endpoints = e m.endpoints = e
return m.err return m.err
} }

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"net/url" "net/url"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
) )
@ -41,7 +41,7 @@ func MakePodRegistryStorage(registry PodRegistry, containerInfo client.Container
} }
// LabelMatch tests to see if a Pod's labels map contains 'key' mapping to 'value' // LabelMatch tests to see if a Pod's labels map contains 'key' mapping to 'value'
func LabelMatch(pod Pod, queryKey, queryValue string) bool { func LabelMatch(pod api.Pod, queryKey, queryValue string) bool {
for key, value := range pod.Labels { for key, value := range pod.Labels {
if queryKey == key && queryValue == value { if queryKey == key && queryValue == value {
return true return true
@ -51,7 +51,7 @@ func LabelMatch(pod Pod, queryKey, queryValue string) bool {
} }
// LabelMatch tests to see if a Pod's labels map contains all key/value pairs in 'labelQuery' // LabelMatch tests to see if a Pod's labels map contains all key/value pairs in 'labelQuery'
func LabelsMatch(pod Pod, labelQuery *map[string]string) bool { func LabelsMatch(pod api.Pod, labelQuery *map[string]string) bool {
if labelQuery == nil { if labelQuery == nil {
return true return true
} }
@ -64,7 +64,7 @@ func LabelsMatch(pod Pod, labelQuery *map[string]string) bool {
} }
func (storage *PodRegistryStorage) List(url *url.URL) (interface{}, error) { func (storage *PodRegistryStorage) List(url *url.URL) (interface{}, error) {
var result PodList var result api.PodList
var query *map[string]string var query *map[string]string
if url != nil { if url != nil {
queryMap := client.DecodeLabelQuery(url.Query().Get("labels")) queryMap := client.DecodeLabelQuery(url.Query().Get("labels"))
@ -72,7 +72,7 @@ func (storage *PodRegistryStorage) List(url *url.URL) (interface{}, error) {
} }
pods, err := storage.registry.ListPods(query) pods, err := storage.registry.ListPods(query)
if err == nil { if err == nil {
result = PodList{ result = api.PodList{
Items: pods, Items: pods,
} }
} }
@ -99,14 +99,14 @@ func (storage *PodRegistryStorage) Delete(id string) error {
} }
func (storage *PodRegistryStorage) Extract(body string) (interface{}, error) { func (storage *PodRegistryStorage) Extract(body string) (interface{}, error) {
pod := Pod{} pod := api.Pod{}
err := json.Unmarshal([]byte(body), &pod) err := json.Unmarshal([]byte(body), &pod)
pod.Kind = "cluster#pod" pod.Kind = "cluster#pod"
return pod, err return pod, err
} }
func (storage *PodRegistryStorage) Create(pod interface{}) error { func (storage *PodRegistryStorage) Create(pod interface{}) error {
podObj := pod.(Pod) podObj := pod.(api.Pod)
if len(podObj.ID) == 0 { if len(podObj.ID) == 0 {
return fmt.Errorf("ID is unspecified: %#v", pod) return fmt.Errorf("ID is unspecified: %#v", pod)
} }
@ -118,5 +118,5 @@ func (storage *PodRegistryStorage) Create(pod interface{}) error {
} }
func (storage *PodRegistryStorage) Update(pod interface{}) error { func (storage *PodRegistryStorage) Update(pod interface{}) error {
return storage.registry.UpdatePod(pod.(Pod)) return storage.registry.UpdatePod(pod.(api.Pod))
} }

View File

@ -21,12 +21,12 @@ import (
"reflect" "reflect"
"testing" "testing"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
type MockPodRegistry struct { type MockPodRegistry struct {
err error err error
pods []Pod pods []api.Pod
} }
func expectNoError(t *testing.T, err error) { func expectNoError(t *testing.T, err error) {
@ -35,19 +35,19 @@ func expectNoError(t *testing.T, err error) {
} }
} }
func (registry *MockPodRegistry) ListPods(*map[string]string) ([]Pod, error) { func (registry *MockPodRegistry) ListPods(*map[string]string) ([]api.Pod, error) {
return registry.pods, registry.err return registry.pods, registry.err
} }
func (registry *MockPodRegistry) GetPod(podId string) (*Pod, error) { func (registry *MockPodRegistry) GetPod(podId string) (*api.Pod, error) {
return &Pod{}, registry.err return &api.Pod{}, registry.err
} }
func (registry *MockPodRegistry) CreatePod(machine string, pod Pod) error { func (registry *MockPodRegistry) CreatePod(machine string, pod api.Pod) error {
return registry.err return registry.err
} }
func (registry *MockPodRegistry) UpdatePod(pod Pod) error { func (registry *MockPodRegistry) UpdatePod(pod api.Pod) error {
return registry.err return registry.err
} }
func (registry *MockPodRegistry) DeletePod(podId string) error { func (registry *MockPodRegistry) DeletePod(podId string) error {
@ -65,7 +65,7 @@ func TestListPodsError(t *testing.T) {
if err != mockRegistry.err { if err != mockRegistry.err {
t.Errorf("Expected %#v, Got %#v", mockRegistry.err, err) t.Errorf("Expected %#v, Got %#v", mockRegistry.err, err)
} }
if len(pods.(PodList).Items) != 0 { if len(pods.(api.PodList).Items) != 0 {
t.Errorf("Unexpected non-zero pod list: %#v", pods) t.Errorf("Unexpected non-zero pod list: %#v", pods)
} }
} }
@ -77,21 +77,21 @@ func TestListEmptyPodList(t *testing.T) {
} }
pods, err := storage.List(nil) pods, err := storage.List(nil)
expectNoError(t, err) expectNoError(t, err)
if len(pods.(PodList).Items) != 0 { if len(pods.(api.PodList).Items) != 0 {
t.Errorf("Unexpected non-zero pod list: %#v", pods) t.Errorf("Unexpected non-zero pod list: %#v", pods)
} }
} }
func TestListPodList(t *testing.T) { func TestListPodList(t *testing.T) {
mockRegistry := MockPodRegistry{ mockRegistry := MockPodRegistry{
pods: []Pod{ pods: []api.Pod{
{ {
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
}, },
{ {
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "bar", ID: "bar",
}, },
}, },
@ -101,7 +101,7 @@ func TestListPodList(t *testing.T) {
registry: &mockRegistry, registry: &mockRegistry,
} }
podsObj, err := storage.List(nil) podsObj, err := storage.List(nil)
pods := podsObj.(PodList) pods := podsObj.(api.PodList)
expectNoError(t, err) expectNoError(t, err)
if len(pods.Items) != 2 { if len(pods.Items) != 2 {
t.Errorf("Unexpected pod list: %#v", pods) t.Errorf("Unexpected pod list: %#v", pods)
@ -119,8 +119,8 @@ func TestExtractJson(t *testing.T) {
storage := PodRegistryStorage{ storage := PodRegistryStorage{
registry: &mockRegistry, registry: &mockRegistry,
} }
pod := Pod{ pod := api.Pod{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: "foo", ID: "foo",
}, },
} }
@ -135,32 +135,32 @@ func TestExtractJson(t *testing.T) {
} }
} }
func expectLabelMatch(t *testing.T, pod Pod, key, value string) { func expectLabelMatch(t *testing.T, pod api.Pod, key, value string) {
if !LabelMatch(pod, key, value) { if !LabelMatch(pod, key, value) {
t.Errorf("Unexpected match failure: %#v %s %s", pod, key, value) t.Errorf("Unexpected match failure: %#v %s %s", pod, key, value)
} }
} }
func expectNoLabelMatch(t *testing.T, pod Pod, key, value string) { func expectNoLabelMatch(t *testing.T, pod api.Pod, key, value string) {
if LabelMatch(pod, key, value) { if LabelMatch(pod, key, value) {
t.Errorf("Unexpected match success: %#v %s %s", pod, key, value) t.Errorf("Unexpected match success: %#v %s %s", pod, key, value)
} }
} }
func expectLabelsMatch(t *testing.T, pod Pod, query *map[string]string) { func expectLabelsMatch(t *testing.T, pod api.Pod, query *map[string]string) {
if !LabelsMatch(pod, query) { if !LabelsMatch(pod, query) {
t.Errorf("Unexpected match failure: %#v %#v", pod, *query) t.Errorf("Unexpected match failure: %#v %#v", pod, *query)
} }
} }
func expectNoLabelsMatch(t *testing.T, pod Pod, query *map[string]string) { func expectNoLabelsMatch(t *testing.T, pod api.Pod, query *map[string]string) {
if LabelsMatch(pod, query) { if LabelsMatch(pod, query) {
t.Errorf("Unexpected match success: %#v %#v", pod, *query) t.Errorf("Unexpected match success: %#v %#v", pod, *query)
} }
} }
func TestLabelMatch(t *testing.T) { func TestLabelMatch(t *testing.T) {
pod := Pod{ pod := api.Pod{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
"baz": "blah", "baz": "blah",
@ -173,7 +173,7 @@ func TestLabelMatch(t *testing.T) {
} }
func TestLabelsMatch(t *testing.T) { func TestLabelsMatch(t *testing.T) {
pod := Pod{ pod := api.Pod{
Labels: map[string]string{ Labels: map[string]string{
"foo": "bar", "foo": "bar",
"baz": "blah", "baz": "blah",

View File

@ -24,7 +24,7 @@ import (
"sync" "sync"
"time" "time"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/go-etcd/etcd"
@ -43,7 +43,7 @@ type ReplicationManager struct {
// An interface that knows how to add or delete pods // An interface that knows how to add or delete pods
// created as an interface to allow testing. // created as an interface to allow testing.
type PodControlInterface interface { type PodControlInterface interface {
createReplica(controllerSpec ReplicationController) createReplica(controllerSpec api.ReplicationController)
deletePod(podID string) error deletePod(podID string) error
} }
@ -51,13 +51,13 @@ type RealPodControl struct {
kubeClient client.ClientInterface kubeClient client.ClientInterface
} }
func (r RealPodControl) createReplica(controllerSpec ReplicationController) { func (r RealPodControl) createReplica(controllerSpec api.ReplicationController) {
labels := controllerSpec.DesiredState.PodTemplate.Labels labels := controllerSpec.DesiredState.PodTemplate.Labels
if labels != nil { if labels != nil {
labels["replicationController"] = controllerSpec.ID labels["replicationController"] = controllerSpec.ID
} }
pod := Pod{ pod := api.Pod{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: fmt.Sprintf("%x", rand.Int()), ID: fmt.Sprintf("%x", rand.Int()),
}, },
DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState, DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState,
@ -102,10 +102,10 @@ func (rm *ReplicationManager) WatchControllers() {
} }
} }
func (rm *ReplicationManager) handleWatchResponse(response *etcd.Response) (*ReplicationController, error) { func (rm *ReplicationManager) handleWatchResponse(response *etcd.Response) (*api.ReplicationController, error) {
if response.Action == "set" { if response.Action == "set" {
if response.Node != nil { if response.Node != nil {
var controllerSpec ReplicationController var controllerSpec api.ReplicationController
err := json.Unmarshal([]byte(response.Node.Value), &controllerSpec) err := json.Unmarshal([]byte(response.Node.Value), &controllerSpec)
if err != nil { if err != nil {
return nil, err return nil, err
@ -118,8 +118,8 @@ func (rm *ReplicationManager) handleWatchResponse(response *etcd.Response) (*Rep
return nil, nil return nil, nil
} }
func (rm *ReplicationManager) filterActivePods(pods []Pod) []Pod { func (rm *ReplicationManager) filterActivePods(pods []api.Pod) []api.Pod {
var result []Pod var result []api.Pod
for _, value := range pods { for _, value := range pods {
if strings.Index(value.CurrentState.Status, "Exit") == -1 { if strings.Index(value.CurrentState.Status, "Exit") == -1 {
result = append(result, value) result = append(result, value)
@ -128,7 +128,7 @@ func (rm *ReplicationManager) filterActivePods(pods []Pod) []Pod {
return result return result
} }
func (rm *ReplicationManager) syncReplicationController(controllerSpec ReplicationController) error { func (rm *ReplicationManager) syncReplicationController(controllerSpec api.ReplicationController) error {
rm.updateLock.Lock() rm.updateLock.Lock()
podList, err := rm.kubeClient.ListPods(controllerSpec.DesiredState.ReplicasInSet) podList, err := rm.kubeClient.ListPods(controllerSpec.DesiredState.ReplicasInSet)
if err != nil { if err != nil {
@ -168,7 +168,7 @@ func (rm *ReplicationManager) Synchronize() {
// sooner rather than later. // sooner rather than later.
if response != nil && response.Node != nil && response.Node.Nodes != nil { if response != nil && response.Node != nil && response.Node.Nodes != nil {
for _, value := range response.Node.Nodes { for _, value := range response.Node.Nodes {
var controllerSpec ReplicationController var controllerSpec api.ReplicationController
err := json.Unmarshal([]byte(value.Value), &controllerSpec) err := json.Unmarshal([]byte(value.Value), &controllerSpec)
if err != nil { if err != nil {
log.Printf("Unexpected error: %#v", err) log.Printf("Unexpected error: %#v", err)

View File

@ -22,8 +22,8 @@ import (
"reflect" "reflect"
"testing" "testing"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/go-etcd/etcd"
) )
@ -36,11 +36,11 @@ func makeUrl(suffix string) string {
} }
type FakePodControl struct { type FakePodControl struct {
controllerSpec []ReplicationController controllerSpec []api.ReplicationController
deletePodID []string deletePodID []string
} }
func (f *FakePodControl) createReplica(spec ReplicationController) { func (f *FakePodControl) createReplica(spec api.ReplicationController) {
f.controllerSpec = append(f.controllerSpec, spec) f.controllerSpec = append(f.controllerSpec, spec)
} }
@ -49,14 +49,14 @@ func (f *FakePodControl) deletePod(podID string) error {
return nil return nil
} }
func makeReplicationController(replicas int) ReplicationController { func makeReplicationController(replicas int) api.ReplicationController {
return ReplicationController{ return api.ReplicationController{
DesiredState: ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
Replicas: replicas, Replicas: replicas,
PodTemplate: PodTemplate{ PodTemplate: api.PodTemplate{
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Containers: []Container{ Containers: []api.Container{
{ {
Image: "foo/bar", Image: "foo/bar",
}, },
@ -72,16 +72,16 @@ func makeReplicationController(replicas int) ReplicationController {
} }
} }
func makePodList(count int) PodList { func makePodList(count int) api.PodList {
pods := []Pod{} pods := []api.Pod{}
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
pods = append(pods, Pod{ pods = append(pods, api.Pod{
JSONBase: JSONBase{ JSONBase: api.JSONBase{
ID: fmt.Sprintf("pod%d", i), ID: fmt.Sprintf("pod%d", i),
}, },
}) })
} }
return PodList{ return api.PodList{
Items: pods, Items: pods,
} }
} }
@ -102,7 +102,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {
ResponseBody: string(body), ResponseBody: string(body),
} }
testServer := httptest.NewTLSServer(&fakeHandler) testServer := httptest.NewTLSServer(&fakeHandler)
client := Client{ client := client.Client{
Host: testServer.URL, Host: testServer.URL,
} }
@ -124,7 +124,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
ResponseBody: string(body), ResponseBody: string(body),
} }
testServer := httptest.NewTLSServer(&fakeHandler) testServer := httptest.NewTLSServer(&fakeHandler)
client := Client{ client := client.Client{
Host: testServer.URL, Host: testServer.URL,
} }
@ -146,7 +146,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
ResponseBody: string(body), ResponseBody: string(body),
} }
testServer := httptest.NewTLSServer(&fakeHandler) testServer := httptest.NewTLSServer(&fakeHandler)
client := Client{ client := client.Client{
Host: testServer.URL, Host: testServer.URL,
} }
@ -168,7 +168,7 @@ func TestCreateReplica(t *testing.T) {
ResponseBody: string(body), ResponseBody: string(body),
} }
testServer := httptest.NewTLSServer(&fakeHandler) testServer := httptest.NewTLSServer(&fakeHandler)
client := Client{ client := client.Client{
Host: testServer.URL, Host: testServer.URL,
} }
@ -176,12 +176,12 @@ func TestCreateReplica(t *testing.T) {
kubeClient: client, kubeClient: client,
} }
controllerSpec := ReplicationController{ controllerSpec := api.ReplicationController{
DesiredState: ReplicationControllerState{ DesiredState: api.ReplicationControllerState{
PodTemplate: PodTemplate{ PodTemplate: api.PodTemplate{
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Containers: []Container{ Containers: []api.Container{
{ {
Image: "foo/bar", Image: "foo/bar",
}, },
@ -213,7 +213,7 @@ func TestHandleWatchResponseNotSet(t *testing.T) {
ResponseBody: string(body), ResponseBody: string(body),
} }
testServer := httptest.NewTLSServer(&fakeHandler) testServer := httptest.NewTLSServer(&fakeHandler)
client := Client{ client := client.Client{
Host: testServer.URL, Host: testServer.URL,
} }
@ -234,7 +234,7 @@ func TestHandleWatchResponseNoNode(t *testing.T) {
ResponseBody: string(body), ResponseBody: string(body),
} }
testServer := httptest.NewTLSServer(&fakeHandler) testServer := httptest.NewTLSServer(&fakeHandler)
client := Client{ client := client.Client{
Host: testServer.URL, Host: testServer.URL,
} }
@ -257,7 +257,7 @@ func TestHandleWatchResponseBadData(t *testing.T) {
ResponseBody: string(body), ResponseBody: string(body),
} }
testServer := httptest.NewTLSServer(&fakeHandler) testServer := httptest.NewTLSServer(&fakeHandler)
client := Client{ client := client.Client{
Host: testServer.URL, Host: testServer.URL,
} }
@ -283,7 +283,7 @@ func TestHandleWatchResponse(t *testing.T) {
ResponseBody: string(body), ResponseBody: string(body),
} }
testServer := httptest.NewTLSServer(&fakeHandler) testServer := httptest.NewTLSServer(&fakeHandler)
client := Client{ client := client.Client{
Host: testServer.URL, Host: testServer.URL,
} }

View File

@ -19,12 +19,12 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
// Scheduler is an interface implemented by things that know how to schedule pods onto machines. // Scheduler is an interface implemented by things that know how to schedule pods onto machines.
type Scheduler interface { type Scheduler interface {
Schedule(Pod) (string, error) Schedule(api.Pod) (string, error)
} }
// RandomScheduler choses machines uniformly at random. // RandomScheduler choses machines uniformly at random.
@ -40,7 +40,7 @@ func MakeRandomScheduler(machines []string, random rand.Rand) Scheduler {
} }
} }
func (s *RandomScheduler) Schedule(pod Pod) (string, error) { func (s *RandomScheduler) Schedule(pod api.Pod) (string, error) {
return s.machines[s.random.Int()%len(s.machines)], nil return s.machines[s.random.Int()%len(s.machines)], nil
} }
@ -57,7 +57,7 @@ func MakeRoundRobinScheduler(machines []string) Scheduler {
} }
} }
func (s *RoundRobinScheduler) Schedule(pod Pod) (string, error) { func (s *RoundRobinScheduler) Schedule(pod api.Pod) (string, error) {
result := s.machines[s.currentIndex] result := s.machines[s.currentIndex]
s.currentIndex = (s.currentIndex + 1) % len(s.machines) s.currentIndex = (s.currentIndex + 1) % len(s.machines)
return result, nil return result, nil
@ -77,7 +77,7 @@ func MakeFirstFitScheduler(machines []string, registry PodRegistry, random *rand
} }
} }
func (s *FirstFitScheduler) containsPort(pod Pod, port Port) bool { func (s *FirstFitScheduler) containsPort(pod api.Pod, port api.Port) bool {
for _, container := range pod.DesiredState.Manifest.Containers { for _, container := range pod.DesiredState.Manifest.Containers {
for _, podPort := range container.Ports { for _, podPort := range container.Ports {
if podPort.HostPort == port.HostPort { if podPort.HostPort == port.HostPort {
@ -88,8 +88,8 @@ func (s *FirstFitScheduler) containsPort(pod Pod, port Port) bool {
return false return false
} }
func (s *FirstFitScheduler) Schedule(pod Pod) (string, error) { func (s *FirstFitScheduler) Schedule(pod api.Pod) (string, error) {
machineToPods := map[string][]Pod{} machineToPods := map[string][]api.Pod{}
pods, err := s.registry.ListPods(nil) pods, err := s.registry.ListPods(nil)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -19,10 +19,10 @@ import (
"math/rand" "math/rand"
"testing" "testing"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
) )
func expectSchedule(scheduler Scheduler, pod Pod, expected string, t *testing.T) { func expectSchedule(scheduler Scheduler, pod api.Pod, expected string, t *testing.T) {
actual, err := scheduler.Schedule(pod) actual, err := scheduler.Schedule(pod)
expectNoError(t, err) expectNoError(t, err)
if actual != expected { if actual != expected {
@ -32,16 +32,16 @@ func expectSchedule(scheduler Scheduler, pod Pod, expected string, t *testing.T)
func TestRoundRobinScheduler(t *testing.T) { func TestRoundRobinScheduler(t *testing.T) {
scheduler := MakeRoundRobinScheduler([]string{"m1", "m2", "m3", "m4"}) scheduler := MakeRoundRobinScheduler([]string{"m1", "m2", "m3", "m4"})
expectSchedule(scheduler, Pod{}, "m1", t) expectSchedule(scheduler, api.Pod{}, "m1", t)
expectSchedule(scheduler, Pod{}, "m2", t) expectSchedule(scheduler, api.Pod{}, "m2", t)
expectSchedule(scheduler, Pod{}, "m3", t) expectSchedule(scheduler, api.Pod{}, "m3", t)
expectSchedule(scheduler, Pod{}, "m4", t) expectSchedule(scheduler, api.Pod{}, "m4", t)
} }
func TestRandomScheduler(t *testing.T) { func TestRandomScheduler(t *testing.T) {
random := rand.New(rand.NewSource(0)) random := rand.New(rand.NewSource(0))
scheduler := MakeRandomScheduler([]string{"m1", "m2", "m3", "m4"}, *random) scheduler := MakeRandomScheduler([]string{"m1", "m2", "m3", "m4"}, *random)
_, err := scheduler.Schedule(Pod{}) _, err := scheduler.Schedule(api.Pod{})
expectNoError(t, err) expectNoError(t, err)
} }
@ -49,21 +49,21 @@ func TestFirstFitSchedulerNothingScheduled(t *testing.T) {
mockRegistry := MockPodRegistry{} mockRegistry := MockPodRegistry{}
r := rand.New(rand.NewSource(0)) r := rand.New(rand.NewSource(0))
scheduler := MakeFirstFitScheduler([]string{"m1", "m2", "m3"}, &mockRegistry, r) scheduler := MakeFirstFitScheduler([]string{"m1", "m2", "m3"}, &mockRegistry, r)
expectSchedule(scheduler, Pod{}, "m3", t) expectSchedule(scheduler, api.Pod{}, "m3", t)
} }
func makePod(host string, hostPorts ...int) Pod { func makePod(host string, hostPorts ...int) api.Pod {
networkPorts := []Port{} networkPorts := []api.Port{}
for _, port := range hostPorts { for _, port := range hostPorts {
networkPorts = append(networkPorts, Port{HostPort: port}) networkPorts = append(networkPorts, api.Port{HostPort: port})
} }
return Pod{ return api.Pod{
CurrentState: PodState{ CurrentState: api.PodState{
Host: host, Host: host,
}, },
DesiredState: PodState{ DesiredState: api.PodState{
Manifest: ContainerManifest{ Manifest: api.ContainerManifest{
Containers: []Container{ Containers: []api.Container{
{ {
Ports: networkPorts, Ports: networkPorts,
}, },
@ -75,7 +75,7 @@ func makePod(host string, hostPorts ...int) Pod {
func TestFirstFitSchedulerFirstScheduled(t *testing.T) { func TestFirstFitSchedulerFirstScheduled(t *testing.T) {
mockRegistry := MockPodRegistry{ mockRegistry := MockPodRegistry{
pods: []Pod{ pods: []api.Pod{
makePod("m1", 8080), makePod("m1", 8080),
}, },
} }
@ -86,7 +86,7 @@ func TestFirstFitSchedulerFirstScheduled(t *testing.T) {
func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) { func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) {
mockRegistry := MockPodRegistry{ mockRegistry := MockPodRegistry{
pods: []Pod{ pods: []api.Pod{
makePod("m1", 80, 8080), makePod("m1", 80, 8080),
makePod("m2", 8081, 8082, 8083), makePod("m2", 8081, 8082, 8083),
makePod("m3", 80, 443, 8085), makePod("m3", 80, 443, 8085),
@ -99,7 +99,7 @@ func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) {
func TestFirstFitSchedulerFirstScheduledImpossible(t *testing.T) { func TestFirstFitSchedulerFirstScheduledImpossible(t *testing.T) {
mockRegistry := MockPodRegistry{ mockRegistry := MockPodRegistry{
pods: []Pod{ pods: []api.Pod{
makePod("m1", 8080), makePod("m1", 8080),
makePod("m2", 8081), makePod("m2", 8081),
makePod("m3", 8080), makePod("m3", 8080),

View File

@ -21,17 +21,17 @@ import (
"strconv" "strconv"
"strings" "strings"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver" "github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
) )
type ServiceRegistry interface { type ServiceRegistry interface {
ListServices() (ServiceList, error) ListServices() (api.ServiceList, error)
CreateService(svc Service) error CreateService(svc api.Service) error
GetService(name string) (*Service, error) GetService(name string) (*api.Service, error)
DeleteService(name string) error DeleteService(name string) error
UpdateService(svc Service) error UpdateService(svc api.Service) error
UpdateEndpoints(e Endpoints) error UpdateEndpoints(e api.Endpoints) error
} }
type ServiceRegistryStorage struct { type ServiceRegistryStorage struct {
@ -44,8 +44,8 @@ func MakeServiceRegistryStorage(registry ServiceRegistry) apiserver.RESTStorage
// GetServiceEnvironmentVariables populates a list of environment variables that are use // GetServiceEnvironmentVariables populates a list of environment variables that are use
// in the container environment to get access to services. // in the container environment to get access to services.
func GetServiceEnvironmentVariables(registry ServiceRegistry, machine string) ([]EnvVar, error) { func GetServiceEnvironmentVariables(registry ServiceRegistry, machine string) ([]api.EnvVar, error) {
var result []EnvVar var result []api.EnvVar
services, err := registry.ListServices() services, err := registry.ListServices()
if err != nil { if err != nil {
return result, err return result, err
@ -53,9 +53,9 @@ func GetServiceEnvironmentVariables(registry ServiceRegistry, machine string) ([
for _, service := range services.Items { for _, service := range services.Items {
name := strings.ToUpper(service.ID) + "_SERVICE_PORT" name := strings.ToUpper(service.ID) + "_SERVICE_PORT"
value := strconv.Itoa(service.Port) value := strconv.Itoa(service.Port)
result = append(result, EnvVar{Name: name, Value: value}) result = append(result, api.EnvVar{Name: name, Value: value})
} }
result = append(result, EnvVar{Name: "SERVICE_HOST", Value: machine}) result = append(result, api.EnvVar{Name: "SERVICE_HOST", Value: machine})
return result, nil return result, nil
} }
@ -76,16 +76,16 @@ func (sr *ServiceRegistryStorage) Delete(id string) error {
} }
func (sr *ServiceRegistryStorage) Extract(body string) (interface{}, error) { func (sr *ServiceRegistryStorage) Extract(body string) (interface{}, error) {
var svc Service var svc api.Service
err := json.Unmarshal([]byte(body), &svc) err := json.Unmarshal([]byte(body), &svc)
svc.Kind = "cluster#service" svc.Kind = "cluster#service"
return svc, err return svc, err
} }
func (sr *ServiceRegistryStorage) Create(obj interface{}) error { func (sr *ServiceRegistryStorage) Create(obj interface{}) error {
return sr.registry.CreateService(obj.(Service)) return sr.registry.CreateService(obj.(api.Service))
} }
func (sr *ServiceRegistryStorage) Update(obj interface{}) error { func (sr *ServiceRegistryStorage) Update(obj interface{}) error {
return sr.registry.UpdateService(obj.(Service)) return sr.registry.UpdateService(obj.(api.Service))
} }