mirror of https://github.com/k3s-io/k3s
commit
4bd809e11e
|
@ -92,11 +92,11 @@ type TaskState struct {
|
||||||
|
|
||||||
type TaskList struct {
|
type TaskList struct {
|
||||||
JSONBase
|
JSONBase
|
||||||
Items []Task `json:"items" yaml:"items,omitempty"`
|
Items []Pod `json:"items" yaml:"items,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task is a single task, used as either input (create, update) or as output (list, get)
|
// Task is a single task, used as either input (create, update) or as output (list, get)
|
||||||
type Task struct {
|
type Pod struct {
|
||||||
JSONBase
|
JSONBase
|
||||||
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
|
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
|
||||||
DesiredState TaskState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
|
DesiredState TaskState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`
|
||||||
|
|
|
@ -39,10 +39,10 @@ import (
|
||||||
// ClientInterface holds the methods for clients of Kubenetes, an interface to allow mock testing
|
// ClientInterface holds the methods for clients of Kubenetes, an interface to allow mock testing
|
||||||
type ClientInterface interface {
|
type ClientInterface interface {
|
||||||
ListTasks(labelQuery map[string]string) (api.TaskList, error)
|
ListTasks(labelQuery map[string]string) (api.TaskList, error)
|
||||||
GetTask(name string) (api.Task, error)
|
GetTask(name string) (api.Pod, error)
|
||||||
DeleteTask(name string) error
|
DeleteTask(name string) error
|
||||||
CreateTask(api.Task) (api.Task, error)
|
CreateTask(api.Pod) (api.Pod, error)
|
||||||
UpdateTask(api.Task) (api.Task, error)
|
UpdateTask(api.Pod) (api.Pod, error)
|
||||||
|
|
||||||
GetReplicationController(name string) (api.ReplicationController, error)
|
GetReplicationController(name string) (api.ReplicationController, error)
|
||||||
CreateReplicationController(api.ReplicationController) (api.ReplicationController, error)
|
CreateReplicationController(api.ReplicationController) (api.ReplicationController, error)
|
||||||
|
@ -154,8 +154,8 @@ func (client Client) ListTasks(labelQuery map[string]string) (api.TaskList, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTask takes the name of the task, and returns the corresponding Task object, and an error if it occurs
|
// GetTask takes the name of the task, and returns the corresponding Task object, and an error if it occurs
|
||||||
func (client Client) GetTask(name string) (api.Task, error) {
|
func (client Client) GetTask(name string) (api.Pod, error) {
|
||||||
var result api.Task
|
var result api.Pod
|
||||||
_, err := client.rawRequest("GET", "tasks/"+name, nil, &result)
|
_, err := client.rawRequest("GET", "tasks/"+name, nil, &result)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
@ -167,8 +167,8 @@ func (client Client) DeleteTask(name string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTask takes the representation of a task. Returns the server's representation of the task, and an error, if it occurs
|
// CreateTask takes the representation of a task. Returns the server's representation of the task, and an error, if it occurs
|
||||||
func (client Client) CreateTask(task api.Task) (api.Task, error) {
|
func (client Client) CreateTask(task api.Pod) (api.Pod, error) {
|
||||||
var result api.Task
|
var result api.Pod
|
||||||
body, err := json.Marshal(task)
|
body, err := json.Marshal(task)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_, err = client.rawRequest("POST", "tasks", bytes.NewBuffer(body), &result)
|
_, err = client.rawRequest("POST", "tasks", bytes.NewBuffer(body), &result)
|
||||||
|
@ -177,8 +177,8 @@ func (client Client) CreateTask(task api.Task) (api.Task, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateTask takes the representation of a task to update. Returns the server's representation of the task, and an error, if it occurs
|
// UpdateTask takes the representation of a task to update. Returns the server's representation of the task, and an error, if it occurs
|
||||||
func (client Client) UpdateTask(task api.Task) (api.Task, error) {
|
func (client Client) UpdateTask(task api.Pod) (api.Pod, error) {
|
||||||
var result api.Task
|
var result api.Pod
|
||||||
body, err := json.Marshal(task)
|
body, err := json.Marshal(task)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_, err = client.rawRequest("PUT", "tasks/"+task.ID, bytes.NewBuffer(body), &result)
|
_, err = client.rawRequest("PUT", "tasks/"+task.ID, bytes.NewBuffer(body), &result)
|
||||||
|
|
|
@ -62,8 +62,8 @@ func TestListEmptyTasks(t *testing.T) {
|
||||||
|
|
||||||
func TestListTasks(t *testing.T) {
|
func TestListTasks(t *testing.T) {
|
||||||
expectedTaskList := api.TaskList{
|
expectedTaskList := api.TaskList{
|
||||||
Items: []api.Task{
|
Items: []api.Pod{
|
||||||
api.Task{
|
api.Pod{
|
||||||
CurrentState: api.TaskState{
|
CurrentState: api.TaskState{
|
||||||
Status: "Foobar",
|
Status: "Foobar",
|
||||||
},
|
},
|
||||||
|
@ -96,8 +96,8 @@ func TestListTasks(t *testing.T) {
|
||||||
|
|
||||||
func TestListTasksLabels(t *testing.T) {
|
func TestListTasksLabels(t *testing.T) {
|
||||||
expectedTaskList := api.TaskList{
|
expectedTaskList := api.TaskList{
|
||||||
Items: []api.Task{
|
Items: []api.Pod{
|
||||||
api.Task{
|
api.Pod{
|
||||||
CurrentState: api.TaskState{
|
CurrentState: api.TaskState{
|
||||||
Status: "Foobar",
|
Status: "Foobar",
|
||||||
},
|
},
|
||||||
|
@ -137,7 +137,7 @@ func TestListTasksLabels(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTask(t *testing.T) {
|
func TestGetTask(t *testing.T) {
|
||||||
expectedTask := api.Task{
|
expectedTask := api.Pod{
|
||||||
CurrentState: api.TaskState{
|
CurrentState: api.TaskState{
|
||||||
Status: "Foobar",
|
Status: "Foobar",
|
||||||
},
|
},
|
||||||
|
@ -184,7 +184,7 @@ func TestDeleteTask(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateTask(t *testing.T) {
|
func TestCreateTask(t *testing.T) {
|
||||||
requestTask := api.Task{
|
requestTask := api.Pod{
|
||||||
CurrentState: api.TaskState{
|
CurrentState: api.TaskState{
|
||||||
Status: "Foobar",
|
Status: "Foobar",
|
||||||
},
|
},
|
||||||
|
@ -214,7 +214,7 @@ func TestCreateTask(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateTask(t *testing.T) {
|
func TestUpdateTask(t *testing.T) {
|
||||||
requestTask := api.Task{
|
requestTask := api.Pod{
|
||||||
JSONBase: api.JSONBase{ID: "foo"},
|
JSONBase: api.JSONBase{ID: "foo"},
|
||||||
CurrentState: api.TaskState{
|
CurrentState: api.TaskState{
|
||||||
Status: "Foobar",
|
Status: "Foobar",
|
||||||
|
|
|
@ -49,9 +49,9 @@ func (client *FakeKubeClient) ListTasks(labelQuery map[string]string) (TaskList,
|
||||||
return client.tasks, nil
|
return client.tasks, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *FakeKubeClient) GetTask(name string) (Task, error) {
|
func (client *FakeKubeClient) GetTask(name string) (Pod, error) {
|
||||||
client.actions = append(client.actions, Action{action: "get-task", value: name})
|
client.actions = append(client.actions, Action{action: "get-task", value: name})
|
||||||
return Task{}, nil
|
return Pod{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *FakeKubeClient) DeleteTask(name string) error {
|
func (client *FakeKubeClient) DeleteTask(name string) error {
|
||||||
|
@ -59,14 +59,14 @@ func (client *FakeKubeClient) DeleteTask(name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *FakeKubeClient) CreateTask(task Task) (Task, error) {
|
func (client *FakeKubeClient) CreateTask(task Pod) (Pod, error) {
|
||||||
client.actions = append(client.actions, Action{action: "create-task"})
|
client.actions = append(client.actions, Action{action: "create-task"})
|
||||||
return Task{}, nil
|
return Pod{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *FakeKubeClient) UpdateTask(task Task) (Task, error) {
|
func (client *FakeKubeClient) UpdateTask(task Pod) (Pod, error) {
|
||||||
client.actions = append(client.actions, Action{action: "update-task", value: task.ID})
|
client.actions = append(client.actions, Action{action: "update-task", value: task.ID})
|
||||||
return Task{}, nil
|
return Pod{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *FakeKubeClient) GetReplicationController(name string) (ReplicationController, error) {
|
func (client *FakeKubeClient) GetReplicationController(name string) (ReplicationController, error) {
|
||||||
|
@ -118,9 +118,9 @@ func validateAction(expectedAction, actualAction Action, t *testing.T) {
|
||||||
func TestUpdateWithTasks(t *testing.T) {
|
func TestUpdateWithTasks(t *testing.T) {
|
||||||
client := FakeKubeClient{
|
client := FakeKubeClient{
|
||||||
tasks: TaskList{
|
tasks: TaskList{
|
||||||
Items: []Task{
|
Items: []Pod{
|
||||||
Task{JSONBase: JSONBase{ID: "task-1"}},
|
Pod{JSONBase: JSONBase{ID: "task-1"}},
|
||||||
Task{JSONBase: JSONBase{ID: "task-2"}},
|
Pod{JSONBase: JSONBase{ID: "task-2"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ func TestRequestWithBodyNoSuchFile(t *testing.T) {
|
||||||
func TestRequestWithBody(t *testing.T) {
|
func TestRequestWithBody(t *testing.T) {
|
||||||
file, err := ioutil.TempFile("", "foo")
|
file, err := ioutil.TempFile("", "foo")
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
data, err := json.Marshal(Task{JSONBase: JSONBase{ID: "foo"}})
|
data, err := json.Marshal(Pod{JSONBase: JSONBase{ID: "foo"}})
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
_, err = file.Write(data)
|
_, err = file.Write(data)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
|
|
|
@ -57,8 +57,8 @@ func TestSyncEndpointsItems(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
taskRegistry := MockTaskRegistry{
|
taskRegistry := MockTaskRegistry{
|
||||||
tasks: []Task{
|
tasks: []Pod{
|
||||||
Task{
|
Pod{
|
||||||
DesiredState: TaskState{
|
DesiredState: TaskState{
|
||||||
Manifest: ContainerManifest{
|
Manifest: ContainerManifest{
|
||||||
Containers: []Container{
|
Containers: []Container{
|
||||||
|
|
|
@ -66,8 +66,8 @@ func makeTaskKey(machine, taskID string) string {
|
||||||
return "/registry/hosts/" + machine + "/tasks/" + taskID
|
return "/registry/hosts/" + machine + "/tasks/" + taskID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *EtcdRegistry) ListTasks(query *map[string]string) ([]Task, error) {
|
func (registry *EtcdRegistry) ListTasks(query *map[string]string) ([]Pod, error) {
|
||||||
tasks := []Task{}
|
tasks := []Pod{}
|
||||||
for _, machine := range registry.machines {
|
for _, machine := range registry.machines {
|
||||||
machineTasks, err := registry.listTasksForMachine(machine)
|
machineTasks, err := registry.listTasksForMachine(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) listTasksForMachine(machine string) ([]Task, error) {
|
func (registry *EtcdRegistry) listTasksForMachine(machine string) ([]Pod, error) {
|
||||||
tasks := []Task{}
|
tasks := []Pod{}
|
||||||
key := "/registry/hosts/" + machine + "/tasks"
|
key := "/registry/hosts/" + machine + "/tasks"
|
||||||
nodes, err := registry.listEtcdNode(key)
|
nodes, err := registry.listEtcdNode(key)
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
task := Task{}
|
task := Pod{}
|
||||||
err = json.Unmarshal([]byte(node.Value), &task)
|
err = json.Unmarshal([]byte(node.Value), &task)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tasks, err
|
return tasks, err
|
||||||
|
@ -111,7 +111,7 @@ func (registry *EtcdRegistry) listTasksForMachine(machine string) ([]Task, error
|
||||||
return tasks, err
|
return tasks, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *EtcdRegistry) GetTask(taskID string) (*Task, error) {
|
func (registry *EtcdRegistry) GetTask(taskID string) (*Pod, error) {
|
||||||
task, _, err := registry.findTask(taskID)
|
task, _, err := registry.findTask(taskID)
|
||||||
return &task, err
|
return &task, err
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ func (registry *EtcdRegistry) updateManifests(machine string, manifests []Contai
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *EtcdRegistry) CreateTask(machineIn string, task Task) error {
|
func (registry *EtcdRegistry) CreateTask(machineIn string, task Pod) error {
|
||||||
taskOut, machine, err := registry.findTask(task.ID)
|
taskOut, machine, err := registry.findTask(task.ID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return fmt.Errorf("A task named %s already exists on %s (%#v)", task.ID, machine, taskOut)
|
return fmt.Errorf("A task named %s already exists on %s (%#v)", task.ID, machine, taskOut)
|
||||||
|
@ -152,7 +152,7 @@ func (registry *EtcdRegistry) CreateTask(machineIn string, task Task) error {
|
||||||
return registry.runTask(task, machineIn)
|
return registry.runTask(task, machineIn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *EtcdRegistry) runTask(task Task, machine string) error {
|
func (registry *EtcdRegistry) runTask(task 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) runTask(task Task, machine string) error {
|
||||||
return registry.updateManifests(machine, manifests)
|
return registry.updateManifests(machine, manifests)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *EtcdRegistry) UpdateTask(task Task) error {
|
func (registry *EtcdRegistry) UpdateTask(task Pod) error {
|
||||||
return fmt.Errorf("Unimplemented!")
|
return fmt.Errorf("Unimplemented!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,33 +213,33 @@ func (registry *EtcdRegistry) deleteTaskFromMachine(machine, taskID string) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *EtcdRegistry) getTaskForMachine(machine, taskID string) (Task, error) {
|
func (registry *EtcdRegistry) getTaskForMachine(machine, taskID string) (Pod, error) {
|
||||||
key := makeTaskKey(machine, taskID)
|
key := makeTaskKey(machine, taskID)
|
||||||
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 Task{}, fmt.Errorf("Not found (%#v).", err)
|
return Pod{}, fmt.Errorf("Not found (%#v).", err)
|
||||||
} else {
|
} else {
|
||||||
return Task{}, err
|
return Pod{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if result.Node == nil || len(result.Node.Value) == 0 {
|
if result.Node == nil || len(result.Node.Value) == 0 {
|
||||||
return Task{}, fmt.Errorf("no nodes field: %#v", result)
|
return Pod{}, fmt.Errorf("no nodes field: %#v", result)
|
||||||
}
|
}
|
||||||
task := Task{}
|
task := Pod{}
|
||||||
err = json.Unmarshal([]byte(result.Node.Value), &task)
|
err = json.Unmarshal([]byte(result.Node.Value), &task)
|
||||||
task.CurrentState.Host = machine
|
task.CurrentState.Host = machine
|
||||||
return task, err
|
return task, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *EtcdRegistry) findTask(taskID string) (Task, string, error) {
|
func (registry *EtcdRegistry) findTask(taskID string) (Pod, string, error) {
|
||||||
for _, machine := range registry.machines {
|
for _, machine := range registry.machines {
|
||||||
task, err := registry.getTaskForMachine(machine, taskID)
|
task, err := registry.getTaskForMachine(machine, taskID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return task, machine, nil
|
return task, machine, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Task{}, "", fmt.Errorf("Task not found %s", taskID)
|
return Pod{}, "", fmt.Errorf("Task not found %s", taskID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isEtcdNotFound(err error) bool {
|
func isEtcdNotFound(err error) bool {
|
||||||
|
|
|
@ -27,7 +27,7 @@ import (
|
||||||
|
|
||||||
func TestEtcdGetTask(t *testing.T) {
|
func TestEtcdGetTask(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := MakeFakeEtcdClient(t)
|
||||||
fakeClient.Set("/registry/hosts/machine/tasks/foo", util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}), 0)
|
fakeClient.Set("/registry/hosts/machine/tasks/foo", util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), 0)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
task, err := registry.GetTask("foo")
|
task, err := registry.GetTask("foo")
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
|
@ -63,7 +63,7 @@ func TestEtcdCreateTask(t *testing.T) {
|
||||||
}
|
}
|
||||||
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{}), 0)
|
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{}), 0)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreateTask("machine", Task{
|
err := registry.CreateTask("machine", Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
|
@ -80,7 +80,7 @@ func TestEtcdCreateTask(t *testing.T) {
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
resp, err := fakeClient.Get("/registry/hosts/machine/tasks/foo", false, false)
|
resp, err := fakeClient.Get("/registry/hosts/machine/tasks/foo", false, false)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
var task Task
|
var task Pod
|
||||||
err = json.Unmarshal([]byte(resp.Node.Value), &task)
|
err = json.Unmarshal([]byte(resp.Node.Value), &task)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
if task.ID != "foo" {
|
if task.ID != "foo" {
|
||||||
|
@ -100,13 +100,13 @@ func TestEtcdCreateTaskAlreadyExisting(t *testing.T) {
|
||||||
fakeClient.Data["/registry/hosts/machine/tasks/foo"] = EtcdResponseWithError{
|
fakeClient.Data["/registry/hosts/machine/tasks/foo"] = EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: &etcd.Node{
|
Node: &etcd.Node{
|
||||||
Value: util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}),
|
Value: util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
E: nil,
|
E: nil,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreateTask("machine", Task{
|
err := registry.CreateTask("machine", Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
|
@ -131,7 +131,7 @@ func TestEtcdCreateTaskWithContainersError(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.CreateTask("machine", Task{
|
err := registry.CreateTask("machine", Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
|
@ -163,7 +163,7 @@ func TestEtcdCreateTaskWithContainersNotFound(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.CreateTask("machine", Task{
|
err := registry.CreateTask("machine", Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
|
@ -181,7 +181,7 @@ func TestEtcdCreateTaskWithContainersNotFound(t *testing.T) {
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
resp, err := fakeClient.Get("/registry/hosts/machine/tasks/foo", false, false)
|
resp, err := fakeClient.Get("/registry/hosts/machine/tasks/foo", false, false)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
var task Task
|
var task Pod
|
||||||
err = json.Unmarshal([]byte(resp.Node.Value), &task)
|
err = json.Unmarshal([]byte(resp.Node.Value), &task)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
if task.ID != "foo" {
|
if task.ID != "foo" {
|
||||||
|
@ -210,7 +210,7 @@ func TestEtcdCreateTaskWithExistingContainers(t *testing.T) {
|
||||||
},
|
},
|
||||||
}), 0)
|
}), 0)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreateTask("machine", Task{
|
err := registry.CreateTask("machine", Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
|
@ -228,7 +228,7 @@ func TestEtcdCreateTaskWithExistingContainers(t *testing.T) {
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
resp, err := fakeClient.Get("/registry/hosts/machine/tasks/foo", false, false)
|
resp, err := fakeClient.Get("/registry/hosts/machine/tasks/foo", false, false)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
var task Task
|
var task Pod
|
||||||
err = json.Unmarshal([]byte(resp.Node.Value), &task)
|
err = json.Unmarshal([]byte(resp.Node.Value), &task)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
if task.ID != "foo" {
|
if task.ID != "foo" {
|
||||||
|
@ -246,7 +246,7 @@ func TestEtcdCreateTaskWithExistingContainers(t *testing.T) {
|
||||||
func TestEtcdDeleteTask(t *testing.T) {
|
func TestEtcdDeleteTask(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := MakeFakeEtcdClient(t)
|
||||||
key := "/registry/hosts/machine/tasks/foo"
|
key := "/registry/hosts/machine/tasks/foo"
|
||||||
fakeClient.Set(key, util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}), 0)
|
fakeClient.Set(key, util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), 0)
|
||||||
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{
|
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{
|
||||||
ContainerManifest{
|
ContainerManifest{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
|
@ -270,7 +270,7 @@ func TestEtcdDeleteTask(t *testing.T) {
|
||||||
func TestEtcdDeleteTaskMultipleContainers(t *testing.T) {
|
func TestEtcdDeleteTaskMultipleContainers(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := MakeFakeEtcdClient(t)
|
||||||
key := "/registry/hosts/machine/tasks/foo"
|
key := "/registry/hosts/machine/tasks/foo"
|
||||||
fakeClient.Set(key, util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}), 0)
|
fakeClient.Set(key, util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), 0)
|
||||||
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{
|
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{
|
||||||
ContainerManifest{Id: "foo"},
|
ContainerManifest{Id: "foo"},
|
||||||
ContainerManifest{Id: "bar"},
|
ContainerManifest{Id: "bar"},
|
||||||
|
@ -337,10 +337,10 @@ func TestEtcdListTasks(t *testing.T) {
|
||||||
Node: &etcd.Node{
|
Node: &etcd.Node{
|
||||||
Nodes: []*etcd.Node{
|
Nodes: []*etcd.Node{
|
||||||
&etcd.Node{
|
&etcd.Node{
|
||||||
Value: util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}),
|
Value: util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}),
|
||||||
},
|
},
|
||||||
&etcd.Node{
|
&etcd.Node{
|
||||||
Value: util.MakeJSONString(Task{JSONBase: JSONBase{ID: "bar"}}),
|
Value: util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "bar"}}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,13 +23,13 @@ import (
|
||||||
type TaskRegistry interface {
|
type TaskRegistry interface {
|
||||||
// ListTasks obtains a list of tasks that match query.
|
// ListTasks obtains a list of tasks that match query.
|
||||||
// Query may be nil in which case all tasks are returned.
|
// Query may be nil in which case all tasks are returned.
|
||||||
ListTasks(query *map[string]string) ([]api.Task, error)
|
ListTasks(query *map[string]string) ([]api.Pod, error)
|
||||||
// Get a specific task
|
// Get a specific task
|
||||||
GetTask(taskId string) (*api.Task, error)
|
GetTask(taskId string) (*api.Pod, error)
|
||||||
// Create a task based on a specification, schedule it onto a specific machine.
|
// Create a task based on a specification, schedule it onto a specific machine.
|
||||||
CreateTask(machine string, task api.Task) error
|
CreateTask(machine string, task api.Pod) error
|
||||||
// Update an existing task
|
// Update an existing task
|
||||||
UpdateTask(task api.Task) error
|
UpdateTask(task api.Pod) error
|
||||||
// Delete an existing task
|
// Delete an existing task
|
||||||
DeleteTask(taskId string) error
|
DeleteTask(taskId string) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,14 @@ import (
|
||||||
|
|
||||||
type ManifestFactory interface {
|
type ManifestFactory interface {
|
||||||
// Make a container object for a given task, given the machine that the task is running on.
|
// Make a container object for a given task, given the machine that the task is running on.
|
||||||
MakeManifest(machine string, task Task) (ContainerManifest, error)
|
MakeManifest(machine string, task Pod) (ContainerManifest, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type BasicManifestFactory struct {
|
type BasicManifestFactory struct {
|
||||||
serviceRegistry ServiceRegistry
|
serviceRegistry ServiceRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BasicManifestFactory) MakeManifest(machine string, task Task) (ContainerManifest, error) {
|
func (b *BasicManifestFactory) MakeManifest(machine string, task Pod) (ContainerManifest, error) {
|
||||||
envVars, err := GetServiceEnvironmentVariables(b.serviceRegistry, machine)
|
envVars, err := GetServiceEnvironmentVariables(b.serviceRegistry, machine)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ContainerManifest{}, err
|
return ContainerManifest{}, err
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestMakeManifestNoServices(t *testing.T) {
|
||||||
serviceRegistry: ®istry,
|
serviceRegistry: ®istry,
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest, err := factory.MakeManifest("machine", Task{
|
manifest, err := factory.MakeManifest("machine", Pod{
|
||||||
JSONBase: JSONBase{ID: "foobar"},
|
JSONBase: JSONBase{ID: "foobar"},
|
||||||
DesiredState: TaskState{
|
DesiredState: TaskState{
|
||||||
Manifest: ContainerManifest{
|
Manifest: ContainerManifest{
|
||||||
|
@ -66,7 +66,7 @@ func TestMakeManifestServices(t *testing.T) {
|
||||||
serviceRegistry: ®istry,
|
serviceRegistry: ®istry,
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest, err := factory.MakeManifest("machine", Task{
|
manifest, err := factory.MakeManifest("machine", Pod{
|
||||||
DesiredState: TaskState{
|
DesiredState: TaskState{
|
||||||
Manifest: ContainerManifest{
|
Manifest: ContainerManifest{
|
||||||
Containers: []Container{
|
Containers: []Container{
|
||||||
|
@ -103,7 +103,7 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
|
||||||
serviceRegistry: ®istry,
|
serviceRegistry: ®istry,
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest, err := factory.MakeManifest("machine", Task{
|
manifest, err := factory.MakeManifest("machine", Pod{
|
||||||
DesiredState: TaskState{
|
DesiredState: TaskState{
|
||||||
Manifest: ContainerManifest{
|
Manifest: ContainerManifest{
|
||||||
Containers: []Container{
|
Containers: []Container{
|
||||||
|
|
|
@ -22,21 +22,21 @@ import (
|
||||||
// An implementation of TaskRegistry and ControllerRegistry that is backed by memory
|
// An implementation of TaskRegistry and ControllerRegistry that is backed by memory
|
||||||
// Mainly used for testing.
|
// Mainly used for testing.
|
||||||
type MemoryRegistry struct {
|
type MemoryRegistry struct {
|
||||||
taskData map[string]Task
|
taskData map[string]Pod
|
||||||
controllerData map[string]ReplicationController
|
controllerData map[string]ReplicationController
|
||||||
serviceData map[string]Service
|
serviceData map[string]Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeMemoryRegistry() *MemoryRegistry {
|
func MakeMemoryRegistry() *MemoryRegistry {
|
||||||
return &MemoryRegistry{
|
return &MemoryRegistry{
|
||||||
taskData: map[string]Task{},
|
taskData: map[string]Pod{},
|
||||||
controllerData: map[string]ReplicationController{},
|
controllerData: map[string]ReplicationController{},
|
||||||
serviceData: map[string]Service{},
|
serviceData: map[string]Service{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MemoryRegistry) ListTasks(labelQuery *map[string]string) ([]Task, error) {
|
func (registry *MemoryRegistry) ListTasks(labelQuery *map[string]string) ([]Pod, error) {
|
||||||
result := []Task{}
|
result := []Pod{}
|
||||||
for _, value := range registry.taskData {
|
for _, value := range registry.taskData {
|
||||||
if LabelsMatch(value, labelQuery) {
|
if LabelsMatch(value, labelQuery) {
|
||||||
result = append(result, value)
|
result = append(result, value)
|
||||||
|
@ -45,7 +45,7 @@ func (registry *MemoryRegistry) ListTasks(labelQuery *map[string]string) ([]Task
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MemoryRegistry) GetTask(taskID string) (*Task, error) {
|
func (registry *MemoryRegistry) GetTask(taskID string) (*Pod, error) {
|
||||||
task, found := registry.taskData[taskID]
|
task, found := registry.taskData[taskID]
|
||||||
if found {
|
if found {
|
||||||
return &task, nil
|
return &task, nil
|
||||||
|
@ -54,7 +54,7 @@ func (registry *MemoryRegistry) GetTask(taskID string) (*Task, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MemoryRegistry) CreateTask(machine string, task Task) error {
|
func (registry *MemoryRegistry) CreateTask(machine string, task Pod) error {
|
||||||
registry.taskData[task.ID] = task
|
registry.taskData[task.ID] = task
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ func (registry *MemoryRegistry) DeleteTask(taskID string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MemoryRegistry) UpdateTask(task Task) error {
|
func (registry *MemoryRegistry) UpdateTask(task Pod) error {
|
||||||
registry.taskData[task.ID] = task
|
registry.taskData[task.ID] = task
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ func TestListTasksEmpty(t *testing.T) {
|
||||||
|
|
||||||
func TestMemoryListTasks(t *testing.T) {
|
func TestMemoryListTasks(t *testing.T) {
|
||||||
registry := MakeMemoryRegistry()
|
registry := MakeMemoryRegistry()
|
||||||
registry.CreateTask("machine", Task{JSONBase: JSONBase{ID: "foo"}})
|
registry.CreateTask("machine", Pod{JSONBase: JSONBase{ID: "foo"}})
|
||||||
tasks, err := registry.ListTasks(nil)
|
tasks, err := registry.ListTasks(nil)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
if len(tasks) != 1 || tasks[0].ID != "foo" {
|
if len(tasks) != 1 || tasks[0].ID != "foo" {
|
||||||
|
@ -42,7 +42,7 @@ func TestMemoryListTasks(t *testing.T) {
|
||||||
|
|
||||||
func TestMemorySetGetTasks(t *testing.T) {
|
func TestMemorySetGetTasks(t *testing.T) {
|
||||||
registry := MakeMemoryRegistry()
|
registry := MakeMemoryRegistry()
|
||||||
expectedTask := Task{JSONBase: JSONBase{ID: "foo"}}
|
expectedTask := Pod{JSONBase: JSONBase{ID: "foo"}}
|
||||||
registry.CreateTask("machine", expectedTask)
|
registry.CreateTask("machine", expectedTask)
|
||||||
task, err := registry.GetTask("foo")
|
task, err := registry.GetTask("foo")
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
|
@ -53,8 +53,8 @@ func TestMemorySetGetTasks(t *testing.T) {
|
||||||
|
|
||||||
func TestMemorySetUpdateGetTasks(t *testing.T) {
|
func TestMemorySetUpdateGetTasks(t *testing.T) {
|
||||||
registry := MakeMemoryRegistry()
|
registry := MakeMemoryRegistry()
|
||||||
oldTask := Task{JSONBase: JSONBase{ID: "foo"}}
|
oldTask := Pod{JSONBase: JSONBase{ID: "foo"}}
|
||||||
expectedTask := Task{
|
expectedTask := Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
|
@ -73,7 +73,7 @@ func TestMemorySetUpdateGetTasks(t *testing.T) {
|
||||||
|
|
||||||
func TestMemorySetDeleteGetTasks(t *testing.T) {
|
func TestMemorySetDeleteGetTasks(t *testing.T) {
|
||||||
registry := MakeMemoryRegistry()
|
registry := MakeMemoryRegistry()
|
||||||
expectedTask := Task{JSONBase: JSONBase{ID: "foo"}}
|
expectedTask := Pod{JSONBase: JSONBase{ID: "foo"}}
|
||||||
registry.CreateTask("machine", expectedTask)
|
registry.CreateTask("machine", expectedTask)
|
||||||
registry.DeleteTask("foo")
|
registry.DeleteTask("foo")
|
||||||
task, err := registry.GetTask("foo")
|
task, err := registry.GetTask("foo")
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (r RealTaskControl) createReplica(controllerSpec ReplicationController) {
|
||||||
if labels != nil {
|
if labels != nil {
|
||||||
labels["replicationController"] = controllerSpec.ID
|
labels["replicationController"] = controllerSpec.ID
|
||||||
}
|
}
|
||||||
task := Task{
|
task := Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: fmt.Sprintf("%x", rand.Int()),
|
ID: fmt.Sprintf("%x", rand.Int()),
|
||||||
},
|
},
|
||||||
|
@ -118,8 +118,8 @@ func (rm *ReplicationManager) handleWatchResponse(response *etcd.Response) (*Rep
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rm *ReplicationManager) filterActiveTasks(tasks []Task) []Task {
|
func (rm *ReplicationManager) filterActiveTasks(tasks []Pod) []Pod {
|
||||||
var result []Task
|
var result []Pod
|
||||||
for _, value := range tasks {
|
for _, value := range tasks {
|
||||||
if strings.Index(value.CurrentState.Status, "Exit") == -1 {
|
if strings.Index(value.CurrentState.Status, "Exit") == -1 {
|
||||||
result = append(result, value)
|
result = append(result, value)
|
||||||
|
|
|
@ -73,9 +73,9 @@ func makeReplicationController(replicas int) ReplicationController {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTaskList(count int) TaskList {
|
func makeTaskList(count int) TaskList {
|
||||||
tasks := []Task{}
|
tasks := []Pod{}
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
tasks = append(tasks, Task{
|
tasks = append(tasks, Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: fmt.Sprintf("task%d", i),
|
ID: fmt.Sprintf("task%d", i),
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,7 +24,7 @@ import (
|
||||||
|
|
||||||
// Scheduler is an interface implemented by things that know how to schedule tasks onto machines.
|
// Scheduler is an interface implemented by things that know how to schedule tasks onto machines.
|
||||||
type Scheduler interface {
|
type Scheduler interface {
|
||||||
Schedule(Task) (string, error)
|
Schedule(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(task Task) (string, error) {
|
func (s *RandomScheduler) Schedule(task 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(task Task) (string, error) {
|
func (s *RoundRobinScheduler) Schedule(task 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
|
||||||
|
@ -75,7 +75,7 @@ func MakeFirstFitScheduler(machines []string, registry TaskRegistry) Scheduler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FirstFitScheduler) containsPort(task Task, port Port) bool {
|
func (s *FirstFitScheduler) containsPort(task Pod, port Port) bool {
|
||||||
for _, container := range task.DesiredState.Manifest.Containers {
|
for _, container := range task.DesiredState.Manifest.Containers {
|
||||||
for _, taskPort := range container.Ports {
|
for _, taskPort := range container.Ports {
|
||||||
if taskPort.HostPort == port.HostPort {
|
if taskPort.HostPort == port.HostPort {
|
||||||
|
@ -86,8 +86,8 @@ func (s *FirstFitScheduler) containsPort(task Task, port Port) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FirstFitScheduler) Schedule(task Task) (string, error) {
|
func (s *FirstFitScheduler) Schedule(task Pod) (string, error) {
|
||||||
machineToTasks := map[string][]Task{}
|
machineToTasks := map[string][]Pod{}
|
||||||
tasks, err := s.registry.ListTasks(nil)
|
tasks, err := s.registry.ListTasks(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
@ -22,7 +22,7 @@ import (
|
||||||
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func expectSchedule(scheduler Scheduler, task Task, expected string, t *testing.T) {
|
func expectSchedule(scheduler Scheduler, task Pod, expected string, t *testing.T) {
|
||||||
actual, err := scheduler.Schedule(task)
|
actual, err := scheduler.Schedule(task)
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
if actual != expected {
|
if actual != expected {
|
||||||
|
@ -32,31 +32,31 @@ func expectSchedule(scheduler Scheduler, task Task, expected string, t *testing.
|
||||||
|
|
||||||
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, Task{}, "m1", t)
|
expectSchedule(scheduler, Pod{}, "m1", t)
|
||||||
expectSchedule(scheduler, Task{}, "m2", t)
|
expectSchedule(scheduler, Pod{}, "m2", t)
|
||||||
expectSchedule(scheduler, Task{}, "m3", t)
|
expectSchedule(scheduler, Pod{}, "m3", t)
|
||||||
expectSchedule(scheduler, Task{}, "m4", t)
|
expectSchedule(scheduler, 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(Task{})
|
_, err := scheduler.Schedule(Pod{})
|
||||||
expectNoError(t, err)
|
expectNoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFirstFitSchedulerNothingScheduled(t *testing.T) {
|
func TestFirstFitSchedulerNothingScheduled(t *testing.T) {
|
||||||
mockRegistry := MockTaskRegistry{}
|
mockRegistry := MockTaskRegistry{}
|
||||||
scheduler := MakeFirstFitScheduler([]string{"m1", "m2", "m3"}, &mockRegistry)
|
scheduler := MakeFirstFitScheduler([]string{"m1", "m2", "m3"}, &mockRegistry)
|
||||||
expectSchedule(scheduler, Task{}, "m1", t)
|
expectSchedule(scheduler, Pod{}, "m1", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTask(host string, hostPorts ...int) Task {
|
func makeTask(host string, hostPorts ...int) Pod {
|
||||||
networkPorts := []Port{}
|
networkPorts := []Port{}
|
||||||
for _, port := range hostPorts {
|
for _, port := range hostPorts {
|
||||||
networkPorts = append(networkPorts, Port{HostPort: port})
|
networkPorts = append(networkPorts, Port{HostPort: port})
|
||||||
}
|
}
|
||||||
return Task{
|
return Pod{
|
||||||
CurrentState: TaskState{
|
CurrentState: TaskState{
|
||||||
Host: host,
|
Host: host,
|
||||||
},
|
},
|
||||||
|
@ -74,7 +74,7 @@ func makeTask(host string, hostPorts ...int) Task {
|
||||||
|
|
||||||
func TestFirstFitSchedulerFirstScheduled(t *testing.T) {
|
func TestFirstFitSchedulerFirstScheduled(t *testing.T) {
|
||||||
mockRegistry := MockTaskRegistry{
|
mockRegistry := MockTaskRegistry{
|
||||||
tasks: []Task{
|
tasks: []Pod{
|
||||||
makeTask("m1", 8080),
|
makeTask("m1", 8080),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ func TestFirstFitSchedulerFirstScheduled(t *testing.T) {
|
||||||
|
|
||||||
func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) {
|
func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) {
|
||||||
mockRegistry := MockTaskRegistry{
|
mockRegistry := MockTaskRegistry{
|
||||||
tasks: []Task{
|
tasks: []Pod{
|
||||||
makeTask("m1", 80, 8080),
|
makeTask("m1", 80, 8080),
|
||||||
makeTask("m2", 8081, 8082, 8083),
|
makeTask("m2", 8081, 8082, 8083),
|
||||||
makeTask("m3", 80, 443, 8085),
|
makeTask("m3", 80, 443, 8085),
|
||||||
|
@ -96,7 +96,7 @@ func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) {
|
||||||
|
|
||||||
func TestFirstFitSchedulerFirstScheduledImpossible(t *testing.T) {
|
func TestFirstFitSchedulerFirstScheduledImpossible(t *testing.T) {
|
||||||
mockRegistry := MockTaskRegistry{
|
mockRegistry := MockTaskRegistry{
|
||||||
tasks: []Task{
|
tasks: []Pod{
|
||||||
makeTask("m1", 8080),
|
makeTask("m1", 8080),
|
||||||
makeTask("m2", 8081),
|
makeTask("m2", 8081),
|
||||||
makeTask("m3", 8080),
|
makeTask("m3", 8080),
|
||||||
|
|
|
@ -41,7 +41,7 @@ func MakeTaskRegistryStorage(registry TaskRegistry, containerInfo client.Contain
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelMatch tests to see if a Task's labels map contains 'key' mapping to 'value'
|
// LabelMatch tests to see if a Task's labels map contains 'key' mapping to 'value'
|
||||||
func LabelMatch(task Task, queryKey, queryValue string) bool {
|
func LabelMatch(task Pod, queryKey, queryValue string) bool {
|
||||||
for key, value := range task.Labels {
|
for key, value := range task.Labels {
|
||||||
if queryKey == key && queryValue == value {
|
if queryKey == key && queryValue == value {
|
||||||
return true
|
return true
|
||||||
|
@ -51,7 +51,7 @@ func LabelMatch(task Task, queryKey, queryValue string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelMatch tests to see if a Task's labels map contains all key/value pairs in 'labelQuery'
|
// LabelMatch tests to see if a Task's labels map contains all key/value pairs in 'labelQuery'
|
||||||
func LabelsMatch(task Task, labelQuery *map[string]string) bool {
|
func LabelsMatch(task Pod, labelQuery *map[string]string) bool {
|
||||||
if labelQuery == nil {
|
if labelQuery == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -99,13 +99,13 @@ func (storage *TaskRegistryStorage) Delete(id string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage *TaskRegistryStorage) Extract(body string) (interface{}, error) {
|
func (storage *TaskRegistryStorage) Extract(body string) (interface{}, error) {
|
||||||
task := Task{}
|
task := Pod{}
|
||||||
err := json.Unmarshal([]byte(body), &task)
|
err := json.Unmarshal([]byte(body), &task)
|
||||||
return task, err
|
return task, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage *TaskRegistryStorage) Create(task interface{}) error {
|
func (storage *TaskRegistryStorage) Create(task interface{}) error {
|
||||||
taskObj := task.(Task)
|
taskObj := task.(Pod)
|
||||||
if len(taskObj.ID) == 0 {
|
if len(taskObj.ID) == 0 {
|
||||||
return fmt.Errorf("ID is unspecified: %#v", task)
|
return fmt.Errorf("ID is unspecified: %#v", task)
|
||||||
}
|
}
|
||||||
|
@ -117,5 +117,5 @@ func (storage *TaskRegistryStorage) Create(task interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage *TaskRegistryStorage) Update(task interface{}) error {
|
func (storage *TaskRegistryStorage) Update(task interface{}) error {
|
||||||
return storage.registry.UpdateTask(task.(Task))
|
return storage.registry.UpdateTask(task.(Pod))
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
|
|
||||||
type MockTaskRegistry struct {
|
type MockTaskRegistry struct {
|
||||||
err error
|
err error
|
||||||
tasks []Task
|
tasks []Pod
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectNoError(t *testing.T, err error) {
|
func expectNoError(t *testing.T, err error) {
|
||||||
|
@ -34,19 +34,19 @@ func expectNoError(t *testing.T, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MockTaskRegistry) ListTasks(*map[string]string) ([]Task, error) {
|
func (registry *MockTaskRegistry) ListTasks(*map[string]string) ([]Pod, error) {
|
||||||
return registry.tasks, registry.err
|
return registry.tasks, registry.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MockTaskRegistry) GetTask(taskId string) (*Task, error) {
|
func (registry *MockTaskRegistry) GetTask(taskId string) (*Pod, error) {
|
||||||
return &Task{}, registry.err
|
return &Pod{}, registry.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MockTaskRegistry) CreateTask(machine string, task Task) error {
|
func (registry *MockTaskRegistry) CreateTask(machine string, task Pod) error {
|
||||||
return registry.err
|
return registry.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (registry *MockTaskRegistry) UpdateTask(task Task) error {
|
func (registry *MockTaskRegistry) UpdateTask(task Pod) error {
|
||||||
return registry.err
|
return registry.err
|
||||||
}
|
}
|
||||||
func (registry *MockTaskRegistry) DeleteTask(taskId string) error {
|
func (registry *MockTaskRegistry) DeleteTask(taskId string) error {
|
||||||
|
@ -83,13 +83,13 @@ func TestListEmptyTaskList(t *testing.T) {
|
||||||
|
|
||||||
func TestListTaskList(t *testing.T) {
|
func TestListTaskList(t *testing.T) {
|
||||||
mockRegistry := MockTaskRegistry{
|
mockRegistry := MockTaskRegistry{
|
||||||
tasks: []Task{
|
tasks: []Pod{
|
||||||
Task{
|
Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Task{
|
Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: "bar",
|
ID: "bar",
|
||||||
},
|
},
|
||||||
|
@ -118,7 +118,7 @@ func TestExtractJson(t *testing.T) {
|
||||||
storage := TaskRegistryStorage{
|
storage := TaskRegistryStorage{
|
||||||
registry: &mockRegistry,
|
registry: &mockRegistry,
|
||||||
}
|
}
|
||||||
task := Task{
|
task := Pod{
|
||||||
JSONBase: JSONBase{
|
JSONBase: JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
|
@ -134,32 +134,32 @@ func TestExtractJson(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectLabelMatch(t *testing.T, task Task, key, value string) {
|
func expectLabelMatch(t *testing.T, task Pod, key, value string) {
|
||||||
if !LabelMatch(task, key, value) {
|
if !LabelMatch(task, key, value) {
|
||||||
t.Errorf("Unexpected match failure: %#v %s %s", task, key, value)
|
t.Errorf("Unexpected match failure: %#v %s %s", task, key, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectNoLabelMatch(t *testing.T, task Task, key, value string) {
|
func expectNoLabelMatch(t *testing.T, task Pod, key, value string) {
|
||||||
if LabelMatch(task, key, value) {
|
if LabelMatch(task, key, value) {
|
||||||
t.Errorf("Unexpected match success: %#v %s %s", task, key, value)
|
t.Errorf("Unexpected match success: %#v %s %s", task, key, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectLabelsMatch(t *testing.T, task Task, query *map[string]string) {
|
func expectLabelsMatch(t *testing.T, task Pod, query *map[string]string) {
|
||||||
if !LabelsMatch(task, query) {
|
if !LabelsMatch(task, query) {
|
||||||
t.Errorf("Unexpected match failure: %#v %#v", task, *query)
|
t.Errorf("Unexpected match failure: %#v %#v", task, *query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectNoLabelsMatch(t *testing.T, task Task, query *map[string]string) {
|
func expectNoLabelsMatch(t *testing.T, task Pod, query *map[string]string) {
|
||||||
if LabelsMatch(task, query) {
|
if LabelsMatch(task, query) {
|
||||||
t.Errorf("Unexpected match success: %#v %#v", task, *query)
|
t.Errorf("Unexpected match success: %#v %#v", task, *query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLabelMatch(t *testing.T) {
|
func TestLabelMatch(t *testing.T) {
|
||||||
task := Task{
|
task := Pod{
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"baz": "blah",
|
"baz": "blah",
|
||||||
|
@ -172,7 +172,7 @@ func TestLabelMatch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLabelsMatch(t *testing.T) {
|
func TestLabelsMatch(t *testing.T) {
|
||||||
task := Task{
|
task := Pod{
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"baz": "blah",
|
"baz": "blah",
|
||||||
|
|
Loading…
Reference in New Issue