fix dot import.

pull/6/head
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"
"net/url"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
)
@ -35,11 +35,11 @@ func MakeControllerRegistryStorage(registry ControllerRegistry) apiserver.RESTSt
}
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()
if err == nil {
result = ReplicationControllerList{
JSONBase: JSONBase{Kind: "cluster#replicationControllerList"},
result = api.ReplicationControllerList{
JSONBase: api.JSONBase{Kind: "cluster#replicationControllerList"},
Items: controllers,
}
}
@ -57,16 +57,16 @@ func (storage *ControllerRegistryStorage) Delete(id string) error {
}
func (storage *ControllerRegistryStorage) Extract(body string) (interface{}, error) {
result := ReplicationController{}
result := api.ReplicationController{}
err := json.Unmarshal([]byte(body), &result)
result.Kind = "cluster#replicationController"
return result, err
}
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 {
return storage.registry.UpdateController(controller.(ReplicationController))
return storage.registry.UpdateController(controller.(api.ReplicationController))
}

View File

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

View File

@ -19,7 +19,7 @@ import (
"fmt"
"log"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
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
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,
Endpoints: endpoints,
})

View File

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

View File

@ -22,7 +22,7 @@ import (
"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
@ -66,8 +66,8 @@ func makePodKey(machine, podID string) string {
return "/registry/hosts/" + machine + "/pods/" + podID
}
func (registry *EtcdRegistry) ListPods(query *map[string]string) ([]Pod, error) {
pods := []Pod{}
func (registry *EtcdRegistry) ListPods(query *map[string]string) ([]api.Pod, error) {
pods := []api.Pod{}
for _, machine := range registry.machines {
machinePods, err := registry.listPodsForMachine(machine)
if err != nil {
@ -95,12 +95,12 @@ func (registry *EtcdRegistry) listEtcdNode(key string) ([]*etcd.Node, error) {
return result.Node.Nodes, nil
}
func (registry *EtcdRegistry) listPodsForMachine(machine string) ([]Pod, error) {
pods := []Pod{}
func (registry *EtcdRegistry) listPodsForMachine(machine string) ([]api.Pod, error) {
pods := []api.Pod{}
key := "/registry/hosts/" + machine + "/pods"
nodes, err := registry.listEtcdNode(key)
for _, node := range nodes {
pod := Pod{}
pod := api.Pod{}
err = json.Unmarshal([]byte(node.Value), &pod)
if err != nil {
return pods, err
@ -111,7 +111,7 @@ func (registry *EtcdRegistry) listPodsForMachine(machine string) ([]Pod, error)
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)
return &pod, err
}
@ -120,14 +120,14 @@ func makeContainerKey(machine string) string {
return "/registry/hosts/" + machine + "/kubelet"
}
func (registry *EtcdRegistry) loadManifests(machine string) ([]ContainerManifest, error) {
var manifests []ContainerManifest
func (registry *EtcdRegistry) loadManifests(machine string) ([]api.ContainerManifest, error) {
var manifests []api.ContainerManifest
response, err := registry.etcdClient.Get(makeContainerKey(machine), false, false)
if err != nil {
if isEtcdNotFound(err) {
err = nil
manifests = []ContainerManifest{}
manifests = []api.ContainerManifest{}
}
} else {
err = json.Unmarshal([]byte(response.Node.Value), &manifests)
@ -135,7 +135,7 @@ func (registry *EtcdRegistry) loadManifests(machine string) ([]ContainerManifest
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)
if err != nil {
return err
@ -144,7 +144,7 @@ func (registry *EtcdRegistry) updateManifests(machine string, manifests []Contai
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)
if err == nil {
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)
}
func (registry *EtcdRegistry) runPod(pod Pod, machine string) error {
func (registry *EtcdRegistry) runPod(pod api.Pod, machine string) error {
manifests, err := registry.loadManifests(machine)
if err != nil {
return err
@ -173,7 +173,7 @@ func (registry *EtcdRegistry) runPod(pod Pod, machine string) error {
return registry.updateManifests(machine, manifests)
}
func (registry *EtcdRegistry) UpdatePod(pod Pod) error {
func (registry *EtcdRegistry) UpdatePod(pod api.Pod) error {
return fmt.Errorf("Unimplemented!")
}
@ -190,7 +190,7 @@ func (registry *EtcdRegistry) deletePodFromMachine(machine, podID string) error
if err != nil {
return err
}
newManifests := make([]ContainerManifest, 0)
newManifests := make([]api.ContainerManifest, 0)
found := false
for _, manifest := range manifests {
if manifest.Id != podID {
@ -213,33 +213,33 @@ func (registry *EtcdRegistry) deletePodFromMachine(machine, podID string) error
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)
result, err := registry.etcdClient.Get(key, false, false)
if err != nil {
if isEtcdNotFound(err) {
return Pod{}, fmt.Errorf("Not found (%#v).", err)
return api.Pod{}, fmt.Errorf("Not found (%#v).", err)
} else {
return Pod{}, err
return api.Pod{}, err
}
}
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)
pod.CurrentState.Host = machine
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 {
pod, err := registry.getPodForMachine(machine, podID)
if err == 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 {
@ -259,12 +259,12 @@ func isEtcdNotFound(err error) bool {
return false
}
func (registry *EtcdRegistry) ListControllers() ([]ReplicationController, error) {
var controllers []ReplicationController
func (registry *EtcdRegistry) ListControllers() ([]api.ReplicationController, error) {
var controllers []api.ReplicationController
key := "/registry/controllers"
nodes, err := registry.listEtcdNode(key)
for _, node := range nodes {
var controller ReplicationController
var controller api.ReplicationController
err = json.Unmarshal([]byte(node.Value), &controller)
if err != nil {
return controllers, err
@ -278,8 +278,8 @@ func makeControllerKey(id string) string {
return "/registry/controllers/" + id
}
func (registry *EtcdRegistry) GetController(controllerID string) (*ReplicationController, error) {
var controller ReplicationController
func (registry *EtcdRegistry) GetController(controllerID string) (*api.ReplicationController, error) {
var controller api.ReplicationController
key := makeControllerKey(controllerID)
result, err := registry.etcdClient.Get(key, false, false)
if err != nil {
@ -296,12 +296,12 @@ func (registry *EtcdRegistry) GetController(controllerID string) (*ReplicationCo
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.
return registry.UpdateController(controller)
}
func (registry *EtcdRegistry) UpdateController(controller ReplicationController) error {
func (registry *EtcdRegistry) UpdateController(controller api.ReplicationController) error {
controllerData, err := json.Marshal(controller)
if err != nil {
return err
@ -321,25 +321,25 @@ func makeServiceKey(name string) string {
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")
if err != nil {
return ServiceList{}, err
return api.ServiceList{}, err
}
var services []Service
var services []api.Service
for _, node := range nodes {
var svc Service
var svc api.Service
err := json.Unmarshal([]byte(node.Value), &svc)
if err != nil {
return ServiceList{}, err
return api.ServiceList{}, err
}
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)
data, err := json.Marshal(svc)
if err != nil {
@ -349,7 +349,7 @@ func (registry *EtcdRegistry) CreateService(svc Service) error {
return err
}
func (registry *EtcdRegistry) GetService(name string) (*Service, error) {
func (registry *EtcdRegistry) GetService(name string) (*api.Service, error) {
key := makeServiceKey(name)
response, err := registry.etcdClient.Get(key, false, false)
if err != nil {
@ -359,7 +359,7 @@ func (registry *EtcdRegistry) GetService(name string) (*Service, error) {
return nil, err
}
}
var svc Service
var svc api.Service
err = json.Unmarshal([]byte(response.Node.Value), &svc)
if err != nil {
return nil, err
@ -378,11 +378,11 @@ func (registry *EtcdRegistry) DeleteService(name string) error {
return err
}
func (registry *EtcdRegistry) UpdateService(svc Service) error {
func (registry *EtcdRegistry) UpdateService(svc api.Service) error {
return registry.CreateService(svc)
}
func (registry *EtcdRegistry) UpdateEndpoints(e Endpoints) error {
func (registry *EtcdRegistry) UpdateEndpoints(e api.Endpoints) error {
data, err := json.Marshal(e)
if err != nil {
return err

View File

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

View File

@ -16,22 +16,22 @@ limitations under the License.
package registry
import (
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
type ManifestFactory interface {
// 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 {
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)
if err != nil {
return ContainerManifest{}, err
return api.ContainerManifest{}, err
}
for ix, container := range pod.DesiredState.Manifest.Containers {
pod.DesiredState.Manifest.Id = pod.ID

View File

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

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ import (
"fmt"
"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/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'
func LabelMatch(pod Pod, queryKey, queryValue string) bool {
func LabelMatch(pod api.Pod, queryKey, queryValue string) bool {
for key, value := range pod.Labels {
if queryKey == key && queryValue == value {
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'
func LabelsMatch(pod Pod, labelQuery *map[string]string) bool {
func LabelsMatch(pod api.Pod, labelQuery *map[string]string) bool {
if labelQuery == nil {
return true
}
@ -64,7 +64,7 @@ func LabelsMatch(pod Pod, labelQuery *map[string]string) bool {
}
func (storage *PodRegistryStorage) List(url *url.URL) (interface{}, error) {
var result PodList
var result api.PodList
var query *map[string]string
if url != nil {
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)
if err == nil {
result = PodList{
result = api.PodList{
Items: pods,
}
}
@ -99,14 +99,14 @@ func (storage *PodRegistryStorage) Delete(id string) error {
}
func (storage *PodRegistryStorage) Extract(body string) (interface{}, error) {
pod := Pod{}
pod := api.Pod{}
err := json.Unmarshal([]byte(body), &pod)
pod.Kind = "cluster#pod"
return pod, err
}
func (storage *PodRegistryStorage) Create(pod interface{}) error {
podObj := pod.(Pod)
podObj := pod.(api.Pod)
if len(podObj.ID) == 0 {
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 {
return storage.registry.UpdatePod(pod.(Pod))
return storage.registry.UpdatePod(pod.(api.Pod))
}

View File

@ -21,12 +21,12 @@ import (
"reflect"
"testing"
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
type MockPodRegistry struct {
err error
pods []Pod
pods []api.Pod
}
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
}
func (registry *MockPodRegistry) GetPod(podId string) (*Pod, error) {
return &Pod{}, registry.err
func (registry *MockPodRegistry) GetPod(podId string) (*api.Pod, error) {
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
}
func (registry *MockPodRegistry) UpdatePod(pod Pod) error {
func (registry *MockPodRegistry) UpdatePod(pod api.Pod) error {
return registry.err
}
func (registry *MockPodRegistry) DeletePod(podId string) error {
@ -65,7 +65,7 @@ func TestListPodsError(t *testing.T) {
if err != mockRegistry.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)
}
}
@ -77,21 +77,21 @@ func TestListEmptyPodList(t *testing.T) {
}
pods, err := storage.List(nil)
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)
}
}
func TestListPodList(t *testing.T) {
mockRegistry := MockPodRegistry{
pods: []Pod{
pods: []api.Pod{
{
JSONBase: JSONBase{
JSONBase: api.JSONBase{
ID: "foo",
},
},
{
JSONBase: JSONBase{
JSONBase: api.JSONBase{
ID: "bar",
},
},
@ -101,7 +101,7 @@ func TestListPodList(t *testing.T) {
registry: &mockRegistry,
}
podsObj, err := storage.List(nil)
pods := podsObj.(PodList)
pods := podsObj.(api.PodList)
expectNoError(t, err)
if len(pods.Items) != 2 {
t.Errorf("Unexpected pod list: %#v", pods)
@ -119,8 +119,8 @@ func TestExtractJson(t *testing.T) {
storage := PodRegistryStorage{
registry: &mockRegistry,
}
pod := Pod{
JSONBase: JSONBase{
pod := api.Pod{
JSONBase: api.JSONBase{
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) {
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) {
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) {
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) {
t.Errorf("Unexpected match success: %#v %#v", pod, *query)
}
}
func TestLabelMatch(t *testing.T) {
pod := Pod{
pod := api.Pod{
Labels: map[string]string{
"foo": "bar",
"baz": "blah",
@ -173,7 +173,7 @@ func TestLabelMatch(t *testing.T) {
}
func TestLabelsMatch(t *testing.T) {
pod := Pod{
pod := api.Pod{
Labels: map[string]string{
"foo": "bar",
"baz": "blah",

View File

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

View File

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

View File

@ -19,12 +19,12 @@ import (
"fmt"
"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.
type Scheduler interface {
Schedule(Pod) (string, error)
Schedule(api.Pod) (string, error)
}
// 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
}
@ -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]
s.currentIndex = (s.currentIndex + 1) % len(s.machines)
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 _, podPort := range container.Ports {
if podPort.HostPort == port.HostPort {
@ -88,8 +88,8 @@ func (s *FirstFitScheduler) containsPort(pod Pod, port Port) bool {
return false
}
func (s *FirstFitScheduler) Schedule(pod Pod) (string, error) {
machineToPods := map[string][]Pod{}
func (s *FirstFitScheduler) Schedule(pod api.Pod) (string, error) {
machineToPods := map[string][]api.Pod{}
pods, err := s.registry.ListPods(nil)
if err != nil {
return "", err

View File

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

View File

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