From e6c67c32e140f88c923499b2a35fb96b34fdfdd2 Mon Sep 17 00:00:00 2001 From: Rodrigo Campos Date: Tue, 26 May 2020 17:02:35 -0300 Subject: [PATCH] Fix kubelet log message when starting a container This code can be called not only when a container is dead and restarted, but when is started for the first time too. For example, any pod with initContainer and containers will exhibit this behaviour. The reason is that in that case, the "if createPodSandbox" path will return the initContainers only and on the next call to this function this code is executed to start the containers for the fist time. In that case, it is wrong to log that the container is dead and will be restarted, as it was never started. In fact, the restart count will not be increased. This commit just changes this to say that the container is not in the desired state and should be started. In the end, the kubelet is a state machine and that is all we really care about. No tests are added, as the behaviour was correct and tests don't check logs messages. Signed-off-by: Rodrigo Campos --- pkg/kubelet/kuberuntime/kuberuntime_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index eebba49bbbe..a4a69e3851e 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -572,7 +572,7 @@ func (m *kubeGenericRuntimeManager) computePodActions(pod *v1.Pod, podStatus *ku // need to restart it. if containerStatus == nil || containerStatus.State != kubecontainer.ContainerStateRunning { if kubecontainer.ShouldContainerBeRestarted(&container, pod, podStatus) { - message := fmt.Sprintf("Container %+v is dead, but RestartPolicy says that we should restart it.", container) + message := fmt.Sprintf("Container %q of pod %q is not in the desired state and shall be started", container.Name, format.Pod(pod)) klog.V(3).Infof(message) changes.ContainersToStart = append(changes.ContainersToStart, idx) if containerStatus != nil && containerStatus.State == kubecontainer.ContainerStateUnknown {