Better handling of unbound pods.

A small collection of tweaks to better handle pods when they are not currently
bound to a host.
This commit is contained in:
Tim Hockin
2014-09-28 21:29:39 -07:00
parent 6947331290
commit 372aa07b58
4 changed files with 19 additions and 5 deletions

View File

@@ -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()

View File

@@ -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()}