mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Add status message population.
This commit is contained in:
parent
f053a49988
commit
c2c6055d70
@ -80,6 +80,19 @@ func (storage *PodRegistryStorage) List(url *url.URL) (interface{}, error) {
|
|||||||
return result, err
|
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) {
|
func (storage *PodRegistryStorage) Get(id string) (interface{}, error) {
|
||||||
pod, err := storage.registry.GetPod(id)
|
pod, err := storage.registry.GetPod(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -90,6 +103,7 @@ func (storage *PodRegistryStorage) Get(id string) (interface{}, error) {
|
|||||||
return pod, err
|
return pod, err
|
||||||
}
|
}
|
||||||
pod.CurrentState.Info = info
|
pod.CurrentState.Info = info
|
||||||
|
pod.CurrentState.Status = makePodStatus(info)
|
||||||
pod.Kind = "cluster#pod"
|
pod.Kind = "cluster#pod"
|
||||||
return pod, err
|
return pod, err
|
||||||
}
|
}
|
||||||
|
@ -201,5 +201,31 @@ func TestLabelsMatch(t *testing.T) {
|
|||||||
"foobar": "bar",
|
"foobar": "bar",
|
||||||
"baz": "blah",
|
"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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user