Skip to content

Commit

Permalink
Merge pull request kubernetes#5213 from yifan-gu/clean_syncPod
Browse files Browse the repository at this point in the history
Refactor pkg/kubelet/kubelet.go: shouldContainerBeRestarted().
  • Loading branch information
dchen1107 committed Mar 10, 2015
2 parents ac582b0 + 241ef34 commit 106e38e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,11 +1074,12 @@ func (kl *Kubelet) makePodDataDirs(pod *api.BoundPod) error {
return nil
}

func (kl *Kubelet) shouldContainerBeRestarted(pod *api.BoundPod, containerName, dockerContainerName string, uid types.UID) bool {
func (kl *Kubelet) shouldContainerBeRestarted(container *api.Container, pod *api.BoundPod) bool {
podFullName := GetPodFullName(pod)
// Check RestartPolicy for dead container
recentContainers, err := dockertools.GetRecentDockerContainersWithNameAndUUID(kl.dockerClient, GetPodFullName(pod), uid, containerName)
recentContainers, err := dockertools.GetRecentDockerContainersWithNameAndUUID(kl.dockerClient, podFullName, pod.UID, container.Name)
if err != nil {
glog.Errorf("Error listing recent containers:%s", dockerContainerName)
glog.Errorf("Error listing recent containers for pod %q: %v", podFullName, err)
// TODO(dawnchen): error handling here?
}
// set dead containers to unready state
Expand All @@ -1088,16 +1089,14 @@ func (kl *Kubelet) shouldContainerBeRestarted(pod *api.BoundPod, containerName,

if len(recentContainers) > 0 {
if pod.Spec.RestartPolicy.Never != nil {
glog.Infof("Already ran container with name %s, do nothing",
dockerContainerName)
glog.Infof("Already ran container %q of pod %q, do nothing", container.Name, podFullName)
return false

}
if pod.Spec.RestartPolicy.OnFailure != nil {
// Check the exit code of last run
if recentContainers[0].State.ExitCode == 0 {
glog.Infof("Already successfully ran container with name %s, do nothing",
dockerContainerName)
glog.Infof("Already successfully ran container %q of pod %q, do nothing", container.Name, podFullName)
return false
}
}
Expand Down Expand Up @@ -1247,7 +1246,7 @@ func (kl *Kubelet) syncPod(pod *api.BoundPod, containersInPod dockertools.Docker
}
}

if !kl.shouldContainerBeRestarted(pod, container.Name, dockerContainerName, uid) {
if !kl.shouldContainerBeRestarted(&container, pod) {
continue
}

Expand Down

0 comments on commit 106e38e

Please sign in to comment.