@@ -1238,6 +1238,19 @@ func getKillMapWithInitContainers(pod *v1.Pod, status *kubecontainer.PodStatus,
1238
1238
return m
1239
1239
}
1240
1240
1241
+ func modifyKillMapContainerImage (containersToKill map [kubecontainer.ContainerID ]containerToKillInfo , status * kubecontainer.PodStatus , cIndexes []int , imageNames []string ) map [kubecontainer.ContainerID ]containerToKillInfo {
1242
+ for idx , i := range cIndexes {
1243
+ containerKillInfo := containersToKill [status .ContainerStatuses [i ].ID ]
1244
+ updatedContainer := containerKillInfo .container .DeepCopy ()
1245
+ updatedContainer .Image = imageNames [idx ]
1246
+ containersToKill [status .ContainerStatuses [i ].ID ] = containerToKillInfo {
1247
+ container : updatedContainer ,
1248
+ name : containerKillInfo .name ,
1249
+ }
1250
+ }
1251
+ return containersToKill
1252
+ }
1253
+
1241
1254
func verifyActions (t * testing.T , expected , actual * podActions , desc string ) {
1242
1255
if actual .ContainersToKill != nil {
1243
1256
// Clear the message and reason fields since we don't need to verify them.
@@ -1524,12 +1537,12 @@ func makeBasePodAndStatusWithInitContainers() (*v1.Pod, *kubecontainer.PodStatus
1524
1537
{
1525
1538
ID : kubecontainer.ContainerID {ID : "initid2" },
1526
1539
Name : "init2" , State : kubecontainer .ContainerStateExited ,
1527
- Hash : kubecontainer .HashContainer (& pod .Spec .InitContainers [0 ]),
1540
+ Hash : kubecontainer .HashContainer (& pod .Spec .InitContainers [1 ]),
1528
1541
},
1529
1542
{
1530
1543
ID : kubecontainer.ContainerID {ID : "initid3" },
1531
1544
Name : "init3" , State : kubecontainer .ContainerStateExited ,
1532
- Hash : kubecontainer .HashContainer (& pod .Spec .InitContainers [0 ]),
1545
+ Hash : kubecontainer .HashContainer (& pod .Spec .InitContainers [2 ]),
1533
1546
},
1534
1547
}
1535
1548
return pod , status
@@ -1702,6 +1715,18 @@ func TestComputePodActionsWithRestartableInitContainers(t *testing.T) {
1702
1715
m .startupManager .Remove (status .ContainerStatuses [2 ].ID )
1703
1716
},
1704
1717
},
1718
+ "kill and recreate the restartable init container if the container definition changes" : {
1719
+ mutatePodFn : func (pod * v1.Pod ) {
1720
+ pod .Spec .RestartPolicy = v1 .RestartPolicyAlways
1721
+ pod .Spec .InitContainers [2 ].Image = "foo-image"
1722
+ },
1723
+ actions : podActions {
1724
+ SandboxID : baseStatus .SandboxStatuses [0 ].Id ,
1725
+ InitContainersToStart : []int {2 },
1726
+ ContainersToKill : modifyKillMapContainerImage (getKillMapWithInitContainers (basePod , baseStatus , []int {2 }), baseStatus , []int {2 }, []string {"foo-image" }),
1727
+ ContainersToStart : []int {0 , 1 , 2 },
1728
+ },
1729
+ },
1705
1730
"restart terminated restartable init container and next init container" : {
1706
1731
mutatePodFn : func (pod * v1.Pod ) { pod .Spec .RestartPolicy = v1 .RestartPolicyAlways },
1707
1732
mutateStatusFn : func (pod * v1.Pod , status * kubecontainer.PodStatus ) {
@@ -1928,12 +1953,12 @@ func makeBasePodAndStatusWithRestartableInitContainers() (*v1.Pod, *kubecontaine
1928
1953
{
1929
1954
ID : kubecontainer.ContainerID {ID : "initid2" },
1930
1955
Name : "restartable-init-2" , State : kubecontainer .ContainerStateRunning ,
1931
- Hash : kubecontainer .HashContainer (& pod .Spec .InitContainers [0 ]),
1956
+ Hash : kubecontainer .HashContainer (& pod .Spec .InitContainers [1 ]),
1932
1957
},
1933
1958
{
1934
1959
ID : kubecontainer.ContainerID {ID : "initid3" },
1935
1960
Name : "restartable-init-3" , State : kubecontainer .ContainerStateRunning ,
1936
- Hash : kubecontainer .HashContainer (& pod .Spec .InitContainers [0 ]),
1961
+ Hash : kubecontainer .HashContainer (& pod .Spec .InitContainers [2 ]),
1937
1962
},
1938
1963
}
1939
1964
return pod , status
0 commit comments