Skip to content

Commit 43d527a

Browse files
committed
add restart on definition change
1 parent 3710d6f commit 43d527a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pkg/kubelet/kuberuntime/kuberuntime_container.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,18 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
11271127
changes.InitContainersToStart = append(changes.InitContainersToStart, i+1)
11281128
}
11291129

1130+
// Restart running sidecar containers which have had their definition changed.
1131+
if _, _, changed := containerChanged(container, status); changed {
1132+
changes.ContainersToKill[status.ID] = containerToKillInfo{
1133+
name: container.Name,
1134+
container: container,
1135+
message: fmt.Sprintf("Init container %s definition changed", container.Name),
1136+
reason: "",
1137+
}
1138+
changes.InitContainersToStart = append(changes.InitContainersToStart, i)
1139+
break
1140+
}
1141+
11301142
// A restartable init container does not have to take into account its
11311143
// liveness probe when it determines to start the next init container.
11321144
if container.LivenessProbe != nil {

test/e2e_node/container_lifecycle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3717,7 +3717,7 @@ var _ = SIGDescribe(nodefeature.SidecarContainers, "Containers Lifecycle", func(
37173717
err = e2epod.WaitForPodCondition(ctx, f.ClientSet, pod.Namespace, pod.Name, "init container attempted to run with updated image",
37183718
time.Duration(30)*time.Second, func(pod *v1.Pod) (bool, error) {
37193719
containerStatus := pod.Status.InitContainerStatuses[1]
3720-
return containerStatus.Image == updatedImage, nil
3720+
return containerStatus.Image == updatedImage && containerStatus.RestartCount > 1, nil
37213721
})
37223722
framework.ExpectNoError(err)
37233723

0 commit comments

Comments
 (0)