Skip to content

Commit e6c67c3

Browse files
committed
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 <[email protected]>
1 parent c73fef5 commit e6c67c3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pkg/kubelet/kuberuntime/kuberuntime_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ func (m *kubeGenericRuntimeManager) computePodActions(pod *v1.Pod, podStatus *ku
572572
// need to restart it.
573573
if containerStatus == nil || containerStatus.State != kubecontainer.ContainerStateRunning {
574574
if kubecontainer.ShouldContainerBeRestarted(&container, pod, podStatus) {
575-
message := fmt.Sprintf("Container %+v is dead, but RestartPolicy says that we should restart it.", container)
575+
message := fmt.Sprintf("Container %q of pod %q is not in the desired state and shall be started", container.Name, format.Pod(pod))
576576
klog.V(3).Infof(message)
577577
changes.ContainersToStart = append(changes.ContainersToStart, idx)
578578
if containerStatus != nil && containerStatus.State == kubecontainer.ContainerStateUnknown {

0 commit comments

Comments
 (0)