@@ -51,6 +51,7 @@ import (
51
51
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
52
52
imagetypes "k8s.io/kubernetes/pkg/kubelet/images"
53
53
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
54
+ kubelettypes "k8s.io/kubernetes/pkg/kubelet/types"
54
55
)
55
56
56
57
var (
@@ -1428,6 +1429,20 @@ func testComputePodActionsWithInitContainers(t *testing.T, sidecarContainersEnab
1428
1429
ContainersToKill : getKillMapWithInitContainers (basePod , baseStatus , []int {}),
1429
1430
},
1430
1431
},
1432
+ "an init container is in the created state due to an unknown error when starting container; restart it" : {
1433
+ mutatePodFn : func (pod * v1.Pod ) { pod .Spec .RestartPolicy = v1 .RestartPolicyAlways },
1434
+ mutateStatusFn : func (status * kubecontainer.PodStatus ) {
1435
+ status .ContainerStatuses [2 ].State = kubecontainer .ContainerStateCreated
1436
+ },
1437
+ actions : podActions {
1438
+ KillPod : false ,
1439
+ SandboxID : baseStatus .SandboxStatuses [0 ].Id ,
1440
+ NextInitContainerToStart : & basePod .Spec .InitContainers [2 ],
1441
+ InitContainersToStart : []int {2 },
1442
+ ContainersToStart : []int {},
1443
+ ContainersToKill : getKillMapWithInitContainers (basePod , baseStatus , []int {}),
1444
+ },
1445
+ },
1431
1446
} {
1432
1447
pod , status := makeBasePodAndStatusWithInitContainers ()
1433
1448
if test .mutatePodFn != nil {
@@ -1438,12 +1453,15 @@ func testComputePodActionsWithInitContainers(t *testing.T, sidecarContainersEnab
1438
1453
}
1439
1454
ctx := context .Background ()
1440
1455
actions := m .computePodActions (ctx , pod , status )
1441
- if ! sidecarContainersEnabled {
1442
- // If sidecar containers are disabled, we should not see any
1456
+ handleRestartableInitContainers := sidecarContainersEnabled && kubelettypes .HasRestartableInitContainer (pod )
1457
+ if ! handleRestartableInitContainers {
1458
+ // If sidecar containers are disabled or the pod does not have any
1459
+ // restartable init container, we should not see any
1443
1460
// InitContainersToStart in the actions.
1444
1461
test .actions .InitContainersToStart = nil
1445
1462
} else {
1446
- // If sidecar containers are enabled, we should not see any
1463
+ // If sidecar containers are enabled and the pod has any
1464
+ // restartable init container, we should not see any
1447
1465
// NextInitContainerToStart in the actions.
1448
1466
test .actions .NextInitContainerToStart = nil
1449
1467
}
@@ -2041,12 +2059,15 @@ func testComputePodActionsWithInitAndEphemeralContainers(t *testing.T, sidecarCo
2041
2059
}
2042
2060
ctx := context .Background ()
2043
2061
actions := m .computePodActions (ctx , pod , status )
2044
- if ! sidecarContainersEnabled {
2045
- // If sidecar containers are disabled, we should not see any
2062
+ handleRestartableInitContainers := sidecarContainersEnabled && kubelettypes .HasRestartableInitContainer (pod )
2063
+ if ! handleRestartableInitContainers {
2064
+ // If sidecar containers are disabled or the pod does not have any
2065
+ // restartable init container, we should not see any
2046
2066
// InitContainersToStart in the actions.
2047
2067
test .actions .InitContainersToStart = nil
2048
2068
} else {
2049
- // If sidecar containers are enabled, we should not see any
2069
+ // If sidecar containers are enabled and the pod has any
2070
+ // restartable init container, we should not see any
2050
2071
// NextInitContainerToStart in the actions.
2051
2072
test .actions .NextInitContainerToStart = nil
2052
2073
}
0 commit comments