// doProbe probes the container once and records the result. // Returns whether the worker should continue. func doProbe(m *manager, w *worker) (keepGoing bool) { defer util.HandleCrash(func(_ interface{}) { keepGoing = true }) status, ok := m.statusManager.GetPodStatus(w.pod.UID) if !ok { // Either the pod has not been created yet, or it was already deleted. glog.V(3).Infof("No status for pod: %v", kubeutil.FormatPodName(w.pod)) return true } // Worker should terminate if pod is terminated. if status.Phase == api.PodFailed || status.Phase == api.PodSucceeded { glog.V(3).Infof("Pod %v %v, exiting probe worker", kubeutil.FormatPodName(w.pod), status.Phase) return false } c, ok := api.GetContainerStatus(status.ContainerStatuses, w.container.Name) if !ok { // Either the container has not been created yet, or it was deleted. glog.V(3).Infof("Non-existant container probed: %v - %v", kubeutil.FormatPodName(w.pod), w.container.Name) return true // Wait for more information. } if w.containerID != types.UID(c.ContainerID) { if w.containerID != "" { m.readinessCache.removeReadiness(string(w.containerID)) } w.containerID = types.UID(kubecontainer.TrimRuntimePrefix(c.ContainerID)) } if c.State.Running == nil { glog.V(3).Infof("Non-running container probed: %v - %v", kubeutil.FormatPodName(w.pod), w.container.Name) m.readinessCache.setReadiness(string(w.containerID), false) // Abort if the container will not be restarted. return c.State.Terminated == nil || w.pod.Spec.RestartPolicy != api.RestartPolicyNever } if int64(time.Since(c.State.Running.StartedAt.Time).Seconds()) < w.spec.InitialDelaySeconds { // Readiness defaults to false during the initial delay. m.readinessCache.setReadiness(string(w.containerID), false) return true } // TODO: Move error handling out of prober. result, _ := m.prober.ProbeReadiness(w.pod, status, w.container, string(w.containerID)) if result != probe.Unknown { m.readinessCache.setReadiness(string(w.containerID), result != probe.Failure) } return true }
func (m *manager) UpdatePodStatus(podUID types.UID, podStatus *api.PodStatus) { for i, c := range podStatus.ContainerStatuses { var ready bool if c.State.Running == nil { ready = false } else if result, ok := m.readinessCache.getReadiness(kubecontainer.TrimRuntimePrefix(c.ContainerID)); ok { ready = result } else { // The check whether there is a probe which hasn't run yet. _, exists := m.getReadinessProbe(podUID, c.Name) ready = !exists } podStatus.ContainerStatuses[i].Ready = ready } }