func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecontainer.PodStatus, pullSecrets []v1.Secret, backOff *flowcontrol.Backoff) (result kubecontainer.PodSyncResult) {
// 1. 计算pod actions,见上文
podContainerChanges := m.computePodActions(pod, podStatus)
.....
// 2. 需要情况下执行kill pod
if podContainerChanges.KillPod {
....
killResult := m.killPodWithSyncResult(pod, kubecontainer.ConvertPodStatusToRunningPod(m.runtimeName, podStatus), nil)
....
} else {
// 3. 不需要kill pod,但需要kill工作container
for containerID, containerInfo := range podContainerChanges.ContainersToKill {
....
if err := m.killContainer(pod, containerID, containerInfo.name, containerInfo.message, nil); err != nil {
...
return
}
}
}
.....
// 4. 按需创建sandbox
podSandboxID := podContainerChanges.SandboxID
if podContainerChanges.CreateSandbox {
.....
podSandboxID, msg, err = m.createPodSandbox(pod, podContainerChanges.Attempt)
....
}
....
// 5. 运行next init container
if container := podContainerChanges.NextInitContainerToStart; container != nil {
....
if msg, err := m.startContainer(podSandboxID, podSandboxConfig, container, pod, podStatus, pullSecrets, podIP); err != nil {
startContainerResult.Fail(err, msg)
utilruntime.HandleError(fmt.Errorf( "init container start failed: %v: %s" , err, msg))
return
}
....
}
// 6. 运行工作containers。注意,根据computePodActions,若NextInitContainerToStart不为空,则不存在ContainersToStart ,即这个循环在当前这个SyncPod中不会被执行
for _, idx := range podContainerChanges.ContainersToStart {
....
if msg, err := m.startContainer(podSandboxID, podSandboxConfig, container, pod, podStatus, pullSecrets, podIP); err != nil {
startContainerResult.Fail(err, msg)
// known errors that are logged in other places are logged at higher levels here to avoid
// repetitive log spam
switch {
case err == images.ErrImagePullBackOff:
glog.V( 3 ).Infof( "container start failed: %v: %s" , err, msg)
default :
utilruntime.HandleError(fmt.Errorf( "container start failed: %v: %s" , err, msg))
}
continue
}
}
return
}
|