From 6cd0c261b339572d824b1469e59a206155046398 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Thu, 9 Oct 2014 16:47:56 -0700 Subject: [PATCH 1/2] runonce: better container state detection --- pkg/kubelet/runonce.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/kubelet/runonce.go b/pkg/kubelet/runonce.go index 0053a4bb8b0..ce9c3d39fbb 100644 --- a/pkg/kubelet/runonce.go +++ b/pkg/kubelet/runonce.go @@ -117,8 +117,18 @@ func (kl *Kubelet) runPod(pod api.BoundPod) error { // isPodRunning returns true if all containers of a manifest are running. func (kl *Kubelet) isPodRunning(pod api.BoundPod, dockerContainers dockertools.DockerContainers) bool { for _, container := range pod.Spec.Containers { - if dockerContainer, found, _ := dockerContainers.FindPodContainer(GetPodFullName(&pod), pod.UID, container.Name); !found || dockerContainer.Status != "running" { - glog.Infof("container %q not found (%v) or not running: %#v", container.Name, found, dockerContainer) + dockerContainer, found, _ := dockerContainers.FindPodContainer(GetPodFullName(&pod), pod.UID, container.Name) + if !found { + glog.Infof("container %q not found", container.Name) + return false + } + inspectResult, err := kl.dockerClient.InspectContainer(dockerContainer.ID) + if err != nil { + glog.Infof("failed to inspect container %q: %v", container.Name, err) + return false + } + if !inspectResult.State.Running { + glog.Infof("container %q not running: %#v", container.Name, inspectResult.State) return false } } From 14c3b9d90094a75a4acc9bf88862a7c130809069 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Fri, 10 Oct 2014 15:46:24 -0700 Subject: [PATCH 2/2] runonce: handle inspect error --- pkg/kubelet/runonce.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/kubelet/runonce.go b/pkg/kubelet/runonce.go index ce9c3d39fbb..0f45aa87cb2 100644 --- a/pkg/kubelet/runonce.go +++ b/pkg/kubelet/runonce.go @@ -95,7 +95,11 @@ func (kl *Kubelet) runPod(pod api.BoundPod) error { if err != nil { return fmt.Errorf("failed to get kubelet docker containers: %v", err) } - if running := kl.isPodRunning(pod, dockerContainers); running { + running, err := kl.isPodRunning(pod, dockerContainers) + if err != nil { + return fmt.Errorf("failed to check pod status: %v", err) + } + if running { glog.Infof("pod %q containers running", pod.ID) return nil } @@ -115,22 +119,22 @@ func (kl *Kubelet) runPod(pod api.BoundPod) error { } // isPodRunning returns true if all containers of a manifest are running. -func (kl *Kubelet) isPodRunning(pod api.BoundPod, dockerContainers dockertools.DockerContainers) bool { +func (kl *Kubelet) isPodRunning(pod api.BoundPod, dockerContainers dockertools.DockerContainers) (bool, error) { for _, container := range pod.Spec.Containers { dockerContainer, found, _ := dockerContainers.FindPodContainer(GetPodFullName(&pod), pod.UID, container.Name) if !found { glog.Infof("container %q not found", container.Name) - return false + return false, nil } inspectResult, err := kl.dockerClient.InspectContainer(dockerContainer.ID) if err != nil { glog.Infof("failed to inspect container %q: %v", container.Name, err) - return false + return false, err } if !inspectResult.State.Running { glog.Infof("container %q not running: %#v", container.Name, inspectResult.State) - return false + return false, nil } } - return true + return true, nil }