提交 b1ef0354 编写于 作者: B bryk

Fix a bug where logs menu would crash when there were no statuses reported for containers

上级 bfbfd0e8
......@@ -80,17 +80,28 @@ func getReplicaSetPods(pods []api.Pod, limit int) *ReplicaSetPods {
for _, pod := range pods {
totalRestartCount := 0
replicaSetPodWithContainers := ReplicaSetPodWithContainers{
Name: pod.Name,
StartTime: pod.Status.StartTime,
Name: pod.Name,
StartTime: pod.Status.StartTime,
PodContainers: make([]PodContainer, 0),
}
for _, containerStatus := range pod.Status.ContainerStatuses {
podContainer := PodContainer{
Name: containerStatus.Name,
RestartCount: containerStatus.RestartCount,
}
podContainersByName := make(map[string]*PodContainer)
for _, container := range pod.Spec.Containers {
podContainer := PodContainer{Name: container.Name}
replicaSetPodWithContainers.PodContainers =
append(replicaSetPodWithContainers.PodContainers, podContainer)
totalRestartCount += containerStatus.RestartCount
podContainersByName[container.Name] = &(replicaSetPodWithContainers.
PodContainers[len(replicaSetPodWithContainers.PodContainers)-1])
}
for _, containerStatus := range pod.Status.ContainerStatuses {
podContainer, ok := podContainersByName[containerStatus.Name]
if ok {
podContainer.RestartCount = containerStatus.RestartCount
totalRestartCount += containerStatus.RestartCount
}
}
replicaSetPodWithContainers.TotalRestartCount = totalRestartCount
replicaSetPods.Pods = append(replicaSetPods.Pods, replicaSetPodWithContainers)
......@@ -103,5 +114,6 @@ func getReplicaSetPods(pods []api.Pod, limit int) *ReplicaSetPods {
}
replicaSetPods.Pods = replicaSetPods.Pods[0:limit]
}
return replicaSetPods
}
......@@ -27,6 +27,12 @@ func TestGetReplicaSetPods(t *testing.T) {
ObjectMeta: api.ObjectMeta{
Name: "pod-1",
},
Spec: api.PodSpec{
Containers: []api.Container{
{Name: "container-1"},
{Name: "container-2"},
},
},
Status: api.PodStatus{
ContainerStatuses: []api.ContainerStatus{
{
......@@ -44,6 +50,11 @@ func TestGetReplicaSetPods(t *testing.T) {
ObjectMeta: api.ObjectMeta{
Name: "pod-2",
},
Spec: api.PodSpec{
Containers: []api.Container{
{Name: "container-3"},
},
},
Status: api.PodStatus{
ContainerStatuses: []api.ContainerStatus{
{
......
......@@ -15,7 +15,6 @@
package main
import (
"fmt"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/runtime"
......@@ -57,7 +56,6 @@ func TestValidateName(t *testing.T) {
for _, c := range cases {
testClient := testclient.NewSimpleFake(c.objects...)
validity, _ := ValidateAppName(c.spec, testClient)
fmt.Printf("%#v\n", validity)
if validity.Valid != c.expected {
t.Errorf("Expected %#v validity to be %#v for objects %#v, but was %#v\n",
c.spec, c.expected, c.objects, validity)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册