diff --git a/pkg/registry/pod_registry.go b/pkg/registry/pod_registry.go index e25d7f74620..07d3476a3d3 100644 --- a/pkg/registry/pod_registry.go +++ b/pkg/registry/pod_registry.go @@ -80,6 +80,19 @@ func (storage *PodRegistryStorage) List(url *url.URL) (interface{}, error) { return result, err } +func makePodStatus(info interface{}) string { + if state, ok := info.(map[string]interface{})["State"]; ok { + if running, ok := state.(map[string]interface{})["Running"]; ok { + if running.(bool) { + return "Running" + } else { + return "Stopped" + } + } + } + return "Pending" +} + func (storage *PodRegistryStorage) Get(id string) (interface{}, error) { pod, err := storage.registry.GetPod(id) if err != nil { @@ -90,6 +103,7 @@ func (storage *PodRegistryStorage) Get(id string) (interface{}, error) { return pod, err } pod.CurrentState.Info = info + pod.CurrentState.Status = makePodStatus(info) pod.Kind = "cluster#pod" return pod, err } diff --git a/pkg/registry/pod_registry_test.go b/pkg/registry/pod_registry_test.go index 1630ca8eb55..0af7e403891 100644 --- a/pkg/registry/pod_registry_test.go +++ b/pkg/registry/pod_registry_test.go @@ -201,5 +201,31 @@ func TestLabelsMatch(t *testing.T) { "foobar": "bar", "baz": "blah", }) - +} + +func TestMakePodStatus(t *testing.T) { + status := makePodStatus(map[string]interface{}{}) + if status != "Pending" { + t.Errorf("Expected 'Pending', got '%s'", status) + } + + status = makePodStatus(map[string]interface{}{ + "State": map[string]interface{}{ + "Running": false, + }, + }) + + if status != "Stopped" { + t.Errorf("Expected 'Stopped', got '%s'", status) + } + + status = makePodStatus(map[string]interface{}{ + "State": map[string]interface{}{ + "Running": true, + }, + }) + + if status != "Running" { + t.Errorf("Expected 'Running', got '%s'", status) + } }