diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index 2a1ef3d15cd..631af02b4fe 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -1127,6 +1127,18 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod changes.InitContainersToStart = append(changes.InitContainersToStart, i+1) } + // Restart running sidecar containers which have had their definition changed. + if _, _, changed := containerChanged(container, status); changed { + changes.ContainersToKill[status.ID] = containerToKillInfo{ + name: container.Name, + container: container, + message: fmt.Sprintf("Init container %s definition changed", container.Name), + reason: "", + } + changes.InitContainersToStart = append(changes.InitContainersToStart, i) + break + } + // A restartable init container does not have to take into account its // liveness probe when it determines to start the next init container. if container.LivenessProbe != nil { diff --git a/test/e2e_node/container_lifecycle_test.go b/test/e2e_node/container_lifecycle_test.go index d75ced5f95e..313f2c6163a 100644 --- a/test/e2e_node/container_lifecycle_test.go +++ b/test/e2e_node/container_lifecycle_test.go @@ -3717,7 +3717,7 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, "Containers Lifecycle", func( err = e2epod.WaitForPodCondition(ctx, f.ClientSet, pod.Namespace, pod.Name, "init container attempted to run with updated image", time.Duration(30)*time.Second, func(pod *v1.Pod) (bool, error) { containerStatus := pod.Status.InitContainerStatuses[1] - return containerStatus.Image == updatedImage, nil + return containerStatus.Image == updatedImage && containerStatus.RestartCount > 1, nil }) framework.ExpectNoError(err)