From 1e26cdfb6792b11d258d032eb6d8556420f675f6 Mon Sep 17 00:00:00 2001 From: Yu-Ju Hong Date: Fri, 21 Aug 2015 11:13:58 -0700 Subject: [PATCH] kubelet: fix container restart counts This commit ensures that the container restart count increments monotonically when there is no kubelet restarts. --- pkg/kubelet/kubelet.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 5651d63b2b1..9763a5abf4f 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -2353,6 +2353,18 @@ func (kl *Kubelet) generatePodStatus(pod *api.Pod) (api.PodStatus, error) { podFullName := kubecontainer.GetPodFullName(pod) glog.V(3).Infof("Generating status for %q", podFullName) + if existingStatus, ok := kl.statusManager.GetPodStatus(pod.UID); ok { + // This is a hacky fix to ensure container restart counts increment + // monotonically. Normally, we should not modify given pod. In this + // case, we check if there are cached status for this pod, and update + // the pod so that we update restart count appropriately. + // TODO(yujuhong): We will not need to count dead containers every time + // once we add the runtime pod cache. + // Note that kubelet restarts may still cause temporarily setback of + // restart counts. + pod.Status = existingStatus + } + // TODO: Consider include the container information. if kl.pastActiveDeadline(pod) { reason := "DeadlineExceeded"