@@ -1082,6 +1082,9 @@ 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
1085
1088
switch status .State {
1086
1089
case kubecontainer .ContainerStateCreated :
1087
1090
// The main sync loop should have created and started the container
@@ -1107,13 +1110,9 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1107
1110
if startup == proberesults .Failure {
1108
1111
// If the restartable init container failed the startup probe,
1109
1112
// restart it.
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 )
1113
+ message = fmt .Sprintf ("%s failed startup probe, will be restarted" , message )
1114
+ reason = reasonStartupProbe
1115
+ restartContainer = true
1117
1116
}
1118
1117
break
1119
1118
}
@@ -1127,6 +1126,13 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1127
1126
changes .InitContainersToStart = append (changes .InitContainersToStart , i + 1 )
1128
1127
}
1129
1128
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
+
1130
1136
// A restartable init container does not have to take into account its
1131
1137
// liveness probe when it determines to start the next init container.
1132
1138
if container .LivenessProbe != nil {
@@ -1138,15 +1144,13 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1138
1144
if liveness == proberesults .Failure {
1139
1145
// If the restartable init container failed the liveness probe,
1140
1146
// restart it.
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 )
1147
+ message = fmt .Sprintf ("%s failed liveness probe, will be restarted" , message )
1148
+ reason = reasonLivenessProbe
1149
+ restartContainer = true
1150
+ break
1148
1151
}
1149
1152
}
1153
+
1150
1154
} else { // init container
1151
1155
// nothing do to but wait for it to finish
1152
1156
break
@@ -1180,14 +1184,9 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1180
1184
default : // kubecontainer.ContainerStatusUnknown or other unknown states
1181
1185
if types .IsRestartableInitContainer (container ) {
1182
1186
// If the restartable init container is in unknown state, restart it.
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 )
1187
+ message = fmt .Sprintf ("%s is in %q state, try killing it before restart" , message , status .State )
1188
+ reason = reasonUnknown
1189
+ restartContainer = true
1191
1190
} else { // init container
1192
1191
if ! isInitContainerFailed (status ) {
1193
1192
klog .V (4 ).InfoS ("This should not happen, init container is in unknown state but not failed" , "pod" , klog .KObj (pod ), "containerStatus" , status )
@@ -1200,17 +1199,23 @@ func (m *kubeGenericRuntimeManager) computeInitContainerActions(pod *v1.Pod, pod
1200
1199
}
1201
1200
1202
1201
// If the init container is in unknown state, restart it.
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 )
1202
+ message = fmt .Sprintf ("%s is in %q state, try killing it before restart" , message , status .State )
1203
+ reason = reasonUnknown
1204
+ restartContainer = true
1211
1205
}
1212
1206
}
1213
1207
1208
+ if restartContainer {
1209
+ changes .ContainersToKill [status .ID ] = containerToKillInfo {
1210
+ name : container .Name ,
1211
+ container : container ,
1212
+ message : message ,
1213
+ reason : reason ,
1214
+ }
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
+ }
1218
+
1214
1219
if ! isPreviouslyInitialized {
1215
1220
// the one before this init container has been initialized
1216
1221
isPreviouslyInitialized = true
0 commit comments