Skip to content

Commit 3710d6f

Browse files
committed
reset kuberuntime_container
1 parent 266d1c8 commit 3710d6f

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

pkg/kubelet/kuberuntime/kuberuntime_container.go

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,6 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
10821082
continue
10831083
}
10841084

1085-
message := fmt.Sprintf("Init container %s", container.Name)
1086-
var reason containerKillReason
1087-
restartContainer := false
10881085
switch status.State {
10891086
case kubecontainer.ContainerStateCreated:
10901087
// The main sync loop should have created and started the container
@@ -1110,9 +1107,13 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
11101107
if startup == proberesults.Failure {
11111108
// If the restartable init container failed the startup probe,
11121109
// restart it.
1113-
message = fmt.Sprintf("%s failed startup probe, will be restarted", message)
1114-
reason = reasonStartupProbe
1115-
restartContainer = true
1110+
changes.ContainersToKill[status.ID] = containerToKillInfo{
1111+
name: container.Name,
1112+
container: container,
1113+
message: fmt.Sprintf("Init container %s failed startup probe", container.Name),
1114+
reason: reasonStartupProbe,
1115+
}
1116+
changes.InitContainersToStart = append(changes.InitContainersToStart, i)
11161117
}
11171118
break
11181119
}
@@ -1126,13 +1127,6 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
11261127
changes.InitContainersToStart = append(changes.InitContainersToStart, i+1)
11271128
}
11281129

1129-
// Restart running sidecar containers which have had their definition changed.
1130-
if _, _, changed := containerChanged(container, status); changed {
1131-
message = fmt.Sprintf("%s definition changed, will be restarted", message)
1132-
restartContainer = true
1133-
break
1134-
}
1135-
11361130
// A restartable init container does not have to take into account its
11371131
// liveness probe when it determines to start the next init container.
11381132
if container.LivenessProbe != nil {
@@ -1144,13 +1138,15 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
11441138
if liveness == proberesults.Failure {
11451139
// If the restartable init container failed the liveness probe,
11461140
// restart it.
1147-
message = fmt.Sprintf("%s failed liveness probe, will be restarted", message)
1148-
reason = reasonLivenessProbe
1149-
restartContainer = true
1150-
break
1141+
changes.ContainersToKill[status.ID] = containerToKillInfo{
1142+
name: container.Name,
1143+
container: container,
1144+
message: fmt.Sprintf("Init container %s failed liveness probe", container.Name),
1145+
reason: reasonLivenessProbe,
1146+
}
1147+
changes.InitContainersToStart = append(changes.InitContainersToStart, i)
11511148
}
11521149
}
1153-
11541150
} else { // init container
11551151
// nothing do to but wait for it to finish
11561152
break
@@ -1184,9 +1180,14 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
11841180
default: // kubecontainer.ContainerStatusUnknown or other unknown states
11851181
if types.IsRestartableInitContainer(container) {
11861182
// If the restartable init container is in unknown state, restart it.
1187-
message = fmt.Sprintf("%s is in %q state, try killing it before restart", message, status.State)
1188-
reason = reasonUnknown
1189-
restartContainer = true
1183+
changes.ContainersToKill[status.ID] = containerToKillInfo{
1184+
name: container.Name,
1185+
container: container,
1186+
message: fmt.Sprintf("Init container is in %q state, try killing it before restart",
1187+
status.State),
1188+
reason: reasonUnknown,
1189+
}
1190+
changes.InitContainersToStart = append(changes.InitContainersToStart, i)
11901191
} else { // init container
11911192
if !isInitContainerFailed(status) {
11921193
klog.V(4).InfoS("This should not happen, init container is in unknown state but not failed", "pod", klog.KObj(pod), "containerStatus", status)
@@ -1199,21 +1200,15 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
11991200
}
12001201

12011202
// If the init container is in unknown state, restart it.
1202-
message = fmt.Sprintf("%s is in %q state, try killing it before restart", message, status.State)
1203-
reason = reasonUnknown
1204-
restartContainer = true
1205-
}
1206-
}
1207-
1208-
if restartContainer {
1209-
changes.ContainersToKill[status.ID] = containerToKillInfo{
1210-
name: container.Name,
1211-
container: container,
1212-
message: message,
1213-
reason: reason,
1203+
changes.ContainersToKill[status.ID] = containerToKillInfo{
1204+
name: container.Name,
1205+
container: container,
1206+
message: fmt.Sprintf("Init container is in %q state, try killing it before restart",
1207+
status.State),
1208+
reason: reasonUnknown,
1209+
}
1210+
changes.InitContainersToStart = append(changes.InitContainersToStart, i)
12141211
}
1215-
changes.InitContainersToStart = append(changes.InitContainersToStart, i)
1216-
klog.V(4).InfoS("Message for Init Container of pod", "containerName", container.Name, "containerStatusID", status.ID, "pod", klog.KObj(pod), "containerMessage", message)
12171212
}
12181213

12191214
if !isPreviouslyInitialized {

0 commit comments

Comments
 (0)