From 4309cafff11f2e6376c97c3fd00073adfa9c373f Mon Sep 17 00:00:00 2001 From: Yifan Gu Date: Mon, 28 Sep 2015 19:14:18 -0700 Subject: [PATCH] rkt: return non error if the pod doesn't exist in GetPodStatus(). Previously, GetPodStatus() will return error if the pod is never created. However we've never seen the sync loop fail because in the beginning of the loop, if the pod is not found, it will be created. This works fine except the pod that keeps crashing. Because the above logic will keep restarting the pod as if it's never created. This PR fixes the bug. --- pkg/kubelet/rkt/rkt.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/kubelet/rkt/rkt.go b/pkg/kubelet/rkt/rkt.go index df2755222aa..7c136c4d2b6 100644 --- a/pkg/kubelet/rkt/rkt.go +++ b/pkg/kubelet/rkt/rkt.go @@ -820,16 +820,26 @@ func (r *runtime) KillPod(pod *api.Pod, runningPod kubecontainer.Pod) error { // getPodStatus reads the service file and invokes 'rkt status $UUID' to get the // pod's status. func (r *runtime) getPodStatus(serviceName string) (*api.PodStatus, error) { + var status api.PodStatus + // TODO(yifan): Get rkt uuid from the service file name. pod, rktInfo, err := r.readServiceFile(serviceName) - if err != nil { + if err != nil && !os.IsNotExist(err) { return nil, err } + + if os.IsNotExist(err) { + // Pod does not exit, means it's not been created yet, + // return empty status for now. + // TODO(yifan): Maybe inspect the image and return waiting status. + return &status, nil + } + podInfo, err := r.getPodInfo(rktInfo.uuid) if err != nil { return nil, err } - status := makePodStatus(pod, podInfo, rktInfo) + status = makePodStatus(pod, podInfo, rktInfo) return &status, nil } @@ -979,10 +989,6 @@ func (r *runtime) IsImagePresent(image kubecontainer.ImageSpec) (bool, error) { // SyncPod syncs the running pod to match the specified desired pod. func (r *runtime) SyncPod(pod *api.Pod, runningPod kubecontainer.Pod, podStatus api.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) error { podFullName := kubeletUtil.FormatPodName(pod) - if len(runningPod.Containers) == 0 { - glog.V(4).Infof("Pod %q is not running, will start it", podFullName) - return r.RunPod(pod, pullSecrets) - } // Add references to all containers. unidentifiedContainers := make(map[types.UID]*kubecontainer.Container) @@ -1036,8 +1042,11 @@ func (r *runtime) SyncPod(pod *api.Pod, runningPod kubecontainer.Pod, podStatus } if restartPod { - if err := r.KillPod(pod, runningPod); err != nil { - return err + // Kill the pod only if the pod is actually running. + if len(runningPod.Containers) > 0 { + if err := r.KillPod(pod, runningPod); err != nil { + return err + } } if err := r.RunPod(pod, pullSecrets); err != nil { return err