diff --git a/pkg/registry/pod_registry.go b/pkg/registry/pod_registry.go index 4ca61c246f5..c63991dc15f 100644 --- a/pkg/registry/pod_registry.go +++ b/pkg/registry/pod_registry.go @@ -91,7 +91,11 @@ func (storage *PodRegistryStorage) fillPodInfo(pod *api.Pod) { pod.CurrentState.Info = info netContainerInfo, ok := info["net"] if ok { - pod.CurrentState.PodIP = netContainerInfo.NetworkSettings.IPAddress + if netContainerInfo.NetworkSettings != nil { + pod.CurrentState.PodIP = netContainerInfo.NetworkSettings.IPAddress + } else { + glog.Warningf("No network settings: %#v", netContainerInfo) + } } else { glog.Warningf("Couldn't find network container in %v", info) } diff --git a/pkg/registry/pod_registry_test.go b/pkg/registry/pod_registry_test.go index 8f7383520eb..2e6d7b826da 100644 --- a/pkg/registry/pod_registry_test.go +++ b/pkg/registry/pod_registry_test.go @@ -317,3 +317,30 @@ func TestFillPodInfo(t *testing.T) { t.Errorf("Expected %s, saw %s", expectedIP, pod.CurrentState.PodIP) } } + +func TestFillPodInfoNoData(t *testing.T) { + expectedIP := "" + fakeGetter := FakePodInfoGetter{ + info: map[string]docker.Container{ + "net": { + ID: "foobar", + Path: "bin/run.sh", + }, + }, + } + storage := PodRegistryStorage{ + podCache: &fakeGetter, + } + + pod := api.Pod{} + + storage.fillPodInfo(&pod) + + if !reflect.DeepEqual(fakeGetter.info, pod.CurrentState.Info) { + t.Errorf("Unexpected mis-match: %#v vs %#v", fakeGetter.info, pod.CurrentState.Info) + } + + if pod.CurrentState.PodIP != expectedIP { + t.Errorf("Expected %s, saw %s", expectedIP, pod.CurrentState.PodIP) + } +}