Use DesiredState rather than CurrentState for Host.

This commit is contained in:
Daniel Smith 2014-08-11 15:12:51 -07:00
parent b7752a86d4
commit b5352a81c7
2 changed files with 19 additions and 8 deletions

View File

@ -64,6 +64,10 @@ func (registry *EtcdRegistry) ListPods(selector labels.Selector) ([]api.Pod, err
} }
for _, pod := range allPods { for _, pod := range allPods {
if selector.Matches(labels.Set(pod.Labels)) { if selector.Matches(labels.Set(pod.Labels)) {
// TODO: Currently nothing sets CurrentState.Host. We need a feedback loop that sets
// the CurrentState.Host and Status fields. Here we pretend that reality perfectly
// matches our desires.
pod.CurrentState.Host = pod.DesiredState.Host
filteredPods = append(filteredPods, pod) filteredPods = append(filteredPods, pod)
} }
} }
@ -77,6 +81,10 @@ func (registry *EtcdRegistry) GetPod(podID string) (*api.Pod, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// TODO: Currently nothing sets CurrentState.Host. We need a feedback loop that sets
// the CurrentState.Host and Status fields. Here we pretend that reality perfectly
// matches our desires.
pod.CurrentState.Host = pod.DesiredState.Host
return &pod, nil return &pod, nil
} }
@ -86,10 +94,14 @@ func makeContainerKey(machine string) string {
// CreatePod creates a pod based on a specification, schedule it onto a specific machine. // CreatePod creates a pod based on a specification, schedule it onto a specific machine.
func (registry *EtcdRegistry) CreatePod(machine string, pod api.Pod) error { func (registry *EtcdRegistry) CreatePod(machine string, pod api.Pod) error {
// Set status to "Waiting". // Set current status to "Waiting".
pod.CurrentState.Status = api.PodWaiting pod.CurrentState.Status = api.PodWaiting
pod.CurrentState.Host = "" pod.CurrentState.Host = ""
// DesiredState.Host == "" is a signal to the scheduler that this pod needs scheduling.
pod.DesiredState.Status = api.PodRunning
pod.DesiredState.Host = ""
err := registry.helper.CreateObj(makePodKey(pod.ID), &pod) err := registry.helper.CreateObj(makePodKey(pod.ID), &pod)
if err != nil { if err != nil {
return err return err
@ -112,8 +124,7 @@ func (registry *EtcdRegistry) AssignPod(podID string, machine string) error {
if !ok { if !ok {
return nil, fmt.Errorf("unexpected object: %#v", obj) return nil, fmt.Errorf("unexpected object: %#v", obj)
} }
pod.CurrentState.Host = machine pod.DesiredState.Host = machine
pod.CurrentState.Status = api.PodWaiting
finalPod = pod finalPod = pod
return pod, nil return pod, nil
}, },
@ -175,7 +186,7 @@ func (registry *EtcdRegistry) DeletePod(podID string) error {
return err return err
} }
machine := pod.CurrentState.Host machine := pod.DesiredState.Host
if machine == "" { if machine == "" {
// Pod was never scheduled anywhere, just return. // Pod was never scheduled anywhere, just return.
return nil return nil

View File

@ -298,7 +298,7 @@ func TestEtcdDeletePod(t *testing.T) {
key := "/registry/pods/foo" key := "/registry/pods/foo"
fakeClient.Set(key, api.EncodeOrDie(api.Pod{ fakeClient.Set(key, api.EncodeOrDie(api.Pod{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
CurrentState: api.PodState{Host: "machine"}, DesiredState: api.PodState{Host: "machine"},
}), 0) }), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(&api.ContainerManifestList{ fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(&api.ContainerManifestList{
Items: []api.ContainerManifest{ Items: []api.ContainerManifest{
@ -334,7 +334,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
key := "/registry/pods/foo" key := "/registry/pods/foo"
fakeClient.Set(key, api.EncodeOrDie(api.Pod{ fakeClient.Set(key, api.EncodeOrDie(api.Pod{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
CurrentState: api.PodState{Host: "machine"}, DesiredState: api.PodState{Host: "machine"},
}), 0) }), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(&api.ContainerManifestList{ fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(&api.ContainerManifestList{
Items: []api.ContainerManifest{ Items: []api.ContainerManifest{
@ -418,13 +418,13 @@ func TestEtcdListPods(t *testing.T) {
{ {
Value: api.EncodeOrDie(api.Pod{ Value: api.EncodeOrDie(api.Pod{
JSONBase: api.JSONBase{ID: "foo"}, JSONBase: api.JSONBase{ID: "foo"},
CurrentState: api.PodState{Host: "machine"}, DesiredState: api.PodState{Host: "machine"},
}), }),
}, },
{ {
Value: api.EncodeOrDie(api.Pod{ Value: api.EncodeOrDie(api.Pod{
JSONBase: api.JSONBase{ID: "bar"}, JSONBase: api.JSONBase{ID: "bar"},
CurrentState: api.PodState{Host: "machine"}, DesiredState: api.PodState{Host: "machine"},
}), }),
}, },
}, },