Merge pull request #1596 from thockin/unbound

Better handling of unbound pods.
pull/6/head
Brendan Burns 2014-10-06 13:31:41 -07:00
commit 7c694d2cad
4 changed files with 19 additions and 5 deletions

View File

@ -182,10 +182,17 @@ func makeImageList(manifest api.ContainerManifest) string {
return strings.Join(images, ",") return strings.Join(images, ",")
} }
func podHostString(host, ip string) string {
if host == "" && ip == "" {
return "<unassigned>"
}
return host + "/" + ip
}
func printPod(pod *api.Pod, w io.Writer) error { func printPod(pod *api.Pod, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
pod.ID, makeImageList(pod.DesiredState.Manifest), pod.ID, makeImageList(pod.DesiredState.Manifest),
pod.CurrentState.Host+"/"+pod.CurrentState.HostIP, podHostString(pod.CurrentState.Host, pod.CurrentState.HostIP),
labels.Set(pod.Labels), pod.CurrentState.Status) labels.Set(pod.Labels), pod.CurrentState.Status)
return err return err
} }

View File

@ -79,6 +79,9 @@ func (p *PodCache) UpdateAllContainers() {
return return
} }
for _, pod := range pods.Items { for _, pod := range pods.Items {
if pod.CurrentState.Host == "" {
continue
}
err := p.updatePodInfo(pod.CurrentState.Host, pod.ID) err := p.updatePodInfo(pod.CurrentState.Host, pod.ID)
if err != nil && err != client.ErrPodInfoNotAvailable { if err != nil && err != client.ErrPodInfoNotAvailable {
glog.Errorf("Error synchronizing container: %v", err) glog.Errorf("Error synchronizing container: %v", err)

View File

@ -133,7 +133,9 @@ func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
} }
pod.CurrentState.Status = status pod.CurrentState.Status = status
} }
if pod.CurrentState.Host != "" {
pod.CurrentState.HostIP = rs.getInstanceIP(pod.CurrentState.Host) pod.CurrentState.HostIP = rs.getInstanceIP(pod.CurrentState.Host)
}
return pod, err return pod, err
} }
@ -165,9 +167,11 @@ func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Obj
return pod, err return pod, err
} }
pod.CurrentState.Status = status pod.CurrentState.Status = status
if pod.CurrentState.Host != "" {
pod.CurrentState.HostIP = rs.getInstanceIP(pod.CurrentState.Host) pod.CurrentState.HostIP = rs.getInstanceIP(pod.CurrentState.Host)
} }
} }
}
return pods, err return pods, err
} }
@ -258,7 +262,7 @@ func getInstanceIPFromCloud(cloud cloudprovider.Interface, host string) string {
} }
addr, err := instances.IPAddress(host) addr, err := instances.IPAddress(host)
if err != nil { if err != nil {
glog.Errorf("Error getting instance IP: %#v", err) glog.Errorf("Error getting instance IP for %q: %#v", host, err)
return "" return ""
} }
return addr.String() return addr.String()

View File

@ -341,7 +341,7 @@ func TestGetPod(t *testing.T) {
func TestGetPodCloud(t *testing.T) { func TestGetPodCloud(t *testing.T) {
fakeCloud := &fake_cloud.FakeCloud{} fakeCloud := &fake_cloud.FakeCloud{}
podRegistry := registrytest.NewPodRegistry(nil) podRegistry := registrytest.NewPodRegistry(nil)
podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} podRegistry.Pod = &api.Pod{JSONBase: api.JSONBase{ID: "foo"}, CurrentState: api.PodState{Host: "machine"}}
clock := &fakeClock{t: time.Now()} clock := &fakeClock{t: time.Now()}