@@ -1082,9 +1082,6 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1082
1082
continue
1083
1083
}
1084
1084
1085
- message := fmt .Sprintf ("Init container %s" , container .Name )
1086
- var reason containerKillReason
1087
- restartContainer := false
1088
1085
switch status .State {
1089
1086
case kubecontainer .ContainerStateCreated :
1090
1087
// The main sync loop should have created and started the container
@@ -1110,9 +1107,13 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1110
1107
if startup == proberesults .Failure {
1111
1108
// If the restartable init container failed the startup probe,
1112
1109
// 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 )
1116
1117
}
1117
1118
break
1118
1119
}
@@ -1126,13 +1127,6 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1126
1127
changes .InitContainersToStart = append (changes .InitContainersToStart , i + 1 )
1127
1128
}
1128
1129
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
-
1136
1130
// A restartable init container does not have to take into account its
1137
1131
// liveness probe when it determines to start the next init container.
1138
1132
if container .LivenessProbe != nil {
@@ -1144,13 +1138,15 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1144
1138
if liveness == proberesults .Failure {
1145
1139
// If the restartable init container failed the liveness probe,
1146
1140
// 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 )
1151
1148
}
1152
1149
}
1153
-
1154
1150
} else { // init container
1155
1151
// nothing do to but wait for it to finish
1156
1152
break
@@ -1184,9 +1180,14 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1184
1180
default : // kubecontainer.ContainerStatusUnknown or other unknown states
1185
1181
if types .IsRestartableInitContainer (container ) {
1186
1182
// 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 )
1190
1191
} else { // init container
1191
1192
if ! isInitContainerFailed (status ) {
1192
1193
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
1199
1200
}
1200
1201
1201
1202
// 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 )
1214
1211
}
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 )
1217
1212
}
1218
1213
1219
1214
if ! isPreviouslyInitialized {
0 commit comments