From 4fdfeaa30e6efe87851fc0e76f251e5483e3fdba Mon Sep 17 00:00:00 2001 From: Dawn Chen Date: Mon, 6 Oct 2014 11:54:51 -0700 Subject: [PATCH] Addressed comments. --- pkg/api/types.go | 2 +- pkg/kubelet/dockertools/docker.go | 25 +++++++++++++++---------- pkg/kubelet/kubelet.go | 3 +-- pkg/kubelet/runonce_test.go | 16 ++++++++++++++-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index e7a99ef66c8..d504e51adc6 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -329,7 +329,7 @@ type ContainerStatus struct { // TODO(dchen1107): Deprecated this soon once we pull entire PodStatus from node, // not just PodInfo. Now we need this to remove docker.Container from API PodIP string `json:"podIP,omitempty" yaml:"podIP,omitempty"` - // TODO(dchen1107): Need to decide how to reprensent this in v1beta3 + // TODO(dchen1107): Need to decide how to represent this in v1beta3 Image string `yaml:"image" json:"image"` // TODO(dchen1107): Once we have done with integration with cadvisor, resource // usage should be included. diff --git a/pkg/kubelet/dockertools/docker.go b/pkg/kubelet/dockertools/docker.go index 314788fade7..c46f96123b9 100644 --- a/pkg/kubelet/dockertools/docker.go +++ b/pkg/kubelet/dockertools/docker.go @@ -275,7 +275,7 @@ var ( ErrNoContainersInPod = errors.New("no containers exist for this pod") // ErrNoNetworkContainerInPod is returned when there is no network container for a given pod - ErrNoNetworkContainerInPod = errors.New("No network container exist for this pod") + ErrNoNetworkContainerInPod = errors.New("No network container exists for this pod") // ErrContainerCannotRun is returned when a container is created, but cannot run properly ErrContainerCannotRun = errors.New("Container cannot run") @@ -292,8 +292,9 @@ func inspectContainer(client DockerInterface, dockerID, containerName string) (* } glog.V(3).Infof("Container: %s [%s] inspect result %+v", *inspectResult) - var containerStatus api.ContainerStatus - containerStatus.Image = inspectResult.Config.Image + containerStatus := api.ContainerStatus{ + Image: inspectResult.Config.Image, + } waiting := true if inspectResult.State.Running { @@ -377,19 +378,23 @@ func GetDockerPodInfo(client DockerInterface, manifest api.ContainerManifest, po } image := container.Image - containerStatus.State.Waiting = &api.ContainerStateWaiting{} // Check image is ready on the node or not // TODO(dchen1107): docker/docker/issues/8365 to figure out if the image exists _, err := client.InspectImage(image) - if err != nil && err == docker.ErrNoSuchImage { - if err == docker.ErrNoSuchImage { - containerStatus.State.Waiting.Reason = fmt.Sprintf("Image: %s is not ready on the node", image) - } else { - containerStatus.State.Waiting.Reason = err.Error() + if err == nil { + containerStatus.State.Waiting = &api.ContainerStateWaiting{ + Reason: fmt.Sprintf("Image: %s is ready, container is creating", image), + } + } else if err == docker.ErrNoSuchImage { + containerStatus.State.Waiting = &api.ContainerStateWaiting{ + Reason: fmt.Sprintf("Image: %s is not ready on the node", image), } } else { - containerStatus.State.Waiting.Reason = fmt.Sprintf("Image: %s is ready, container is creating", image) + containerStatus.State.Waiting = &api.ContainerStateWaiting{ + Reason: err.Error(), + } } + info[container.Name] = containerStatus } } diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 57e8d464a39..2c1820abbaa 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -771,8 +771,7 @@ func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail stri func (kl *Kubelet) GetPodInfo(podFullName, uuid string) (api.PodInfo, error) { var manifest api.ContainerManifest for _, pod := range kl.pods { - fullName := fmt.Sprintf("%s.%s", pod.Name, pod.Namespace) - if fullName == podFullName { + if GetPodFullName(&pod) == podFullName { manifest = pod.Manifest break } diff --git a/pkg/kubelet/runonce_test.go b/pkg/kubelet/runonce_test.go index 4949a99594c..5766dcd98e5 100644 --- a/pkg/kubelet/runonce_test.go +++ b/pkg/kubelet/runonce_test.go @@ -85,8 +85,20 @@ func TestRunOnce(t *testing.T) { }}, }, inspectContainersResults: []inspectContainersResult{ - {label: "syncPod", container: docker.Container{State: docker.State{Running: true}}}, - {label: "syncPod", container: docker.Container{State: docker.State{Running: true}}}, + { + label: "syncPod", + container: docker.Container{ + Config: &docker.Config{Image: "someimage"}, + State: docker.State{Running: true}, + }, + }, + { + label: "syncPod", + container: docker.Container{ + Config: &docker.Config{Image: "someimage"}, + State: docker.State{Running: true}, + }, + }, }, t: t, }