mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	kubelet: Refactor isPodRunning() in runonce.go
Replace InspectContainer() with generic GetPodStatus().
This commit is contained in:
		@@ -22,6 +22,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
 | 
				
			||||||
 | 
						kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
 | 
				
			||||||
	"github.com/golang/glog"
 | 
						"github.com/golang/glog"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -119,19 +120,14 @@ func (kl *Kubelet) runPod(pod *api.Pod, retryDelay time.Duration) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// isPodRunning returns true if all containers of a manifest are running.
 | 
					// isPodRunning returns true if all containers of a manifest are running.
 | 
				
			||||||
func (kl *Kubelet) isPodRunning(pod *api.Pod, runningPod container.Pod) (bool, error) {
 | 
					func (kl *Kubelet) isPodRunning(pod *api.Pod, runningPod container.Pod) (bool, error) {
 | 
				
			||||||
	for _, container := range pod.Spec.Containers {
 | 
						status, err := kl.containerManager.GetPodStatus(pod)
 | 
				
			||||||
		c := runningPod.FindContainerByName(container.Name)
 | 
					 | 
				
			||||||
		if c == nil {
 | 
					 | 
				
			||||||
			glog.Infof("container %q not found", container.Name)
 | 
					 | 
				
			||||||
			return false, nil
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		inspectResult, err := kl.dockerClient.InspectContainer(string(c.ID))
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
			glog.Infof("failed to inspect container %q: %v", container.Name, err)
 | 
							glog.Infof("Failed to get the status of pod %q: %v", kubecontainer.GetPodFullName(pod), err)
 | 
				
			||||||
		return false, err
 | 
							return false, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		if !inspectResult.State.Running {
 | 
						for _, st := range status.ContainerStatuses {
 | 
				
			||||||
			glog.Infof("container %q not running: %#v", container.Name, inspectResult.State)
 | 
							if st.State.Running == nil {
 | 
				
			||||||
 | 
								glog.Infof("Container %q not running: %#v", st.Name, st.State)
 | 
				
			||||||
			return false, nil
 | 
								return false, nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -113,6 +113,7 @@ func TestRunOnce(t *testing.T) {
 | 
				
			|||||||
			{label: "list pod container", containers: []docker.APIContainers{}},
 | 
								{label: "list pod container", containers: []docker.APIContainers{}},
 | 
				
			||||||
			{label: "syncPod", containers: podContainers},
 | 
								{label: "syncPod", containers: podContainers},
 | 
				
			||||||
			{label: "list pod container", containers: podContainers},
 | 
								{label: "list pod container", containers: podContainers},
 | 
				
			||||||
 | 
								{label: "list pod container", containers: podContainers},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		inspectContainersResults: []inspectContainersResult{
 | 
							inspectContainersResults: []inspectContainersResult{
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user