From 372aa07b58a0645a90b57b31953a498ed1c9c4c0 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sun, 28 Sep 2014 21:29:39 -0700 Subject: [PATCH] Better handling of unbound pods. A small collection of tweaks to better handle pods when they are not currently bound to a host. --- pkg/kubecfg/resource_printer.go | 9 ++++++++- pkg/master/pod_cache.go | 3 +++ pkg/registry/pod/rest.go | 10 +++++++--- pkg/registry/pod/rest_test.go | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pkg/kubecfg/resource_printer.go b/pkg/kubecfg/resource_printer.go index cbc0d920ec..c4e037248c 100644 --- a/pkg/kubecfg/resource_printer.go +++ b/pkg/kubecfg/resource_printer.go @@ -182,10 +182,17 @@ func makeImageList(manifest api.ContainerManifest) string { return strings.Join(images, ",") } +func podHostString(host, ip string) string { + if host == "" && ip == "" { + return "" + } + return host + "/" + ip +} + func printPod(pod *api.Pod, w io.Writer) error { _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", 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) return err } diff --git a/pkg/master/pod_cache.go b/pkg/master/pod_cache.go index da9bd92e58..4dbaa3b13e 100644 --- a/pkg/master/pod_cache.go +++ b/pkg/master/pod_cache.go @@ -79,6 +79,9 @@ func (p *PodCache) UpdateAllContainers() { return } for _, pod := range pods.Items { + if pod.CurrentState.Host == "" { + continue + } err := p.updatePodInfo(pod.CurrentState.Host, pod.ID) if err != nil && err != client.ErrPodInfoNotAvailable { glog.Errorf("Error synchronizing container: %v", err) diff --git a/pkg/registry/pod/rest.go b/pkg/registry/pod/rest.go index 61b40941fa..835221635e 100644 --- a/pkg/registry/pod/rest.go +++ b/pkg/registry/pod/rest.go @@ -133,7 +133,9 @@ func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) { } pod.CurrentState.Status = status } - pod.CurrentState.HostIP = rs.getInstanceIP(pod.CurrentState.Host) + if pod.CurrentState.Host != "" { + pod.CurrentState.HostIP = rs.getInstanceIP(pod.CurrentState.Host) + } return pod, err } @@ -165,7 +167,9 @@ func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Obj return pod, err } pod.CurrentState.Status = status - pod.CurrentState.HostIP = rs.getInstanceIP(pod.CurrentState.Host) + if pod.CurrentState.Host != "" { + pod.CurrentState.HostIP = rs.getInstanceIP(pod.CurrentState.Host) + } } } return pods, err @@ -258,7 +262,7 @@ func getInstanceIPFromCloud(cloud cloudprovider.Interface, host string) string { } addr, err := instances.IPAddress(host) if err != nil { - glog.Errorf("Error getting instance IP: %#v", err) + glog.Errorf("Error getting instance IP for %q: %#v", host, err) return "" } return addr.String() diff --git a/pkg/registry/pod/rest_test.go b/pkg/registry/pod/rest_test.go index f052670a26..b7af44aa5f 100644 --- a/pkg/registry/pod/rest_test.go +++ b/pkg/registry/pod/rest_test.go @@ -341,7 +341,7 @@ func TestGetPod(t *testing.T) { func TestGetPodCloud(t *testing.T) { fakeCloud := &fake_cloud.FakeCloud{} 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()}