mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
Merge pull request #126525 from dshebib/addSidecarE2EImgTest
Restart sidecar container when the image has changed
This commit is contained in:
commit
98b4ee6bfa
@ -1127,6 +1127,18 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
|
|||||||
changes.InitContainersToStart = append(changes.InitContainersToStart, i+1)
|
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
|
// A restartable init container does not have to take into account its
|
||||||
// liveness probe when it determines to start the next init container.
|
// liveness probe when it determines to start the next init container.
|
||||||
if container.LivenessProbe != nil {
|
if container.LivenessProbe != nil {
|
||||||
|
@ -1238,6 +1238,19 @@ func getKillMapWithInitContainers(pod *v1.Pod, status *kubecontainer.PodStatus,
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func modifyKillMapContainerImage(containersToKill map[kubecontainer.ContainerID]containerToKillInfo, status *kubecontainer.PodStatus, cIndexes []int, imageNames []string) map[kubecontainer.ContainerID]containerToKillInfo {
|
||||||
|
for idx, i := range cIndexes {
|
||||||
|
containerKillInfo := containersToKill[status.ContainerStatuses[i].ID]
|
||||||
|
updatedContainer := containerKillInfo.container.DeepCopy()
|
||||||
|
updatedContainer.Image = imageNames[idx]
|
||||||
|
containersToKill[status.ContainerStatuses[i].ID] = containerToKillInfo{
|
||||||
|
container: updatedContainer,
|
||||||
|
name: containerKillInfo.name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return containersToKill
|
||||||
|
}
|
||||||
|
|
||||||
func verifyActions(t *testing.T, expected, actual *podActions, desc string) {
|
func verifyActions(t *testing.T, expected, actual *podActions, desc string) {
|
||||||
if actual.ContainersToKill != nil {
|
if actual.ContainersToKill != nil {
|
||||||
// Clear the message and reason fields since we don't need to verify them.
|
// Clear the message and reason fields since we don't need to verify them.
|
||||||
@ -1524,12 +1537,12 @@ func makeBasePodAndStatusWithInitContainers() (*v1.Pod, *kubecontainer.PodStatus
|
|||||||
{
|
{
|
||||||
ID: kubecontainer.ContainerID{ID: "initid2"},
|
ID: kubecontainer.ContainerID{ID: "initid2"},
|
||||||
Name: "init2", State: kubecontainer.ContainerStateExited,
|
Name: "init2", State: kubecontainer.ContainerStateExited,
|
||||||
Hash: kubecontainer.HashContainer(&pod.Spec.InitContainers[0]),
|
Hash: kubecontainer.HashContainer(&pod.Spec.InitContainers[1]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: kubecontainer.ContainerID{ID: "initid3"},
|
ID: kubecontainer.ContainerID{ID: "initid3"},
|
||||||
Name: "init3", State: kubecontainer.ContainerStateExited,
|
Name: "init3", State: kubecontainer.ContainerStateExited,
|
||||||
Hash: kubecontainer.HashContainer(&pod.Spec.InitContainers[0]),
|
Hash: kubecontainer.HashContainer(&pod.Spec.InitContainers[2]),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return pod, status
|
return pod, status
|
||||||
@ -1702,6 +1715,18 @@ func TestComputePodActionsWithRestartableInitContainers(t *testing.T) {
|
|||||||
m.startupManager.Remove(status.ContainerStatuses[2].ID)
|
m.startupManager.Remove(status.ContainerStatuses[2].ID)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"kill and recreate the restartable init container if the container definition changes": {
|
||||||
|
mutatePodFn: func(pod *v1.Pod) {
|
||||||
|
pod.Spec.RestartPolicy = v1.RestartPolicyAlways
|
||||||
|
pod.Spec.InitContainers[2].Image = "foo-image"
|
||||||
|
},
|
||||||
|
actions: podActions{
|
||||||
|
SandboxID: baseStatus.SandboxStatuses[0].Id,
|
||||||
|
InitContainersToStart: []int{2},
|
||||||
|
ContainersToKill: modifyKillMapContainerImage(getKillMapWithInitContainers(basePod, baseStatus, []int{2}), baseStatus, []int{2}, []string{"foo-image"}),
|
||||||
|
ContainersToStart: []int{0, 1, 2},
|
||||||
|
},
|
||||||
|
},
|
||||||
"restart terminated restartable init container and next init container": {
|
"restart terminated restartable init container and next init container": {
|
||||||
mutatePodFn: func(pod *v1.Pod) { pod.Spec.RestartPolicy = v1.RestartPolicyAlways },
|
mutatePodFn: func(pod *v1.Pod) { pod.Spec.RestartPolicy = v1.RestartPolicyAlways },
|
||||||
mutateStatusFn: func(pod *v1.Pod, status *kubecontainer.PodStatus) {
|
mutateStatusFn: func(pod *v1.Pod, status *kubecontainer.PodStatus) {
|
||||||
@ -1928,12 +1953,12 @@ func makeBasePodAndStatusWithRestartableInitContainers() (*v1.Pod, *kubecontaine
|
|||||||
{
|
{
|
||||||
ID: kubecontainer.ContainerID{ID: "initid2"},
|
ID: kubecontainer.ContainerID{ID: "initid2"},
|
||||||
Name: "restartable-init-2", State: kubecontainer.ContainerStateRunning,
|
Name: "restartable-init-2", State: kubecontainer.ContainerStateRunning,
|
||||||
Hash: kubecontainer.HashContainer(&pod.Spec.InitContainers[0]),
|
Hash: kubecontainer.HashContainer(&pod.Spec.InitContainers[1]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: kubecontainer.ContainerID{ID: "initid3"},
|
ID: kubecontainer.ContainerID{ID: "initid3"},
|
||||||
Name: "restartable-init-3", State: kubecontainer.ContainerStateRunning,
|
Name: "restartable-init-3", State: kubecontainer.ContainerStateRunning,
|
||||||
Hash: kubecontainer.HashContainer(&pod.Spec.InitContainers[0]),
|
Hash: kubecontainer.HashContainer(&pod.Spec.InitContainers[2]),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return pod, status
|
return pod, status
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user